Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] shrink_all_memory(): fix lru_pages handling

At the end of shrink_all_memory() we forget to recalculate lru_pages: it can
be zero.

Fix that up, and add a helper function for this operation too.

Also, recalculate lru_pages each time around the inner loop to get the
balancing correct.

Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Andrew Morton and committed by
Linus Torvalds
76395d37 d63b7090

+16 -17
+16 -17
mm/vmscan.c
··· 1406 1406 return ret; 1407 1407 } 1408 1408 1409 + static unsigned long count_lru_pages(void) 1410 + { 1411 + struct zone *zone; 1412 + unsigned long ret = 0; 1413 + 1414 + for_each_zone(zone) 1415 + ret += zone->nr_active + zone->nr_inactive; 1416 + return ret; 1417 + } 1418 + 1409 1419 /* 1410 1420 * Try to free `nr_pages' of memory, system-wide, and return the number of 1411 1421 * freed pages. ··· 1430 1420 unsigned long ret = 0; 1431 1421 int pass; 1432 1422 struct reclaim_state reclaim_state; 1433 - struct zone *zone; 1434 1423 struct scan_control sc = { 1435 1424 .gfp_mask = GFP_KERNEL, 1436 1425 .may_swap = 0, ··· 1440 1431 1441 1432 current->reclaim_state = &reclaim_state; 1442 1433 1443 - lru_pages = 0; 1444 - for_each_zone(zone) 1445 - lru_pages += zone->nr_active + zone->nr_inactive; 1446 - 1434 + lru_pages = count_lru_pages(); 1447 1435 nr_slab = global_page_state(NR_SLAB_RECLAIMABLE); 1448 1436 /* If slab caches are huge, it's better to hit them first */ 1449 1437 while (nr_slab >= lru_pages) { ··· 1467 1461 for (pass = 0; pass < 5; pass++) { 1468 1462 int prio; 1469 1463 1470 - /* Needed for shrinking slab caches later on */ 1471 - if (!lru_pages) 1472 - for_each_zone(zone) { 1473 - lru_pages += zone->nr_active; 1474 - lru_pages += zone->nr_inactive; 1475 - } 1476 - 1477 1464 /* Force reclaiming mapped pages in the passes #3 and #4 */ 1478 1465 if (pass > 2) { 1479 1466 sc.may_swap = 1; ··· 1482 1483 goto out; 1483 1484 1484 1485 reclaim_state.reclaimed_slab = 0; 1485 - shrink_slab(sc.nr_scanned, sc.gfp_mask, lru_pages); 1486 + shrink_slab(sc.nr_scanned, sc.gfp_mask, 1487 + count_lru_pages()); 1486 1488 ret += reclaim_state.reclaimed_slab; 1487 1489 if (ret >= nr_pages) 1488 1490 goto out; ··· 1491 1491 if (sc.nr_scanned && prio < DEF_PRIORITY - 2) 1492 1492 congestion_wait(WRITE, HZ / 10); 1493 1493 } 1494 - 1495 - lru_pages = 0; 1496 1494 } 1497 1495 1498 1496 /* 1499 1497 * If ret = 0, we could not shrink LRUs, but there may be something 1500 1498 * in slab caches 1501 1499 */ 1502 - if (!ret) 1500 + if (!ret) { 1503 1501 do { 1504 1502 reclaim_state.reclaimed_slab = 0; 1505 - shrink_slab(nr_pages, sc.gfp_mask, lru_pages); 1503 + shrink_slab(nr_pages, sc.gfp_mask, count_lru_pages()); 1506 1504 ret += reclaim_state.reclaimed_slab; 1507 1505 } while (ret < nr_pages && reclaim_state.reclaimed_slab > 0); 1506 + } 1508 1507 1509 1508 out: 1510 1509 current->reclaim_state = NULL;