Skip to content

Commit 7fb2d46

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
[PATCH] zone_reclaim: additional comments and cleanup
Add some comments to explain how zone reclaim works. And it fixes the following issues: - PF_SWAPWRITE needs to be set for RECLAIM_SWAP to be able to write out pages to swap. Currently RECLAIM_SWAP may not do that. - remove setting nr_reclaimed pages after slab reclaim since the slab shrinking code does not use that and the nr_reclaimed pages is just right for the intended follow up action. Signed-off-by: Christoph Lameter <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1742f19 commit 7fb2d46

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

mm/vmscan.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,7 @@ int zone_reclaim_interval __read_mostly = 30*HZ;
18871887
*/
18881888
static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
18891889
{
1890+
/* Minimum pages needed in order to stay on node */
18901891
const unsigned long nr_pages = 1 << order;
18911892
struct task_struct *p = current;
18921893
struct reclaim_state reclaim_state;
@@ -1924,9 +1925,12 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
19241925

19251926
if (nr_reclaimed < nr_pages && (zone_reclaim_mode & RECLAIM_SLAB)) {
19261927
/*
1927-
* shrink_slab does not currently allow us to determine
1928-
* how many pages were freed in the zone. So we just
1929-
* shake the slab and then go offnode for a single allocation.
1928+
* shrink_slab() does not currently allow us to determine how
1929+
* many pages were freed in this zone. So we just shake the slab
1930+
* a bit and then go off node for this particular allocation
1931+
* despite possibly having freed enough memory to allocate in
1932+
* this zone. If we freed local memory then the next
1933+
* allocations will be local again.
19301934
*
19311935
* shrink_slab will free memory on all zones and may take
19321936
* a long time.
@@ -1937,8 +1941,14 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
19371941
p->reclaim_state = NULL;
19381942
current->flags &= ~(PF_MEMALLOC | PF_SWAPWRITE);
19391943

1940-
if (nr_reclaimed == 0)
1944+
if (nr_reclaimed == 0) {
1945+
/*
1946+
* We were unable to reclaim enough pages to stay on node. We
1947+
* now allow off node accesses for a certain time period before
1948+
* trying again to reclaim pages from the local zone.
1949+
*/
19411950
zone->last_unsuccessful_zone_reclaim = jiffies;
1951+
}
19421952

19431953
return nr_reclaimed >= nr_pages;
19441954
}

0 commit comments

Comments
 (0)