>From e3c9516beb8302cb8fb2f5ab866bbe2686fda5fb Mon Sep 17 00:00:00 2001 From: Aaron Lu Date: Thu, 6 Jul 2017 15:00:07 +0800 Subject: [PATCH] percpu_pagelist_batch: add a batch interface Signed-off-by: Aaron Lu --- include/linux/mmzone.h | 2 ++ kernel/sysctl.c | 9 +++++++++ mm/page_alloc.c | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index ef6a13b7bd3e..0548d038b7cd 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -875,6 +875,8 @@ int lowmem_reserve_ratio_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); +int percpu_pagelist_batch_sysctl_handler(struct ctl_table *, int, + void __user *, size_t *, loff_t *); int sysctl_min_unmapped_ratio_sysctl_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); int sysctl_min_slab_ratio_sysctl_handler(struct ctl_table *, int, diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 4dfba1a76cc3..85cc4544db1b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -108,6 +108,7 @@ extern unsigned int core_pipe_limit; extern int pid_max; extern int pid_max_min, pid_max_max; extern int percpu_pagelist_fraction; +extern int percpu_pagelist_batch; extern int latencytop_enabled; extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max; #ifndef CONFIG_MMU @@ -1440,6 +1441,14 @@ static struct ctl_table vm_table[] = { .proc_handler = percpu_pagelist_fraction_sysctl_handler, .extra1 = &zero, }, + { + .procname = "percpu_pagelist_batch", + .data = &percpu_pagelist_batch, + .maxlen = sizeof(percpu_pagelist_batch), + .mode = 0644, + .proc_handler = percpu_pagelist_batch_sysctl_handler, + .extra1 = &zero, + }, #ifdef CONFIG_MMU { .procname = "max_map_count", diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2302f250d6b1..aa96a4bd6467 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -129,6 +129,7 @@ unsigned long totalreserve_pages __read_mostly; unsigned long totalcma_pages __read_mostly; int percpu_pagelist_fraction; +int percpu_pagelist_batch; gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK; /* @@ -5477,7 +5478,8 @@ static void pageset_set_high_and_batch(struct zone *zone, (zone->managed_pages / percpu_pagelist_fraction)); else - pageset_set_batch(pcp, zone_batchsize(zone)); + pageset_set_batch(pcp, percpu_pagelist_batch ? + percpu_pagelist_batch : zone_batchsize(zone)); } static void __meminit zone_pageset_init(struct zone *zone, int cpu) @@ -7157,6 +7159,42 @@ int percpu_pagelist_fraction_sysctl_handler(struct ctl_table *table, int write, return ret; } +int percpu_pagelist_batch_sysctl_handler(struct ctl_table *table, int write, + void __user *buffer, size_t *length, loff_t *ppos) +{ + struct zone *zone; + int old_percpu_pagelist_batch; + int ret; + + mutex_lock(&pcp_batch_high_lock); + old_percpu_pagelist_batch = percpu_pagelist_batch; + + ret = proc_dointvec_minmax(table, write, buffer, length, ppos); + if (!write || ret < 0) + goto out; + + /* Sanity checking to avoid pcp imbalance */ + if (percpu_pagelist_batch <= 0) { + ret = -EINVAL; + goto out; + } + + /* No change? */ + if (percpu_pagelist_batch == old_percpu_pagelist_batch) + goto out; + + for_each_populated_zone(zone) { + unsigned int cpu; + + for_each_possible_cpu(cpu) + pageset_set_high_and_batch(zone, + per_cpu_ptr(zone->pageset, cpu)); + } +out: + mutex_unlock(&pcp_batch_high_lock); + return ret; +} + #ifdef CONFIG_NUMA int hashdist = HASHDIST_DEFAULT; -- 2.9.5