Provide unmapped page cache control (v2)
Subsystems (9)
cover Provide unmapped page cache control (v2)
The following series implements page cache control, this is a split out version of patch 1 of version 3 of the page cache optimization patches posted earlier at Previous posting https://lkml.org/lkml/2010/11/30/79
The previous revision received lot of comments, I've tried to address as many of those as possible in this revision. The last series was reviewed-by Christoph Lameter.
There were comments on overlap with Nick's changes and overlap with them. I don't feel these changes impact Nick's work and integration can/will be considered as the patches evolve, if need be.
Detailed Description
====================
This patch implements unmapped page cache control via preferred page cache reclaim. The current patch hooks into kswapd and reclaims page cache if the user has requested for unmapped page control. This is useful in the following scenario
- In a virtualized environment with cache=writethrough, we see double caching - (one in the host and one in the guest). As we try to scale guests, cache usage across the system grows. The goal of this patch is to reclaim page cache when Linux is running as a guest and get the host to hold the page cache and manage it. There might be temporary duplication, but in the long run, memory in the guests would be used for mapped pages.
- The option is controlled via a boot option and the administrator can selectively turn it on, on a need to use basis.
A lot of the code is borrowed from zone_reclaim_mode logic for __zone_reclaim(). One might argue that the with ballooning and KSM this feature is not very useful, but even with ballooning, we need extra logic to balloon multiple VM machines and it is hard to figure out the correct amount of memory to balloon. With these patches applied, each guest has a sufficient amount of free memory available, that can be easily seen and reclaimed by the balloon driver. The additional memory in the guest can be reused for additional applications or used to start additional guests/balance memory in the host.
KSM currently does not de-duplicate host and guest page cache. The goal of this patch is to help automatically balance unmapped page cache when instructed to do so.
There are some magic numbers in use in the code, UNMAPPED_PAGE_RATIO and the number of pages to reclaim when unmapped_page_control argument is supplied. These numbers were chosen to avoid aggressiveness in reaping page cache ever so frequently, at the same time providing control.
The sysctl for min_unmapped_ratio provides further control from within the guest on the amount of unmapped pages to reclaim.
Data from the previous patchsets can be found at
https://lkml.org/lkml/2010/11/30/79
Size measurement
CONFIG_UNMAPPED_PAGECACHE_CONTROL and CONFIG_NUMA enabled
# size mm/built-in.o text data bss dec hex filename 419431 1883047 140888 2443366 254866 mm/built-in.o
CONFIG_UNMAPPED_PAGECACHE_CONTROL disabled, CONFIG_NUMA enabled
# size mm/built-in.o text data bss dec hex filename 418908 1883023 140888 2442819 254643 mm/built-in.o
---
Balbir Singh (3):
Move zone_reclaim() outside of CONFIG_NUMA Refactor zone_reclaim, move reusable functionality outside Provide control over unmapped pages
Documentation/kernel-parameters.txt | 8 ++ include/linux/mmzone.h | 4 + include/linux/swap.h | 21 +++++- init/Kconfig | 12 +++ kernel/sysctl.c | 20 +++-- mm/page_alloc.c | 9 ++ mm/vmscan.c | 132 +++++++++++++++++++++++++++++++---- 7 files changed, 175 insertions(+), 31 deletions(-)
Signature · 2 lines
Three Cheers, Balbir
PATCH 1/3 Move zone_reclaim() outside of CONFIG_NUMA (v2)
Changelog v2
Moved sysctl for min_unmapped_ratio as well
This patch moves zone_reclaim and associated helpers outside CONFIG_NUMA. This infrastructure is reused in the patches for page cache control that follow.
--- include/linux/mmzone.h | 4 ++-- include/linux/swap.h | 4 ++-- kernel/sysctl.c | 18 +++++++++--------- mm/vmscan.c | 2 -- 4 files changed, 13 insertions(+), 15 deletions(-)
include/linux/mmzone.h +2 -2
@@ -302,12 +302,12 @@ struct zone {*/ unsigned long lowmem_reserve[MAX_NR_ZONES ]; -#ifdef CONFIG_NUMA -int node;/* * zone reclaim becomes active if more unmapped pages exist. */ unsigned long min_unmapped_pages; +#ifdef CONFIG_NUMA +int node;unsigned long min_slab_pages;#endif struct per_cpu_pageset __percpu *pageset;
include/linux/swap.h +2 -2
@@ -253,11 +253,11 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; +extern int sysctl_min_unmapped_ratio; +extern int zone_reclaim (struct zone *,gfp_t ,unsigned int );#ifdef CONFIG_NUMA extern int zone_reclaim_mode; -extern int sysctl_min_unmapped_ratio;extern int sysctl_min_slab_ratio; -extern int zone_reclaim (struct zone *,gfp_t ,unsigned int );#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)
kernel/sysctl.c +9 -9
@@ -1211,15 +1211,6 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, },#endif -#ifdef CONFIG_NUMA - { - .procname = "zone_reclaim_mode", - .data = &zone_reclaim_mode, - .maxlen = sizeof(zone_reclaim_mode), - .mode = 0644, - .proc_handler = proc_dointvec, - .extra1 = &zero, - }, { .procname = "min_unmapped_ratio", .data = &sysctl_min_unmapped_ratio,
@@ -1229,6 +1220,15 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &one_hundred, }, +#ifdef CONFIG_NUMA + { + .procname = "zone_reclaim_mode", + .data = &zone_reclaim_mode, + .maxlen = sizeof(zone_reclaim_mode), + .mode = 0644, + .proc_handler = proc_dointvec, + .extra1 = &zero, + }, { .procname = "min_slab_ratio", .data = &sysctl_min_slab_ratio,
mm/vmscan.c +0 -2
@@ -2740,7 +2740,6 @@ static int __init kswapd_init(void)module_init (kswapd_init) -#ifdef CONFIG_NUMA/* * Zone reclaim mode *
@@ -2950,7 +2949,6 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)return ret; } -#endif /* * page_evictable - test whether a page is evictable
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 Refactor zone_reclaim (v2)
In reply to Balbir SinghMove reusable functionality outside of zone_reclaim. Make zone_reclaim_unmapped_pages modular
--- mm/vmscan.c | 35 +++++++++++++++++++++++------------ 1 files changed, 23 insertions(+), 12 deletions(-)
mm/vmscan.c +23 -12
@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) }/* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, +unsigned long nr_pages) +{ +int priority; +/* +* Free memory by calling shrink zone with increasing +* priorities until we have enough memory freed. +*/ + priority =ZONE_RECLAIM_PRIORITY ; +do { +shrink_zone (priority, zone, sc); + priority--; + }while (priority >=0 && sc->nr_reclaimed < nr_pages); +} + +/* * Try to free up some pages from this zone through reclaim. */ static int __zone_reclaim (struct zone *zone,gfp_t gfp_mask,unsigned int order)
@@ -2823,7 +2844,6 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)const unsigned long nr_pages =1 << order;struct task_struct *p = current;struct reclaim_state reclaim_state; -int priority;struct scan_control sc = { .may_writepage = !!(zone_reclaim_mode &RECLAIM_WRITE ), .may_unmap = !!(zone_reclaim_mode &RECLAIM_SWAP ),
@@ -2847,17 +2867,8 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) reclaim_state.reclaimed_slab =0 ; p->reclaim_state = &reclaim_state; -if (zone_pagecache_reclaimable (zone) > zone->min_unmapped_pages) { -/* -* Free memory by calling shrink zone with increasing -* priorities until we have enough memory freed. -*/ - priority =ZONE_RECLAIM_PRIORITY ; -do { -shrink_zone (priority, zone, &sc); - priority--; - }while (priority >=0 && sc.nr_reclaimed < nr_pages); - } +if (zone_pagecache_reclaimable (zone) > zone->min_unmapped_pages) +zone_reclaim_unmapped_pages (zone, &sc, nr_pages); nr_slab_pages0 =zone_page_state (zone,NR_SLAB_RECLAIMABLE );if (nr_slab_pages0 > zone->min_slab_pages) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] Refactor zone_reclaim (v2)
Hi Balbir,
Quoted 25 lines · Balbir Singh
Move reusable functionality outside of
zone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>---
mm/vmscan.c | 35 +++++++++++++++++++++++------------1 files changed, 23 insertions(+), 12 deletions(-)mm/vmscan.c +9
-0@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) } /* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, + unsigned long nr_pages) +{ + int priority;
mm/vmscan.c static long zone_pagecache_reclaimable(struct zone *zone) · line 2836
Quoted 10 lines
mm/vmscan.c +10
-0+ /* + * Free memory by calling shrink zone with increasing + * priorities until we have enough memory freed. + */ + priority = ZONE_RECLAIM_PRIORITY; + do { + shrink_zone(priority, zone, sc); + priority--; + } while (priority >= 0 && sc->nr_reclaimed < nr_pages); +}
As I said previous version, zone_reclaim_unmapped_pages doesn't have any functions related to reclaim unmapped pages.
The function name is rather strange.
It would be better to add scan_control setup in function inner to reclaim only unmapped pages.
Signature · 9 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] Refactor zone_reclaim (v2)
Quoted 34 lines · MinChan Kim
Hi Balbir,
Quoted 30 lines · Balbir Singh
Move reusable functionality outside of
zone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>---
mm/vmscan.c | 35 +++++++++++++++++++++++------------1 files changed, 23 insertions(+), 12 deletions(-)mm/vmscan.c +14
-0@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) } /* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, + unsigned long nr_pages) +{ + int priority; + /* + * Free memory by calling shrink zone with increasing + * priorities until we have enough memory freed. + */ + priority = ZONE_RECLAIM_PRIORITY;
Quoted 8 lines
mm/vmscan.c static long zone_pagecache_reclaimable(struct zone *zone) · line 2836
Quoted 5 lines
mm/vmscan.c +5
-0+ do { + shrink_zone(priority, zone, sc); + priority--; + } while (priority >= 0 && sc->nr_reclaimed < nr_pages); +}As I said previous version,
zone_reclaim_unmapped_pagesdoesn't have any functions related to reclaim unmapped pages.
The scan control point has the right arguments for implementing reclaim of unmapped pages.
Quoted 7 lines
The function name is rather strange.
It would be better to addscan_controlsetup in function inner to reclaim only unmapped pages.Signature · 2 lines
Kind regards, Minchan Kim
Signature · 9 lines
Three Cheers, Balbir -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] Refactor zone_reclaim (v2)
Quoted 45 lines · Balbir Singh
Quoted 34 lines · MinChan Kim
Hi Balbir,
Quoted 30 lines · Balbir Singh
Move reusable functionality outside of
zone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>---
mm/vmscan.c | 35 +++++++++++++++++++++++------------1 files changed, 23 insertions(+), 12 deletions(-)mm/vmscan.c +14
-0@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) } /* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, + unsigned long nr_pages) +{ + int priority; + /* + * Free memory by calling shrink zone with increasing + * priorities until we have enough memory freed. + */ + priority = ZONE_RECLAIM_PRIORITY;Quoted 8 lines
mm/vmscan.c static long zone_pagecache_reclaimable(struct zone *zone) · line 2836
Quoted 5 lines
mm/vmscan.c +5
-0+ do { + shrink_zone(priority, zone, sc); + priority--; + } while (priority >= 0 && sc->nr_reclaimed < nr_pages); +}As I said previous version,
zone_reclaim_unmapped_pagesdoesn't have any functions related to reclaim unmapped pages.
Quoted 2 lines
The scan control point has the right arguments for implementing reclaim of unmapped pages.
I mean you should set up scan_control setup in this function. Current zone_reclaim_unmapped_pages doesn't have any specific routine related to reclaim unmapped pages.
Otherwise, change the function name with just "zone_reclaim_pages". I think you don't want it.
Signature · 9 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] Refactor zone_reclaim (v2)
Quoted 46 lines · MinChan Kim
Quoted 45 lines · Balbir Singh
Quoted 42 lines · MinChan Kim
Hi Balbir,
Quoted 25 lines · Balbir Singh
Move reusable functionality outside of
zone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>---
mm/vmscan.c | 35 +++++++++++++++++++++++------------1 files changed, 23 insertions(+), 12 deletions(-)mm/vmscan.c +9
-0@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) } /* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, + unsigned long nr_pages) +{ + int priority;mm/vmscan.c static long zone_pagecache_reclaimable(struct zone *zone) · line 2836
Quoted 10 lines
mm/vmscan.c +10
-0+ /* + * Free memory by calling shrink zone with increasing + * priorities until we have enough memory freed. + */ + priority = ZONE_RECLAIM_PRIORITY; + do { + shrink_zone(priority, zone, sc); + priority--; + } while (priority >= 0 && sc->nr_reclaimed < nr_pages); +}As I said previous version,
zone_reclaim_unmapped_pagesdoesn't have any functions related to reclaim unmapped pages.
Quoted 8 lines
Quoted 2 lines
The scan control point has the right arguments for implementing reclaim of unmapped pages.
I mean you should set up
scan_controlsetup in this function. Currentzone_reclaim_unmapped_pagesdoesn't have any specific routine related to reclaim unmapped pages.
Otherwise, change the function name with just "zone_reclaim_pages". I think you don't want it.
Done, I renamed the function to zone_reclaim_pages.
Thanks!
Signature · 9 lines
Three Cheers, Balbir -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 2/3] Refactor zone_reclaim (v2)
In reply to Minchan KimQuoted 37 lines · MinChan Kim
Hi Balbir,
Quoted 33 lines · Balbir Singh
Move reusable functionality outside of
zone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>---
mm/vmscan.c | 35 +++++++++++++++++++++++------------1 files changed, 23 insertions(+), 12 deletions(-)mm/vmscan.c +17
-0@@ -2815,6 +2815,27 @@ static long zone_pagecache_reclaimable(struct zone *zone) } /* +* Helper function to reclaim unmapped pages, we might add something +* similar to this for slab cache as well. Currently this function +* is shared with __zone_reclaim() +*/ +static inline void +zone_reclaim_unmapped_pages (struct zone *zone,struct scan_control *sc, + unsigned long nr_pages) +{ + int priority; + /* + * Free memory by calling shrink zone with increasing + * priorities until we have enough memory freed. + */ + priority = ZONE_RECLAIM_PRIORITY; + do { + shrink_zone(priority, zone, sc); + priority--;
Quoted 8 lines
mm/vmscan.c static long zone_pagecache_reclaimable(struct zone *zone) · line 2836
Quoted 2 lines
mm/vmscan.c +2
-0+ } while (priority >= 0 && sc->nr_reclaimed < nr_pages); +}As I said previous version,
zone_reclaim_unmapped_pagesdoesn't have any functions related to reclaim unmapped pages.
The function name is rather strange.
It would be better to addscan_controlsetup in function inner to reclaim only unmapped pages.
OK, that is an idea worth looking at, I'll revisit this function.
Thanks for the review!
Signature · 2 lines
Three Cheers, Balbir
PATCH 3/3 Provide control over unmapped pages (v2)
In reply to Balbir SinghChangelog v2
1. Use a config option to enable the code (Andrew Morton)
2. Explain the magic tunables in the code or at-least attempt to explain them (General comment)
3. Hint uses of the boot parameter with unlikely (Andrew Morton)
4. Use better names (balanced is not a good naming convention)
5. Updated Documentation/kernel-parameters.txt (Andrew Morton)
Provide control using zone_reclaim() and a boot parameter. The code reuses functionality from zone_reclaim() to isolate unmapped pages and reclaim them as a priority, ahead of other mapped pages.
--- Documentation/kernel-parameters.txt | 8 +++ include/linux/swap.h | 21 ++++++-- init/Kconfig | 12 ++++ kernel/sysctl.c | 2 + mm/page_alloc.c | 9 +++ mm/vmscan.c | 97 +++++++++++++++++++++++++++++++++++ 6 files changed, 142 insertions(+), 7 deletions(-)
Documentation/kernel-parameters.txt +8 -0
@@ -2515,6 +2515,14 @@ and is between 256 and 4096 characters. It is defined in the file [X86] Set unknown_nmi_panic=1 early on boot. + unmapped_page_control + [KNL] Available if CONFIG_UNMAPPED_PAGECACHE_CONTROL + is enabled. It controls the amount of unmapped memory + that is present in the system. This boot option plus + vm.min_unmapped_ratio (sysctl) provide granular control + over how much unmapped page cache can exist in the system + before kswapd starts reclaiming unmapped page cache pages. + usbcore.autosuspend= [USB] The autosuspend time delay (in seconds) used for newly-detected USB devices (default 2). This
include/linux/swap.h +17 -4
@@ -253,19 +253,32 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) || defined(CONFIG_NUMA )extern int sysctl_min_unmapped_ratio;extern int zone_reclaim (struct zone *,gfp_t ,unsigned int ); -#ifdef CONFIG_NUMA -extern int zone_reclaim_mode; -extern int sysctl_min_slab_ratio;#else -#define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order) {return 0 ; }#endif +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) +extern bool should_reclaim_unmapped_pages (struct zone *zone); +#else +static inline bool should_reclaim_unmapped_pages (struct zone *zone) +{ +return false; +} +#endif + +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode; +extern int sysctl_min_slab_ratio; +#else +#define zone_reclaim_mode 0 +#endif +extern int page_evictable (struct page *page,struct vm_area_struct *vma);extern void scan_mapping_unevictable_pages (struct address_space *);
init/Kconfig +12 -0
@@ -782,6 +782,18 @@ endif # NAMESPACES config MM_OWNER bool +config UNMAPPED_PAGECACHE_CONTROL + bool "Provide control over unmapped page cache" + default n + help + This option adds support for controlling unmapped page cache + via a boot parameter (unmapped_page_control). The boot parameter + with sysctl (vm.min_unmapped_ratio) control the total number + of unmapped pages in the system. This feature is useful if + you want to limit the amount of unmapped page cache or want + to reduce page cache duplication in a virtualized environment. + If unsure say 'N' + config SYSFS_DEPRECATED bool "enable deprecated sysfs features to support old userspace tools" depends on SYSFS
kernel/sysctl.c +2 -0
@@ -1211,6 +1211,7 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, },#endif +#if defined(CONFIG_UNMAPPED_PAGE_CONTROL ) || defined(CONFIG_NUMA ) { .procname = "min_unmapped_ratio", .data = &sysctl_min_unmapped_ratio,
@@ -1220,6 +1221,7 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &one_hundred, }, +#endif #ifdef CONFIG_NUMA { .procname = "zone_reclaim_mode",
mm/page_alloc.c +7 -2
@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret; +if (should_reclaim_unmapped_pages (zone)) +wakeup_kswapd (zone, order); + mark = zone->watermark[alloc_flags &ALLOC_WMARK_MASK ];if (zone_watermark_ok (zone, order, mark, classzone_idx, alloc_flags))
@@ -4154,10 +4157,12 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat, zone->spanned_pages = size; zone->present_pages = realsize; -#ifdef CONFIG_NUMA - zone->node = nid; +#if defined(CONFIG_UNMAPPED_PAGE_CONTROL ) || defined(CONFIG_NUMA ) zone->min_unmapped_pages = (realsize*sysctl_min_unmapped_ratio) /100 ; +#endif +#ifdef CONFIG_NUMA + zone->node = nid; zone->min_slab_pages = (realsize * sysctl_min_slab_ratio) /100 ;#endif zone->name = zone_names[j];
mm/vmscan.c +96 -1
133 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] Provide control over unmapped pages (v2)
Quoted 130 lines · Balbir Singh
Changelog v2
1. Use a config option to enable the code (Andrew Morton)
2. Explain the magic tunables in the code or at-least attempt to explain them (General comment)
3. Hint uses of the boot parameter with unlikely (Andrew Morton)
4. Use better names (balanced is not a good naming convention)
5. UpdatedDocumentation/kernel-parameters.txt(Andrew Morton)Provide control using
zone_reclaim()and a boot parameter. The code reuses functionality fromzone_reclaim()to isolate unmapped pages and reclaim them as a priority, ahead of other mapped pages.Signed-off-by Balbir Singh <[email protected]>---
Documentation/kernel-parameters.txt | 8 +++include/linux/swap.h| 21 ++++++--
init/Kconfig | 12 ++++
kernel/sysctl.c | 2 +
mm/page_alloc.c | 9 +++
mm/vmscan.c | 97 +++++++++++++++++++++++++++++++++++6 files changed, 142 insertions(+), 7 deletions(-)Documentation/kernel-parameters.txt +0
-0@@ -2515,6 +2515,14 @@ and is between 256 and 4096 characters. It is defined in the file[X86]
Set unknown_nmi_panic=1 early on boot.+
unmapped_page_control
+ [KNL] Available ifCONFIG_UNMAPPED_PAGECACHE_CONTROL
+ is enabled. It controls the amount of unmapped memory
+ that is present in the system. This boot option plus
+ vm.min_unmapped_ratio (sysctl) provide granular control
+ over how much unmapped page cache can exist in the system
+ before kswapd starts reclaiming unmapped page cache pages. +
usbcore.autosuspend=
[USB] The autosuspend time delay (in seconds) used for newly-detected USB devices (default 2). Thisinclude/linux/swap.h +17
-4@@ -253,19 +253,32 @@ extern int vm_swappiness; extern int remove_mapping(struct address_space *mapping, struct page *page); extern long vm_total_pages; +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) || defined(CONFIG_NUMA ) extern int sysctl_min_unmapped_ratio; extern int zone_reclaim(struct zone *, gfp_t, unsigned int); -#ifdef CONFIG_NUMA -extern int zone_reclaim_mode; -extern int sysctl_min_slab_ratio; #else -#define zone_reclaim_mode 0 static inline int zone_reclaim(struct zone *z, gfp_t mask, unsigned int order) { return 0; } #endif +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) +extern bool should_reclaim_unmapped_pages (struct zone *zone); +#else +static inline bool should_reclaim_unmapped_pages (struct zone *zone) +{ + return false; +} +#endif + +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode; +extern int sysctl_min_slab_ratio; +#else +#define zone_reclaim_mode 0 +#endif + extern int page_evictable(struct page *page, struct vm_area_struct *vma); extern void scan_mapping_unevictable_pages(struct address_space *);init/Kconfig +0
-0@@ -782,6 +782,18 @@ endif # NAMESPACESconfig
MM_OWNER
boolinit/Kconfig +12
-0+config UNMAPPED_PAGECACHE_CONTROL + bool "Provide control over unmapped page cache" + default n + help + This option adds support for controlling unmapped page cache + via a boot parameter (unmapped_page_control). The boot parameter + with sysctl (vm.min_unmapped_ratio) control the total number + of unmapped pages in the system. This feature is useful if + you want to limit the amount of unmapped page cache or want + to reduce page cache duplication in a virtualized environment. + If unsure say 'N' +config
SYSFS_DEPRECATED
bool "enable deprecated sysfs features to support old userspace tools" depends on SYSFSkernel/sysctl.c +2
-0@@ -1211,6 +1211,7 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, }, #endif +#if defined(CONFIG_UNMAPPED_PAGE_CONTROL ) || defined(CONFIG_NUMA ) { .procname = "min_unmapped_ratio", .data = &sysctl_min_unmapped_ratio,@@ -1220,6 +1221,7 @@ static struct ctl_table vm_table[] = { .extra1 = &zero, .extra2 = &one_hundred, }, +#endif #ifdef CONFIG_NUMA { .procname = "zone_reclaim_mode",mm/page_alloc.c +0
-0
mm/page_alloc.c zonelist_scan: · line 1666
Quoted 5 lines
mm/page_alloc.c +2
-0@@ -1662,6 +1662,9 @@ zonelist_scan: unsigned long mark; int ret; + if (should_reclaim_unmapped_pages(zone)) + wakeup_kswapd(zone, order);
I think we can put the logic into zone_watermark_okay.
Quoted 54 lines
mm/page_alloc.c +5
-2+ mark = zone->watermark[alloc_flags & ALLOC_WMARK_MASK]; if (zone_watermark_ok(zone, order, mark, classzone_idx, alloc_flags))@@ -4154,10 +4157,12 @@ static void __paginginit free_area_init_core(struct pglist_data *pgdat, zone->spanned_pages = size; zone->present_pages = realsize; -#ifdef CONFIG_NUMA - zone->node = nid; +#if defined(CONFIG_UNMAPPED_PAGE_CONTROL ) || defined(CONFIG_NUMA ) zone->min_unmapped_pages = (realsize*sysctl_min_unmapped_ratio) / 100; +#endif +#ifdef CONFIG_NUMA + zone->node = nid; zone->min_slab_pages = (realsize * sysctl_min_slab_ratio) / 100; #endif zone->name = zone_names[j];mm/vmscan.c +23
-0@@ -158,6 +158,29 @@ static DECLARE_RWSEM(shrinker_rwsem); #define scanning_global_lru(sc) (1) #endif +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) +static unsigned long reclaim_unmapped_pages (int priority,struct zone *zone, + struct scan_control *sc); +static int unmapped_page_control__read_mostly ; + +static int __init unmapped_page_control_parm (char *str) +{ + unmapped_page_control = 1; + /* + * XXX: Should we tweak swappiness here? + */ + return 1; +} +__setup ("unmapped_page_control" , unmapped_page_control_parm); + +#else /* !CONFIG_UNMAPPED_PAGECACHE_CONTROL */ +static inline unsigned long reclaim_unmapped_pages (int priority, + struct zone *zone, struct scan_control *sc) +{ + return 0; +} +#endif + static struct zone_reclaim_stat *get_reclaim_stat(struct zone *zone, struct scan_control *sc) {
mm/vmscan.c loop_again: · line 2327
Quoted 8 lines
mm/vmscan.c +5
-0@@ -2297,6 +2320,12 @@ loop_again: shrink_active_list(SWAP_CLUSTER_MAX, zone, &sc, priority, 0); + /* + * We do unmapped page reclaim once here and once + * below, so that we don't lose out + */ + reclaim_unmapped_pages(priority, zone, &sc);
It can make unnecessary stir of lru pages.
How about this?zone_watermark_ok returns ZONE_UNMAPPED_PAGE_FULL. wakeup_kswapd(..., please reclaim unmapped page cache).
If kswapd is woke up by unmapped page full, kswapd sets up sc with unmap = 0. If the kswapd try to reclaim unmapped page, shrink_page_list doesn't rotate non-unmapped pages.
mm/vmscan.c loop_again: · line 2368
Quoted 13 lines
mm/vmscan.c +6
-0+ if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone), 0, 0)) { end_zone = i;@@ -2332,6 +2361,11 @@ loop_again: continue; sc.nr_scanned = 0; + /* + * Reclaim unmapped pages upfront, this should be + * really cheap + */ + reclaim_unmapped_pages(priority, zone, &sc);
Remove the hacky code.
Quoted 39 lines
mm/vmscan.c +17
-1/** Call soft limit reclaim before calling shrink_zone. @@ -2587,7 +2621,8 @@ void wakeup_kswapd(struct zone *zone, int order) pgdat->kswapd_max_order = order; if (!waitqueue_active(&pgdat->kswapd_wait)) return; - if (zone_watermark_ok_safe(zone, order, low_wmark_pages(zone), 0, 0)) + if (zone_watermark_ok_safe(zone, order, low_wmark_pages(zone), 0, 0) && + !should_reclaim_unmapped_pages(zone)) return; trace_mm_vmscan_wakeup_kswapd(pgdat->node_id, zone_idx(zone), order);@@ -2740,6 +2775,7 @@ static int __init kswapd_init(void) module_init(kswapd_init) +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) || defined(CONFIG_NUMA ) /** Zone reclaim mode * @@ -2960,6 +2996,65 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) return ret; } +#endif + +#if defined(CONFIG_UNMAPPED_PAGECACHE_CONTROL ) +/* +* Routine to reclaim unmapped pages, inspired from the code under +* CONFIG_NUMA that does unmapped page and slab page control by keeping +* min_unmapped_pages in the zone. We currently reclaim just unmapped +* pages, slab control will come in soon, at which point this routine +* should be called reclaim cached pages +*/ +unsigned long reclaim_unmapped_pages (int priority,struct zone *zone, + struct scan_control *sc) +{ + if (unlikely(unmapped_page_control) &&
mm/vmscan.c int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) · line 3022
Quoted 10 lines
mm/vmscan.c +10
-0+ (zone_unmapped_file_pages(zone) > zone->min_unmapped_pages)) { + struct scan_control nsc; + unsigned long nr_pages; + + nsc = *sc; + + nsc.swappiness = 0; + nsc.may_writepage = 0; + nsc.may_unmap = 0; + nsc.nr_reclaimed = 0;
This logic can be put in zone_reclaim_unmapped_pages.
Quoted 30 lines
mm/vmscan.c +28
-0+ + nr_pages = zone_unmapped_file_pages(zone) - + zone->min_unmapped_pages; + /* + * We don't want to be too aggressive with our + * reclaim, it is our best effort to control + * unmapped pages + */ + nr_pages >>= 3; + + zone_reclaim_unmapped_pages(zone, &nsc, nr_pages); + return nsc.nr_reclaimed; + } + return 0; +} + +/* +* 16 is a magic number that was pulled out of a magician's +* hat. This number automatically provided the best performance +* to memory usage (unmapped pages). Lower than this and we spend +* a lot of time in frequent reclaims, higher and our control is +* weakend. +*/ +#define UNMAPPED_PAGE_RATIO 16 + +bool should_reclaim_unmapped_pages (struct zone *zone) +{ + if (unlikely(unmapped_page_control) &&
mm/vmscan.c int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) · line 3060
Quoted 10 lines
mm/vmscan.c +7
-0+ (zone_unmapped_file_pages(zone) > + UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages)) + return true; + return false; +} +#endif + /** page_evictable - test whether a page is evictable
As I look first, the code isn't good shape. But more important thing is how many there are users. Could we pay cost to maintain feature few user?
It depends on your effort which proves the usage cases and benefit. It would be good to give a real data.
If we want really this, how about the new cache lru idea as Kame suggests? For example, add_to_page_cache_lru adds the page into cache lru. page_add_file_rmap moves the page into inactive file. page_remove_rmap moves the page into lru cache, again.
We can count the unmapped pages and if the size exceeds limit, we can wake up kswapd.
whenever the memory pressure happens, first of all, reclaimer try to reclaim cache lru.
It can enhance reclaim latency and is good to embedded people.
Signature · 2 lines
Kind regards, Minchan Kim
Re: [PATCH 3/3] Provide control over unmapped pages (v2)
Quoted 5 lines · MinChan Kim
Quoted 2 lines
+ if (
should_reclaim_unmapped_pages(zone))
+wakeup_kswapd(zone, order);I think we can put the logic into
zone_watermark_okay.
I did some checks and zone_watermark_ok is used in several places for a generic check like this -- for example prior to zone_reclaim(), if in get_page_from_freelist() we skip zones based on the return value. The compaction code uses it as well, the impact would be deeper. The compaction code uses it to check whether an allocation will succeed or not, I don't want unmapped page control to impact that.
Quoted 6 lines
Quoted 5 lines
+ /*
+ * We do unmapped page reclaim once here and once
+ * below, so that we don't lose out
+ */
+reclaim_unmapped_pages(priority, zone, &sc);
Quoted 7 lines
It can make unnecessary stir of lru pages.
How about this?zone_watermark_okreturnsZONE_UNMAPPED_PAGE_FULL.wakeup_kswapd(..., please reclaim unmapped page cache).
If kswapd is woke up by unmapped page full, kswapd sets up sc with unmap = 0. If the kswapd try to reclaim unmapped page,shrink_page_listdoesn't rotate non-unmapped pages.
With may_unmap set to 0 and may_writepage set to 0, I don't think this should be a major problem, like I said this code is already enabled if zone_reclaim_mode != 0 and CONFIG_NUMA is set.
Quoted 8 lines
Quoted 8 lines
mm/vmscan.c +8
-0+unsigned long reclaim_unmapped_pages (int priority,struct zone *zone, + struct scan_control *sc) +{ + if (unlikely(unmapped_page_control) && + (zone_unmapped_file_pages(zone) > zone->min_unmapped_pages)) { + struct scan_control nsc; + unsigned long nr_pages; +
Quoted 9 lines
Quoted 6 lines
+ nsc = *sc;
+
+ nsc.swappiness = 0;
+ nsc.may_writepage = 0;
+ nsc.may_unmap = 0;
+ nsc.nr_reclaimed = 0;This logic can be put in
zone_reclaim_unmapped_pages.
Now that I refactored the code and called it zone_reclaim_pages, I expect the correct sc to be passed to it. This code is reused between zone_reclaim() and reclaim_unmapped_pages(). In the former, zone_reclaim does the setup.
Quoted 8 lines
If we want really this, how about the new cache lru idea as Kame suggests? For example,
add_to_page_cache_lruadds the page into cache lru.page_add_file_rmapmoves the page into inactive file.page_remove_rmapmoves the page into lru cache, again.
We can count the unmapped pages and if the size exceeds limit, we can wake up kswapd.
whenever the memory pressure happens, first of all, reclaimer try to reclaim cache lru.
We already have a file LRU and that has active/inactive lists, I don't think a special mapped/unmapped list makes sense at this point.
Signature · 9 lines
Three Cheers, Balbir -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/3] Provide control over unmapped pages (v2)
Quoted 8 lines · Balbir Singh
Quoted 5 lines · MinChan Kim
Quoted 2 lines
+ if (
should_reclaim_unmapped_pages(zone))
+wakeup_kswapd(zone, order);I think we can put the logic into
zone_watermark_okay.
Quoted 6 lines
I did some checks and
zone_watermark_okis used in several places for a generic check like this -- for example prior tozone_reclaim(), if inget_page_from_freelist()we skip zones based on the return value. The compaction code uses it as well, the impact would be deeper. The compaction code uses it to check whether an allocation will succeed or not, I don't want unmapped page control to impact that.
Agree.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
+ /*
+ * We do unmapped page reclaim once here and once
+ * below, so that we don't lose out
+ */
+reclaim_unmapped_pages(priority, zone, &sc);Quoted 7 lines
It can make unnecessary stir of lru pages.
How about this?zone_watermark_okreturnsZONE_UNMAPPED_PAGE_FULL.wakeup_kswapd(..., please reclaim unmapped page cache).
If kswapd is woke up by unmapped page full, kswapd sets up sc with unmap = 0. If the kswapd try to reclaim unmapped page,shrink_page_listdoesn't rotate non-unmapped pages.
Quoted 3 lines
With
may_unmapset to 0 andmay_writepageset to 0, I don't think this should be a major problem, like I said this code is already enabled ifzone_reclaim_mode!= 0 andCONFIG_NUMAis set.
True. It has been already in there.
But it is only NUMA and you are going to take out of NUMA. That's why I have a concern.
I want to make this usefully in embedded.
Recently ChromOS try to protect mapped page so I think your series hep the situation.
But frequent shrink unmapped pages makes stir of LRU which victim mapped page(ie, tail of inactive file) can move into head of inactive file. After all, LRU ordering makes confused so that NOT-LRU page can be evicted.
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
mm/vmscan.c +4
-0+unsigned long reclaim_unmapped_pages (int priority,struct zone *zone, + struct scan_control *sc) +{ + if (unlikely(unmapped_page_control) &&mm/vmscan.c int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) · line 3022
Quoted 10 lines
mm/vmscan.c +10
-0+ (zone_unmapped_file_pages(zone) > zone->min_unmapped_pages)) { + struct scan_control nsc; + unsigned long nr_pages; + + nsc = *sc; + + nsc.swappiness = 0; + nsc.may_writepage = 0; + nsc.may_unmap = 0; + nsc.nr_reclaimed = 0;This logic can be put in
zone_reclaim_unmapped_pages.
Quoted 4 lines
Now that I refactored the code and called it
zone_reclaim_pages, I expect the correct sc to be passed to it. This code is reused betweenzone_reclaim()andreclaim_unmapped_pages(). In the former,zone_reclaimdoes the setup.
Thanks.
Quoted 10 lines
Quoted 9 lines
If we want really this, how about the new cache lru idea as Kame suggests? For example,
add_to_page_cache_lruadds the page into cache lru.page_add_file_rmapmoves the page into inactive file.page_remove_rmapmoves the page into lru cache, again.
We can count the unmapped pages and if the size exceeds limit, we can wake up kswapd.
whenever the memory pressure happens, first of all, reclaimer try to reclaim cache lru.
Quoted 2 lines
We already have a file LRU and that has active/inactive lists, I don't think a special mapped/unmapped list makes sense at this point.
That's for reclaim latency for embedded use case but I think it would have benefit in desktop, too.
But it can be another patch series so I don't insist on.
Thanks, Balbir.
Quoted 6 lines
--
Three Cheers,
Balbir
Signature · 9 lines
Kind regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>