shrinker.c (99b1bb61b225c3eb4d3b196d4f1d041695b19a7e) | shrinker.c (1ab6c4997e04a00c50c6d786c2f046adc0d1f5de) |
---|---|
1/* 2 * This file is part of UBIFS. 3 * 4 * Copyright (C) 2006-2008 Nokia Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 as published by 8 * the Free Software Foundation. --- 263 unchanged lines hidden (view full) --- 272 mutex_unlock(&c->umount_mutex); 273 } 274 } 275 spin_unlock(&ubifs_infos_lock); 276 277 return 0; 278} 279 | 1/* 2 * This file is part of UBIFS. 3 * 4 * Copyright (C) 2006-2008 Nokia Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 as published by 8 * the Free Software Foundation. --- 263 unchanged lines hidden (view full) --- 272 mutex_unlock(&c->umount_mutex); 273 } 274 } 275 spin_unlock(&ubifs_infos_lock); 276 277 return 0; 278} 279 |
280int ubifs_shrinker(struct shrinker *shrink, struct shrink_control *sc) | 280unsigned long ubifs_shrink_count(struct shrinker *shrink, 281 struct shrink_control *sc) |
281{ | 282{ |
282 int nr = sc->nr_to_scan; 283 int freed, contention = 0; | |
284 long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt); 285 | 283 long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt); 284 |
286 if (nr == 0) 287 /* 288 * Due to the way UBIFS updates the clean znode counter it may 289 * temporarily be negative. 290 */ 291 return clean_zn_cnt >= 0 ? clean_zn_cnt : 1; | 285 /* 286 * Due to the way UBIFS updates the clean znode counter it may 287 * temporarily be negative. 288 */ 289 return clean_zn_cnt >= 0 ? clean_zn_cnt : 1; 290} |
292 | 291 |
292unsigned long ubifs_shrink_scan(struct shrinker *shrink, 293 struct shrink_control *sc) 294{ 295 unsigned long nr = sc->nr_to_scan; 296 int contention = 0; 297 unsigned long freed; 298 long clean_zn_cnt = atomic_long_read(&ubifs_clean_zn_cnt); 299 |
|
293 if (!clean_zn_cnt) { 294 /* 295 * No clean znodes, nothing to reap. All we can do in this case 296 * is to kick background threads to start commit, which will 297 * probably make clean znodes which, in turn, will be freeable. 298 * And we return -1 which means will make VM call us again 299 * later. 300 */ --- 10 unchanged lines hidden (view full) --- 311 if (freed >= nr) 312 goto out; 313 314 dbg_tnc("not enough young znodes, free all"); 315 freed += shrink_tnc_trees(nr - freed, 0, &contention); 316 317 if (!freed && contention) { 318 dbg_tnc("freed nothing, but contention"); | 300 if (!clean_zn_cnt) { 301 /* 302 * No clean znodes, nothing to reap. All we can do in this case 303 * is to kick background threads to start commit, which will 304 * probably make clean znodes which, in turn, will be freeable. 305 * And we return -1 which means will make VM call us again 306 * later. 307 */ --- 10 unchanged lines hidden (view full) --- 318 if (freed >= nr) 319 goto out; 320 321 dbg_tnc("not enough young znodes, free all"); 322 freed += shrink_tnc_trees(nr - freed, 0, &contention); 323 324 if (!freed && contention) { 325 dbg_tnc("freed nothing, but contention"); |
319 return -1; | 326 return SHRINK_STOP; |
320 } 321 322out: | 327 } 328 329out: |
323 dbg_tnc("%d znodes were freed, requested %d", freed, nr); | 330 dbg_tnc("%lu znodes were freed, requested %lu", freed, nr); |
324 return freed; 325} | 331 return freed; 332} |