Skip to content

Commit 9614634

Browse files
Christoph LameterLinus Torvalds
authored andcommitted
[PATCH] ZVC/zone_reclaim: Leave 1% of unmapped pagecache pages for file I/O
It turns out that it is advantageous to leave a small portion of unmapped file backed pages if all of a zone's pages (or almost all pages) are allocated and so the page allocator has to go off-node. This allows recently used file I/O buffers to stay on the node and reduces the times that zone reclaim is invoked if file I/O occurs when we run out of memory in a zone. The problem is that zone reclaim runs too frequently when the page cache is used for file I/O (read write and therefore unmapped pages!) alone and we have almost all pages of the zone allocated. Zone reclaim may remove 32 unmapped pages. File I/O will use these pages for the next read/write requests and the unmapped pages increase. After the zone has filled up again zone reclaim will remove it again after only 32 pages. This cycle is too inefficient and there are potentially too many zone reclaim cycles. With the 1% boundary we may still remove all unmapped pages for file I/O in zone reclaim pass. However. it will take a large number of read and writes to get back to 1% again where we trigger zone reclaim again. The zone reclaim 2.6.16/17 does not show this behavior because we have a 30 second timeout. [akpm@osdl.org: rename the /proc file and the variable] Signed-off-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent cb6358e commit 9614634

7 files changed

Lines changed: 69 additions & 14 deletions

File tree

‎Documentation/sysctl/vm.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Currently, these files are in /proc/sys/vm:
2828
- block_dump
2929
- drop-caches
3030
- zone_reclaim_mode
31+
- min_unmapped_ratio
3132
- panic_on_oom
3233

3334
==============================================================
@@ -168,6 +169,19 @@ in all nodes of the system.
168169

169170
=============================================================
170171

172+
min_unmapped_ratio:
173+
174+
This is available only on NUMA kernels.
175+
176+
A percentage of the file backed pages in each zone. Zone reclaim will only
177+
occur if more than this percentage of pages are file backed and unmapped.
178+
This is to insure that a minimal amount of local pages is still available for
179+
file I/O even if the node is overallocated.
180+
181+
The default is 1 percent.
182+
183+
=============================================================
184+
171185
panic_on_oom
172186

173187
This enables or disables panic on out-of-memory feature. If this is set to 1,

‎include/linux/mmzone.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ struct zone {
150150
unsigned long lowmem_reserve[MAX_NR_ZONES];
151151

152152
#ifdef CONFIG_NUMA
153+
/*
154+
* zone reclaim becomes active if more unmapped pages exist.
155+
*/
156+
unsigned long min_unmapped_ratio;
153157
struct per_cpu_pageset *pageset[NR_CPUS];
154158
#else
155159
struct per_cpu_pageset pageset[NR_CPUS];
@@ -414,6 +418,8 @@ int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, struct file *,
414418
void __user *, size_t *, loff_t *);
415419
int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *, int, struct file *,
416420
void __user *, size_t *, loff_t *);
421+
int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *, int,
422+
struct file *, void __user *, size_t *, loff_t *);
417423

418424
#include <linux/topology.h>
419425
/* Returns the number of the current Node. */

‎include/linux/swap.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ extern long vm_total_pages;
189189

190190
#ifdef CONFIG_NUMA
191191
extern int zone_reclaim_mode;
192+
extern int sysctl_min_unmapped_ratio;
192193
extern int zone_reclaim(struct zone *, gfp_t, unsigned int);
193194
#else
194195
#define zone_reclaim_mode 0

‎include/linux/sysctl.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ enum
188188
VM_DROP_PAGECACHE=29, /* int: nuke lots of pagecache */
189189
VM_PERCPU_PAGELIST_FRACTION=30,/* int: fraction of pages in each percpu_pagelist */
190190
VM_ZONE_RECLAIM_MODE=31, /* reclaim local zone memory before going off node */
191-
VM_ZONE_RECLAIM_INTERVAL=32, /* time period to wait after reclaim failure */
191+
VM_MIN_UNMAPPED=32, /* Set min percent of unmapped pages */
192192
VM_PANIC_ON_OOM=33, /* panic at out-of-memory */
193193
VM_VDSO_ENABLED=34, /* map VDSO into new processes? */
194194
};

