glock.c (55f841ce9395a72c6285fbcc4c403c0c786e1c74) | glock.c (1ab6c4997e04a00c50c6d786c2f046adc0d1f5de) |
---|---|
1/* 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This copyrighted material is made available to anyone wishing to use, 6 * modify, copy, or redistribute it subject to the terms and conditions 7 * of the GNU General Public License version 2. 8 */ --- 1413 unchanged lines hidden (view full) --- 1422 * gfs2_scan_glock_lru - Scan the LRU looking for locks to demote 1423 * @nr: The number of entries to scan 1424 * 1425 * This function selects the entries on the LRU which are able to 1426 * be demoted, and then kicks off the process by calling 1427 * gfs2_dispose_glock_lru() above. 1428 */ 1429 | 1/* 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. 4 * 5 * This copyrighted material is made available to anyone wishing to use, 6 * modify, copy, or redistribute it subject to the terms and conditions 7 * of the GNU General Public License version 2. 8 */ --- 1413 unchanged lines hidden (view full) --- 1422 * gfs2_scan_glock_lru - Scan the LRU looking for locks to demote 1423 * @nr: The number of entries to scan 1424 * 1425 * This function selects the entries on the LRU which are able to 1426 * be demoted, and then kicks off the process by calling 1427 * gfs2_dispose_glock_lru() above. 1428 */ 1429 |
1430static void gfs2_scan_glock_lru(int nr) | 1430static long gfs2_scan_glock_lru(int nr) |
1431{ 1432 struct gfs2_glock *gl; 1433 LIST_HEAD(skipped); 1434 LIST_HEAD(dispose); | 1431{ 1432 struct gfs2_glock *gl; 1433 LIST_HEAD(skipped); 1434 LIST_HEAD(dispose); |
1435 long freed = 0; |
|
1435 1436 spin_lock(&lru_lock); | 1436 1437 spin_lock(&lru_lock); |
1437 while(nr && !list_empty(&lru_list)) { | 1438 while ((nr-- >= 0) && !list_empty(&lru_list)) { |
1438 gl = list_entry(lru_list.next, struct gfs2_glock, gl_lru); 1439 1440 /* Test for being demotable */ 1441 if (!test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { 1442 list_move(&gl->gl_lru, &dispose); 1443 atomic_dec(&lru_count); | 1439 gl = list_entry(lru_list.next, struct gfs2_glock, gl_lru); 1440 1441 /* Test for being demotable */ 1442 if (!test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { 1443 list_move(&gl->gl_lru, &dispose); 1444 atomic_dec(&lru_count); |
1444 nr--; | 1445 freed++; |
1445 continue; 1446 } 1447 1448 list_move(&gl->gl_lru, &skipped); 1449 } 1450 list_splice(&skipped, &lru_list); 1451 if (!list_empty(&dispose)) 1452 gfs2_dispose_glock_lru(&dispose); 1453 spin_unlock(&lru_lock); | 1446 continue; 1447 } 1448 1449 list_move(&gl->gl_lru, &skipped); 1450 } 1451 list_splice(&skipped, &lru_list); 1452 if (!list_empty(&dispose)) 1453 gfs2_dispose_glock_lru(&dispose); 1454 spin_unlock(&lru_lock); |
1455 1456 return freed; |
|
1454} 1455 | 1457} 1458 |
1456static int gfs2_shrink_glock_memory(struct shrinker *shrink, 1457 struct shrink_control *sc) | 1459static unsigned long gfs2_glock_shrink_scan(struct shrinker *shrink, 1460 struct shrink_control *sc) |
1458{ | 1461{ |
1459 if (sc->nr_to_scan) { 1460 if (!(sc->gfp_mask & __GFP_FS)) 1461 return -1; 1462 gfs2_scan_glock_lru(sc->nr_to_scan); 1463 } | 1462 if (!(sc->gfp_mask & __GFP_FS)) 1463 return SHRINK_STOP; 1464 return gfs2_scan_glock_lru(sc->nr_to_scan); 1465} |
1464 | 1466 |
1467static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink, 1468 struct shrink_control *sc) 1469{ |
|
1465 return vfs_pressure_ratio(atomic_read(&lru_count)); 1466} 1467 1468static struct shrinker glock_shrinker = { | 1470 return vfs_pressure_ratio(atomic_read(&lru_count)); 1471} 1472 1473static struct shrinker glock_shrinker = { |
1469 .shrink = gfs2_shrink_glock_memory, | |
1470 .seeks = DEFAULT_SEEKS, | 1474 .seeks = DEFAULT_SEEKS, |
1475 .count_objects = gfs2_glock_shrink_count, 1476 .scan_objects = gfs2_glock_shrink_scan, |
|
1471}; 1472 1473/** 1474 * examine_bucket - Call a function for glock in a hash bucket 1475 * @examiner: the function 1476 * @sdp: the filesystem 1477 * @bucket: the bucket 1478 * --- 655 unchanged lines hidden --- | 1477}; 1478 1479/** 1480 * examine_bucket - Call a function for glock in a hash bucket 1481 * @examiner: the function 1482 * @sdp: the filesystem 1483 * @bucket: the bucket 1484 * --- 655 unchanged lines hidden --- |