‎kernel/sysctl.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,17 @@ static ctl_table vm_table[] = {
932932
.strategy = &sysctl_intvec,
933933
.extra1 = &zero,
934934
},
935+
{
936+
.ctl_name = VM_MIN_UNMAPPED,
937+
.procname = "min_unmapped_ratio",
938+
.data = &sysctl_min_unmapped_ratio,
939+
.maxlen = sizeof(sysctl_min_unmapped_ratio),
940+
.mode = 0644,
941+
.proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
942+
.strategy = &sysctl_intvec,
943+
.extra1 = &zero,
944+
.extra2 = &one_hundred,
945+
},
935946
#endif
936947
#ifdef CONFIG_X86_32
937948
{

‎mm/page_alloc.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,6 +2005,10 @@ static void __meminit free_area_init_core(struct pglist_data *pgdat,
20052005

20062006
zone->spanned_pages = size;
20072007
zone->present_pages = realsize;
2008+
#ifdef CONFIG_NUMA
2009+
zone->min_unmapped_ratio = (realsize*sysctl_min_unmapped_ratio)
2010+
/ 100;
2011+
#endif
20082012
zone->name = zone_names[j];
20092013
spin_lock_init(&zone->lock);
20102014
spin_lock_init(&zone->lru_lock);
@@ -2298,6 +2302,24 @@ int min_free_kbytes_sysctl_handler(ctl_table *table, int write,
22982302
return 0;
22992303
}
23002304

2305+
#ifdef CONFIG_NUMA
2306+
int sysctl_min_unmapped_ratio_sysctl_handler(ctl_table *table, int write,
2307+
struct file *file, void __user *buffer, size_t *length, loff_t *ppos)
2308+
{
2309+
struct zone *zone;
2310+
int rc;
2311+
2312+
rc = proc_dointvec_minmax(table, write, file, buffer, length, ppos);
2313+
if (rc)
2314+
return rc;
2315+
2316+
for_each_zone(zone)
2317+
zone->min_unmapped_ratio = (zone->present_pages *
2318+
sysctl_min_unmapped_ratio) / 100;
2319+
return 0;
2320+
}
2321+
#endif
2322+
23012323
/*
23022324
* lowmem_reserve_ratio_sysctl_handler - just a wrapper around
23032325
* proc_dointvec() so that we can call setup_per_zone_lowmem_reserve()

‎mm/vmscan.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,6 @@ module_init(kswapd_init)
15031503
*
15041504
* If non-zero call zone_reclaim when the number of free pages falls below
15051505
* the watermarks.
1506-
*
1507-
* In the future we may add flags to the mode. However, the page allocator
1508-
* should only have to check that zone_reclaim_mode != 0 before calling
1509-
* zone_reclaim().
15101506
*/
15111507
int zone_reclaim_mode __read_mostly;
15121508

@@ -1523,6 +1519,12 @@ int zone_reclaim_mode __read_mostly;
15231519
*/
15241520
#define ZONE_RECLAIM_PRIORITY 4
15251521

1522+
/*
1523+
* Percentage of pages in a zone that must be unmapped for zone_reclaim to
1524+
* occur.
1525+
*/
1526+
int sysctl_min_unmapped_ratio = 1;
1527+
15261528
/*
15271529
* Try to free up some pages from this zone through reclaim.
15281530
*/
@@ -1590,18 +1592,17 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
15901592
int node_id;
15911593

15921594
/*
1593-
* Do not reclaim if there are not enough reclaimable pages in this
1594-
* zone that would satify this allocations.
1595+
* Zone reclaim reclaims unmapped file backed pages.
15951596
*
1596-
* All unmapped pagecache pages are reclaimable.
1597-
*
1598-
* Both counters may be temporarily off a bit so we use
1599-
* SWAP_CLUSTER_MAX as the boundary. It may also be good to
1600-
* leave a few frequently used unmapped pagecache pages around.
1597+
* A small portion of unmapped file backed pages is needed for
1598+
* file I/O otherwise pages read by file I/O will be immediately
1599+
* thrown out if the zone is overallocated. So we do not reclaim
1600+
* if less than a specified percentage of the zone is used by
1601+
* unmapped file backed pages.
16011602
*/
16021603
if (zone_page_state(zone, NR_FILE_PAGES) -
1603-
zone_page_state(zone, NR_FILE_MAPPED) < SWAP_CLUSTER_MAX)
1604-
return 0;
1604+
zone_page_state(zone, NR_FILE_MAPPED) <= zone->min_unmapped_ratio)
1605+
return 0;
16051606

16061607
/*
16071608
* Avoid concurrent zone reclaims, do not reclaim in a zone that does

0 commit comments

Comments
 (0)