Series short description
Subsystems (7)
cover Series short description
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
http://www.mail-archive.com/[email protected]/msg43654.html
Christoph Lamater recommended splitting out patch 1, which is what this series does
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.
For a single VM - running kernbench
Enabled
Optimal load -j 8 run number 1...
Optimal load -j 8 run number 2...
Optimal load -j 8 run number 3...
Optimal load -j 8 run number 4...
Optimal load -j 8 run number 5...
Average Optimal load -j 8 Run (std deviation):
Elapsed Time 273.726 (1.2683)
User Time 190.014 (0.589941)
System Time 298.758 (1.72574)
Percent CPU 178 (0)
Context Switches 119953 (865.74)
Sleeps 38758 (795.074)
Disabled
Optimal load -j 8 run number 1...
Optimal load -j 8 run number 2...
Optimal load -j 8 run number 3...
Optimal load -j 8 run number 4...
Optimal load -j 8 run number 5...
Average Optimal load -j 8 Run (std deviation):
Elapsed Time 272.672 (0.453178)
User Time 189.7 (0.718157)
System Time 296.77 (0.845606)
Percent CPU 178 (0)
Context Switches 118822 (277.434)
Sleeps 37542.8 (545.922)
More data on the test results with the earlier patch is at http://www.mail-archive.com/[email protected]/msg43655.html
---
Balbir Singh (3):
Move zone_reclaim() outside of CONFIG_NUMA Refactor zone_reclaim, move reusable functionality outside Provide control over unmapped pages
include/linux/mmzone.h | 4 +- include/linux/swap.h | 5 +- mm/page_alloc.c | 7 ++- mm/vmscan.c | 109 +++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 104 insertions(+), 21 deletions(-)
Signature · 1 line
Balbir
PATCH 1/3 Move zone_reclaim() outside of CONFIG_NUMA
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 ++-- mm/vmscan.c | 2 -- 2 files changed, 2 insertions(+), 4 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;
mm/vmscan.c +0 -2
@@ -2644,7 +2644,6 @@ static int __init kswapd_init(void)module_init (kswapd_init) -#ifdef CONFIG_NUMA/* * Zone reclaim mode *
@@ -2854,7 +2853,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>
Re: [PATCH 1/3] Move zone_reclaim() outside of CONFIG_NUMA
Andrew Morton
maintainerRe: [PATCH 1/3] Move zone_reclaim() outside of CONFIG_NUMA
In reply to Balbir SinghQuoted 4 lines · On Tue, 30 Nov 2010 15:45:12 +0530 Balbir Singh <[email protected]>…
This patch moves
zone_reclaimand associated helpers outsideCONFIG_NUMA. This infrastructure is reused in the patches for page cache control that follow.
Thereby adding a nice dollop of bloat to everyone's kernel. I don't think that is justifiable given that the audience for this feature is about eight people :(
How's about CONFIG_UNMAPPED_PAGECACHE_CONTROL?
Also this patch instantiates sysctl_min_unmapped_ratio and sysctl_min_slab_ratio on non-NUMA builds but fails to make those tunables actually tunable in procfs. Changes to sysctl.c are needed.
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>
More careful reviewers, please.
--
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>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 1/3] Move zone_reclaim() outside of CONFIG_NUMA
Quoted 21 lines · Balbir Singh
Quoted 8 lines · Andrew Morton
Quoted 4 lines · On Tue, 30 Nov 2010 15:45:12 +0530 Balbir Singh <[email protected]>…
This patch moves
zone_reclaimand associated helpers outsideCONFIG_NUMA. This infrastructure is reused in the patches for page cache control that follow.Quoted 6 lines
Thereby adding a nice dollop of bloat to everyone's kernel. I don't think that is justifiable given that the audience for this feature is about eight people :(
How's about
CONFIG_UNMAPPED_PAGECACHE_CONTROL?OK, I'll add the config, but this code is enabled under
CONFIG_NUMAtoday, so the bloat I agree is more for non NUMA users. I'll makeCONFIG_UNMAPPED_PAGECACHE_CONTROLdefault ifCONFIG_NUMAis set.
Quoted 10 lines
Quoted 5 lines
Also this patch instantiates
sysctl_min_unmapped_ratioandsysctl_min_slab_ratioon non-NUMA builds but fails to make those tunables actually tunable in procfs. Changes tosysctl.care needed.Oh! yeah.. I missed it while refactoring, my fault.
Quoted 2 lines
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>
My local MTA failed to deliver the message, trying again.
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>
PATCH 2/3 Refactor zone_reclaim
In reply to Balbir SinghRefactor zone_reclaim, move 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
@@ -2719,6 +2719,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)
@@ -2727,7 +2748,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 ),
@@ -2751,17 +2771,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) {
Re: [PATCH 2/3] Refactor zone_reclaim
--
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
In reply to Balbir SinghQuoted 4 lines · On Tue, 30 Nov 2010 15:45:55 +0530 Balbir Singh <[email protected]>…
Refactor
zone_reclaim, move reusable functionality outside ofzone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>
Why is this min_mapped_pages based on zone (IOW, per-zone) ?
Thanks,
-Kame
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 2/3] Refactor zone_reclaim
Quoted 10 lines · Balbir Singh
Quoted 8 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Tue, 30 Nov 2010 15:45:55 +0530 Balbir Singh <[email protected]>…
Refactor
zone_reclaim, move reusable functionality outside ofzone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>
Quoted 8 lines
Quoted 2 lines
Why is this
min_mapped_pagesbased on zone (IOW, per-zone) ?Kamezawa-San, this has been the design before the refactoring (it is based on
zone_reclaim_modeand reclaim based on top of that). I am reusing bits of existing technology. The advantage of it being per-zone is that it integrates well with kswapd.
My local MTA failed to deliver the message, trying again.
Signature · 2 lines
Three Cheers, Balbir
Re: [PATCH 2/3] Refactor zone_reclaim
Quoted 12 lines · On Wed, 1 Dec 2010 10:52:18 +0530 Balbir Singh <[email protected]>…
Quoted 10 lines · Balbir Singh
Quoted 8 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Tue, 30 Nov 2010 15:45:55 +0530 Balbir Singh <[email protected]>…
Refactor
zone_reclaim, move reusable functionality outside ofzone_reclaim. Makezone_reclaim_unmapped_pagesmodularSigned-off-by Balbir Singh <[email protected]>
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
Why is this
min_mapped_pagesbased on zone (IOW, per-zone) ?Kamezawa-San, this has been the design before the refactoring (it is based on
zone_reclaim_modeand reclaim based on top of that). I am reusing bits of existing technology. The advantage of it being per-zone is that it integrates well with kswapd.
Sorry, what I wanted to here was:
Why min_mapped_pages per zone ?
Why you don't add "limit_for_unmapped_page_cache_size" for the whole system ?
I guess what you really want is "limit_for_unmapped_page_cache_size".
Then, you have to use this kind of mysterious code. ==
(zone_unmapped_file_pages(zone) >
+ UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages))
Thanks,
-Kame
--
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
In reply to Balbir SinghHi Balbir,
Quoted 26 lines · Balbir Singh
Refactor
zone_reclaim, move reusable functionality outside ofzone_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 +10
-0@@ -2719,6 +2719,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 2741
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); +} +
I don't see any specific logic about naming "zone_reclaim_unmapped_pages" in your function.
Maybe, caller of this function have to handle sc->may_unmap. So, this function's naming
is not good.
As I see your logic, the function name would be just "zone_reclaim_pages" If you want to name it with zone_reclaim_unmapped_pages, it could be better with setting sc->may_unmap in this function.
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>
PATCH 3/3 Provide control over unmapped pages
In reply to Balbir SinghProvide 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.
--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)
include/linux/swap.h +3 -2
@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)
mm/page_alloc.c +5 -2
@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret; +if (should_balance_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))
@@ -4136,10 +4139,10 @@ 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; zone->min_unmapped_pages = (realsize*sysctl_min_unmapped_ratio) /100 ; +#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 +71 -1
102 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
Looks good.
--
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>
Andrew Morton
maintainerRe: [PATCH 3/3] Provide control over unmapped pages
In reply to Balbir SinghQuoted 16 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +0
-0
include/linux/swap.h extern int vm_swappiness; · line 256
Quoted 7 lines
include/linux/swap.h +0
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#ifdef CONFIG_NUMA -extern int zone_reclaim_mode;extern int sysctl_min_unmapped_ratio;extern int sysctl_min_slab_ratio;
This change will need to be moved into the first patch.
Quoted 12 lines
include/linux/swap.h +3
-0extern int zone_reclaim (struct zone *,gfp_t ,unsigned int ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)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_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order);
gack, this is on the page allocator fastpath, isn't it? So 99.99999999% of the world's machines end up doing a pointless call to a pointless function which pointlessly tests a pointless global and pointlessly returns? All because of some whacky KSM thing?
The speed and space overhead of this code should be *zero* if !CONFIG_UNMAPPED_PAGECACHE_CONTROL and should be minimal if CONFIG_UNMAPPED_PAGECACHE_CONTROL=y. The way to do the latter is to inline the test of unmapped_page_control into callers and only if it is true (and use unlikely(), please) do we call into the KSM gunk.
Quoted 9 lines
mm/vmscan.c +3
-0@@ -145,6 +145,21 @@ static DECLARE_RWSEM(shrinker_rwsem);#define scanning_global_lru (sc) (1)#endif +static unsigned long balance_unmapped_pages (int priority,struct zone *zone, +struct scan_control *sc); +static int unmapped_page_control__read_mostly ;
mm/vmscan.c static DECLARE_RWSEM(shrinker_rwsem); · line 160
Quoted 10 lines
mm/vmscan.c +10
-0+ +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);
aw c'mon guys, everybody knows that when you add a kernel parameter you document it in Documentation/kernel-parameters.txt.
Quoted 17 lines
mm/vmscan.c +6
-0static struct zone_reclaim_stat *get_reclaim_stat (struct zone *zone,struct scan_control *sc) {@@ -2223,6 +2238,12 @@ loop_again:shrink_active_list (SWAP_CLUSTER_MAX , zone, &sc, priority,0 ); +/* +* We do unmapped page balancing once here and once +* below, so that we don't lose out +*/ +balance_unmapped_pages (priority, zone, &sc); +if (!zone_watermark_ok_safe (zone, order,high_wmark_pages (zone),0 ,0 )) { end_zone = i;
mm/vmscan.c loop_again: · line 2286
Quoted 8 lines
mm/vmscan.c +5
-0@@ -2258,6 +2279,11 @@ loop_again:continue ; sc.nr_scanned =0 ; +/* +* Balance unmapped pages upfront, this should be +* really cheap +*/ +balance_unmapped_pages (priority, zone, &sc);
More unjustifiable overhead on a commonly-executed codepath.
Quoted 13 lines
mm/vmscan.c +2
-1/* * Call soft limit reclaim before calling shrink_zone. @@ -2491,7 +2517,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_balance_unmapped_pages (zone))return ;trace_mm_vmscan_wakeup_kswapd (pgdat->node_id,zone_idx (zone), order);
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2775
Quoted 9 lines
mm/vmscan.c +6
-0@@ -2740,6 +2767,49 @@ zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, }/* +* Routine to balance 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 balance cached pages +*/
The problem I have with this comment is that it uses the term "balance" without ever defining it. Plus "balance" is already a term which is used in memory reclaim.
So if you can think up a unique noun then that's good but whether or not that is done, please describe with great care what that term actually means in this context.
Quoted 4 lines
mm/vmscan.c +4
-0+static unsigned long balance_unmapped_pages (int priority,struct zone *zone, +struct scan_control *sc) +{ + if (unmapped_page_control &&
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2789
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 ;
Doing a clone-and-own of a scan_control is novel. What's going on here?
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2802
Quoted 12 lines
mm/vmscan.c +12
-0+ nr_pages =zone_unmapped_file_pages (zone) - + zone->min_unmapped_pages; +/* Magically try to reclaim eighth the unmapped cache pages */ + nr_pages >>=3 ; + +zone_reclaim_unmapped_pages (zone, &nsc, nr_pages); +return nsc.nr_reclaimed; + } +return 0 ; +} + +#define UNMAPPED_PAGE_RATIO 16
Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
Quoted 11 lines
mm/vmscan.c +8
-0+bool should_balance_unmapped_pages (struct zone *zone) +{ +if (unmapped_page_control && + (zone_unmapped_file_pages (zone) > +UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages)) +return true; +return false; +}Reviewed-by Christoph Lameter <[email protected]>
So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
--
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>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] Provide control over unmapped pages
Quoted 215 lines · Balbir Singh
Quoted 22 lines · Andrew Morton
Quoted 19 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +0
-0@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages;Quoted 7 lines
include/linux/swap.h extern int vm_swappiness; · line 256
Quoted 4 lines
include/linux/swap.h +0
-2-#ifdef CONFIG_NUMA -extern int zone_reclaim_mode;extern int sysctl_min_unmapped_ratio;extern int sysctl_min_slab_ratio;This change will need to be moved into the first patch.
OK, will do, thanks for pointing it out
Quoted 23 lines
Quoted 12 lines
include/linux/swap.h +3
-0extern int zone_reclaim (struct zone *,gfp_t ,unsigned int ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0mm/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_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order);gack, this is on the page allocator fastpath, isn't it? So 99.99999999% of the world's machines end up doing a pointless call to a pointless function which pointlessly tests a pointless global and pointlessly returns? All because of some whacky KSM thing?
Quoted 6 lines
The speed and space overhead of this code should be *zero* if !CONFIG_UNMAPPED_PAGECACHE_CONTROL and should be minimal if
CONFIG_UNMAPPED_PAGECACHE_CONTROL=y. The way to do the latter is to inline the test ofunmapped_page_controlinto callers and only if it is true (and useunlikely(), please) do we call into the KSM gunk.Will do,
should_balance_unmapped_pages()will be a made a no-op in the absence ofCONFIG_UNMAPPED_PAGECACHE_CONTROLQuoted 6 lines
Quoted 6 lines
mm/vmscan.c +0
-0@@ -145,6 +145,21 @@ static DECLARE_RWSEM(shrinker_rwsem);#define scanning_global_lru (sc) (1)#endif Quoted 16 lines
mm/vmscan.c static DECLARE_RWSEM(shrinker_rwsem); · line 160
Quoted 13 lines
mm/vmscan.c +13
-0+static unsigned long balance_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);aw c'mon guys, everybody knows that when you add a kernel parameter you document it in
Documentation/kernel-parameters.txt.Will do - feeling silly on missing it out, that is where reviews help.
Quoted 20 lines
Quoted 20 lines
mm/vmscan.c +6
-0static struct zone_reclaim_stat *get_reclaim_stat (struct zone *zone,struct scan_control *sc) {@@ -2223,6 +2238,12 @@ loop_again:shrink_active_list (SWAP_CLUSTER_MAX , zone, &sc, priority,0 ); +/* +* We do unmapped page balancing once here and once +* below, so that we don't lose out +*/ +balance_unmapped_pages (priority, zone, &sc); +if (!zone_watermark_ok_safe (zone, order,high_wmark_pages (zone),0 ,0 )) { end_zone = i;@@ -2258,6 +2279,11 @@ loop_again:continue ;Quoted 9 lines
mm/vmscan.c loop_again: · line 2286
Quoted 6 lines
mm/vmscan.c +5
-0sc.nr_scanned =0 ; +/* +* Balance unmapped pages upfront, this should be +* really cheap +*/ +balance_unmapped_pages (priority, zone, &sc);More unjustifiable overhead on a commonly-executed codepath.
Will refactor with a CONFIG suggested above.
Quoted 27 lines
Quoted 13 lines
mm/vmscan.c +2
-1/* * Call soft limit reclaim before calling shrink_zone. @@ -2491,7 +2517,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_balance_unmapped_pages (zone))return ;trace_mm_vmscan_wakeup_kswapd (pgdat->node_id,zone_idx (zone), order);mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2775
Quoted 9 lines
mm/vmscan.c +6
-0@@ -2740,6 +2767,49 @@ zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, }/* +* Routine to balance 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 balance cached pages +*/ The problem I have with this comment is that it uses the term "balance" without ever defining it. Plus "balance" is already a term which is used in memory reclaim.
Quoted 3 lines
So if you can think up a unique noun then that's good but whether or not that is done, please describe with great care what that term actually means in this context.
I used balance as a not a 1:1 balance, but to balance the proportion of unmapped page cache based on a sysctl/tunable.
Quoted 17 lines
Quoted 5 lines
mm/vmscan.c +4
-0+static unsigned long balance_unmapped_pages (int priority,struct zone *zone, +struct scan_control *sc) +{ + if (unmapped_page_control &&mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2789
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 ;Doing a clone-and-own of a
scan_controlis novel. What's going on here?This code overwrites the swappiness, may_* and
nr_reclaimedfor correct stats. The idea is to vary the reclaim behaviour/bias it.Quoted 17 lines
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2802
Quoted 13 lines
mm/vmscan.c +12
-0+ nr_pages =zone_unmapped_file_pages (zone) - + zone->min_unmapped_pages; +/* Magically try to reclaim eighth the unmapped cache pages */ + nr_pages >>=3 ; + +zone_reclaim_unmapped_pages (zone, &nsc, nr_pages); +return nsc.nr_reclaimed; + } +return 0 ; +} + +#define UNMAPPED_PAGE_RATIO 16Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
Sorry, I documented that in the changelog of the first patchset. I'll document it here as well. The reason for choosing 16 is based on heuristics and test, the tradeoff being overenthusiastic reclaim versus size of cache/performance.
Quoted 13 lines
Quoted 12 lines
mm/vmscan.c +8
-0+bool should_balance_unmapped_pages (struct zone *zone) +{ +if (unmapped_page_control && + (zone_unmapped_file_pages (zone) > +UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages)) +return true; +return false; +}Reviewed-by Christoph Lameter <[email protected]>
Quoted 8 lines
Quoted 2 lines
So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
I'll do a better one, BTW, a lot of embedded folks are interested in page cache control outside of cgroup behaviour.
Thanks for the detailed review!
My local MTA failed to deliver the message, trying again.
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
Quoted 8 lines · Balbir Singh
Quoted 6 lines · Balbir Singh
Quoted 2 lines · Andrew Morton
So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
I'll do a better one, BTW, a lot of embedded folks are interested in page cache control outside of cgroup behaviour.
Yes. Embedded people(at least, me) want it. That's because they don't have any swap device so they could reclaim only page cache page. And many page cache pages are mapped at address space of application(ex, android uses java model so many pages are mapped by application's address space). It means it's hard to reclaim them without lagging.
So I have a interest in this patch.
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 3/3] Provide control over unmapped pages
In reply to Andrew MortonQuoted 5 lines · Andrew Morton
Quoted 1 line
+#define
UNMAPPED_PAGE_RATIO16Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
The meaning is analoguous to the other zone reclaim ratio. But yes it should be justified and defined.
Quoted 4 lines
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
This is a feature that has been requested over and over for years. Using /proc/vm/drop_caches for fixing situations where one simply has too many page cache pages is not so much fun in the long run.
--
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
Quoted 11 lines · Andrew Morton
Quoted 6 lines
Quoted 2 lines
+#define
UNMAPPED_PAGE_RATIO16Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
The meaning is analoguous to the other zone reclaim ratio. But yes it should be justified and defined.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
This is a feature that has been requested over and over for years. Using
/proc/vm/drop_cachesfor fixing situations where one simply has too many page cache pages is not so much fun in the long run.
I'm not against page cache limitation feature at all. But, this is too ugly and too destructive fast path. I hope this patch reduce negative impact more.
--
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
Quoted 16 lines · On Thu, 2 Dec 2010 10:22:16 +0900 (JST) KOSAKI Motohiro…
Quoted 16 lines · Andrew Morton
Quoted 6 lines
Quoted 2 lines
+#define
UNMAPPED_PAGE_RATIO16Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
The meaning is analoguous to the other zone reclaim ratio. But yes it should be justified and defined.
Quoted 4 lines
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
Quoted 8 lines
Quoted 3 lines
This is a feature that has been requested over and over for years. Using
/proc/vm/drop_cachesfor fixing situations where one simply has too many page cache pages is not so much fun in the long run.I'm not against page cache limitation feature at all. But, this is too ugly and too destructive fast path. I hope this patch reduce negative impact more.
And I think min_mapped_unmapped_pages is ugly. It should be "unmapped_pagecache_limit" or some because it's for limitation feature.
Thanks,
-Kame
--
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
Quoted 23 lines · KAMEZAWA Hiroyuki
Quoted 20 lines · On Thu, 2 Dec 2010 10:22:16 +0900 (JST) KOSAKI Motohiro…
Quoted 19 lines · Andrew Morton
Quoted 6 lines
Quoted 2 lines
+#define
UNMAPPED_PAGE_RATIO16Well. Giving 16 a name didn't really clarify anything. Attentive readers will want to know what this does, why 16 was chosen and what the effects of changing it will be.
The meaning is analoguous to the other zone reclaim ratio. But yes it should be justified and defined.
Quoted 4 lines
Quoted 1 line
Reviewed-by Christoph Lameter <[email protected]>So you're OK with shoving all this flotsam into 100,000,000 cellphones? This was a pretty outrageous patchset!
This is a feature that has been requested over and over for years. Using
/proc/vm/drop_cachesfor fixing situations where one simply has too many page cache pages is not so much fun in the long run.
Quoted 8 lines
Quoted 4 lines
I'm not against page cache limitation feature at all. But, this is too ugly and too destructive fast path. I hope this patch reduce negative impact more.
And I think
min_mapped_unmapped_pagesis ugly. It should be "unmapped_pagecache_limit" or some because it's for limitation feature.
The feature will now be enabled with a CONFIG and boot parameter, I find changing the naming convention now - it is already in use and well known is not a good idea. THe name of the boot parameter can be changed of-course.
Signature · 2 lines
Three Cheers, Balbir
Re: [PATCH 3/3] Provide control over unmapped pages
In reply to Balbir SinghQuoted 35 lines
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0
mm/page_alloc.c zonelist_scan: · line 1667
Quoted 6 lines
mm/page_alloc.c +3
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret; +if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +
You don't have to add extra branch into fast path.
Quoted 43 lines
mm/page_alloc.c +2
-2mark = zone->watermark[alloc_flags &ALLOC_WMARK_MASK ];if (zone_watermark_ok (zone, order, mark, classzone_idx, alloc_flags))@@ -4136,10 +4139,10 @@ 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; zone->min_unmapped_pages = (realsize*sysctl_min_unmapped_ratio) /100 ; +#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 +15
-0@@ -145,6 +145,21 @@ static DECLARE_RWSEM(shrinker_rwsem);#define scanning_global_lru (sc) (1)#endif +static unsigned long balance_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); + +static struct zone_reclaim_stat *get_reclaim_stat (struct zone *zone,struct scan_control *sc) {
mm/vmscan.c loop_again: · line 2245
Quoted 8 lines
mm/vmscan.c +5
-0@@ -2223,6 +2238,12 @@ loop_again:shrink_active_list (SWAP_CLUSTER_MAX , zone, &sc, priority,0 ); +/* +* We do unmapped page balancing once here and once +* below, so that we don't lose out +*/ +balance_unmapped_pages (priority, zone, &sc);
You can't invoke any reclaim from here. It is in zone balancing detection phase. It mean your code reclaim pages from zones which has lots free pages too.
mm/vmscan.c loop_again: · line 2286
Quoted 13 lines
mm/vmscan.c +6
-0+if (!zone_watermark_ok_safe (zone, order,high_wmark_pages (zone),0 ,0 )) { end_zone = i;@@ -2258,6 +2279,11 @@ loop_again:continue ; sc.nr_scanned =0 ; +/* +* Balance unmapped pages upfront, this should be +* really cheap +*/ +balance_unmapped_pages (priority, zone, &sc);
This code break page-cache/slab balancing logic. And this is conflict against Nick's per-zone slab effort.
Plus, high-order + priority=5 reclaim Simon's case. (see "Free memory never fully used, swapping" threads)
Quoted 27 lines
mm/vmscan.c +12
-1/* * Call soft limit reclaim before calling shrink_zone. @@ -2491,7 +2517,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_balance_unmapped_pages (zone))return ;trace_mm_vmscan_wakeup_kswapd (pgdat->node_id,zone_idx (zone), order);@@ -2740,6 +2767,49 @@ zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, }/* +* Routine to balance 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 balance cached pages +*/ +static unsigned long balance_unmapped_pages (int priority,struct zone *zone, +struct scan_control *sc) +{ + if (unmapped_page_control &&
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2789
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 ;
Don't you need to fill nsc.nr_to_reclaim field?
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2794
Quoted 5 lines
mm/vmscan.c +5
-0+ + nr_pages =zone_unmapped_file_pages (zone) - + zone->min_unmapped_pages; +/* Magically try to reclaim eighth the unmapped cache pages */ + nr_pages >>=3 ;
Please don't make magic.
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2802
Quoted 8 lines
mm/vmscan.c +8
-0+ +zone_reclaim_unmapped_pages (zone, &nsc, nr_pages); +return nsc.nr_reclaimed; + } +return 0 ; +} + +#define UNMAPPED_PAGE_RATIO 16
Please don't make magic ratio.
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2815
Quoted 13 lines
mm/vmscan.c +10
-0+bool should_balance_unmapped_pages (struct zone *zone) +{ +if (unmapped_page_control && + (zone_unmapped_file_pages (zone) > +UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages)) +return true; +return false; +} + +/* * 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)
Hmm....
As far as I reviewed, I can't find any reason why this patch works as expected. So, I think cleancache looks promising more than this idea. Have you seen Dan's patch? I would suggested discuss him.
Thanks.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] Provide control over unmapped pages
Quoted 221 lines · Balbir Singh
Quoted 91 lines · KOSAKI Motohiro
Quoted 35 lines
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0mm/page_alloc.c zonelist_scan: · line 1667
Quoted 6 lines
mm/page_alloc.c +3
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret; +if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +You don't have to add extra branch into fast path.
Quoted 46 lines
mm/page_alloc.c +2
-2mark = zone->watermark[alloc_flags &ALLOC_WMARK_MASK ];if (zone_watermark_ok (zone, order, mark, classzone_idx, alloc_flags))@@ -4136,10 +4139,10 @@ 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; zone->min_unmapped_pages = (realsize*sysctl_min_unmapped_ratio) /100 ; +#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 +15
-0@@ -145,6 +145,21 @@ static DECLARE_RWSEM(shrinker_rwsem);#define scanning_global_lru (sc) (1)#endif +static unsigned long balance_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); + +static struct zone_reclaim_stat *get_reclaim_stat (struct zone *zone,struct scan_control *sc) {@@ -2223,6 +2238,12 @@ loop_again:shrink_active_list (SWAP_CLUSTER_MAX , zone, &sc, priority,0 );Quoted 8 lines
mm/vmscan.c loop_again: · line 2245
Quoted 5 lines
mm/vmscan.c +5
-0+/* +* We do unmapped page balancing once here and once +* below, so that we don't lose out +*/ +balance_unmapped_pages (priority, zone, &sc);You can't invoke any reclaim from here. It is in zone balancing detection phase. It mean your code reclaim pages from zones which has lots free pages too.
The goal is to check not only for
zone_watermark_ok, but also to see if unmapped pages are way higher than expected values.Quoted 8 lines
Quoted 8 lines
mm/vmscan.c +1
-0+if (!zone_watermark_ok_safe (zone, order,high_wmark_pages (zone),0 ,0 )) { end_zone = i;@@ -2258,6 +2279,11 @@ loop_again:continue ;Quoted 11 lines
mm/vmscan.c loop_again: · line 2286
Quoted 6 lines
mm/vmscan.c +5
-0sc.nr_scanned =0 ; +/* +* Balance unmapped pages upfront, this should be +* really cheap +*/ +balance_unmapped_pages (priority, zone, &sc);This code break page-cache/slab balancing logic. And this is conflict against Nick's per-zone slab effort.
OK, cc'ing Nick for comments.
Quoted 3 lines
Plus, high-order + priority=5 reclaim Simon's case. (see "Free memory never fully used, swapping" threads)
OK, this path should not add to swapping activity, if that is your concern.
Quoted 31 lines
Quoted 31 lines
mm/vmscan.c +16
-1/* * Call soft limit reclaim before calling shrink_zone. @@ -2491,7 +2517,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_balance_unmapped_pages (zone))return ;trace_mm_vmscan_wakeup_kswapd (pgdat->node_id,zone_idx (zone), order);@@ -2740,6 +2767,49 @@ zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, }/* +* Routine to balance 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 balance cached pages +*/ +static unsigned long balance_unmapped_pages (int priority,struct zone *zone, +struct scan_control *sc) +{ +if (unmapped_page_control && + (zone_unmapped_file_pages (zone) > zone->min_unmapped_pages)) { +struct scan_control nsc; +unsigned long nr_pages; +Quoted 9 lines
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2789
Quoted 6 lines
mm/vmscan.c +6
-0+ nsc = *sc; + + nsc.swappiness =0 ; + nsc.may_writepage =0 ; + nsc.may_unmap =0 ; + nsc.nr_reclaimed =0 ;Don't you need to fill nsc.nr_to_reclaim field?
Yes, since the relcaim code looks at
nr_reclaimed, it needs to be 0 at every iteration - did I miss something?Quoted 8 lines
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2794
Quoted 5 lines
mm/vmscan.c +5
-0+ + nr_pages =zone_unmapped_file_pages (zone) - + zone->min_unmapped_pages; +/* Magically try to reclaim eighth the unmapped cache pages */ + nr_pages >>=3 ;Please don't make magic.
OK, it is a hueristic, how do I use it?
Quoted 10 lines
mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2802
Quoted 8 lines
mm/vmscan.c +8
-0+ +zone_reclaim_unmapped_pages (zone, &nsc, nr_pages); +return nsc.nr_reclaimed; + } +return 0 ; +} + +#define UNMAPPED_PAGE_RATIO 16Please don't make magic ratio.
OK, it is a hueristic, how do I use heuristics - sysctl?
Quoted 18 lines
Quoted 4 lines
mm/vmscan.c +3
-0+bool should_balance_unmapped_pages (struct zone *zone) +{ + if (unmapped_page_control &&mm/vmscan.c zone_reclaim_unmapped_pages(struct zone *zone, struct scan_control *sc, · line 2815
Quoted 10 lines
mm/vmscan.c +7
-0+ (zone_unmapped_file_pages(zone) > + UNMAPPED_PAGE_RATIO * zone->min_unmapped_pages)) +return true; +return false; +} + +/* * 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)Hmm....
Quoted 8 lines
Quoted 3 lines
As far as I reviewed, I can't find any reason why this patch works as expected. So, I think cleancache looks promising more than this idea. Have you seen Dan's patch? I would suggested discuss him.
Please try the patch, I've been using it and it works exactly as expected for me. kswapd does the balancing and works well. I've posted some data as well.
My local MTA failed to deliver the message, trying again.
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
In reply to Balbir SinghQuoted 35 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0
mm/page_alloc.c zonelist_scan: · line 1667
Quoted 6 lines
mm/page_alloc.c +3
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret; +if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +
Hm, I'm not sure the final vision of this feature. Does this reclaiming feature can't be called directly via balloon driver just before alloc_page() ?
Do you need to keep page caches small even when there are free memory on host ?
Thanks,
-Kame
--
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>
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] Provide control over unmapped pages
Quoted 54 lines · Balbir Singh
Quoted 41 lines · KAMEZAWA Hiroyuki
Quoted 38 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret;Quoted 7 lines
mm/page_alloc.c zonelist_scan: · line 1667
Quoted 3 lines
mm/page_alloc.c +3
-0+if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +Hm, I'm not sure the final vision of this feature. Does this reclaiming feature can't be called directly via balloon driver just before
alloc_page()?That is a separate patch, this is a boot paramter based control approach.
Quoted 7 lines
Quoted 2 lines
Do you need to keep page caches small even when there are free memory on host ?
The goal is to avoid duplication, as you know page cache fills itself to consume as much memory as possible. The host generally does not have a lot of free memory in a consolidated environment.
My local MTA failed to deliver the message, trying again.
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
Quoted 56 lines · On Wed, 1 Dec 2010 10:52:59 +0530 Balbir Singh <[email protected]>…
Quoted 54 lines · Balbir Singh
Quoted 41 lines · KAMEZAWA Hiroyuki
Quoted 38 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret;Quoted 7 lines
mm/page_alloc.c zonelist_scan: · line 1667
Quoted 3 lines
mm/page_alloc.c +3
-0+if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +Hm, I'm not sure the final vision of this feature. Does this reclaiming feature can't be called directly via balloon driver just before
alloc_page()?That is a separate patch, this is a boot paramter based control approach.
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Do you need to keep page caches small even when there are free memory on host ?
The goal is to avoid duplication, as you know page cache fills itself to consume as much memory as possible. The host generally does not have a lot of free memory in a consolidated environment.
That's a point. Then, why the guest has to do _extra_ work for host even when the host says nothing ? I think trigger this by guests themselves is not very good.
Thanks,
-Kame
--
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
Quoted 62 lines · KAMEZAWA Hiroyuki
Quoted 59 lines · On Wed, 1 Dec 2010 10:52:59 +0530 Balbir Singh <[email protected]>…
Quoted 57 lines · Balbir Singh
Quoted 41 lines · KAMEZAWA Hiroyuki
Quoted 38 lines · On Tue, 30 Nov 2010 15:46:31 +0530 Balbir Singh <[email protected]>…
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]>--- include/linux/swap.h | 5 ++- mm/page_alloc.c | 7 +++-- mm/vmscan.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 5 deletions(-)include/linux/swap.h +3
-2@@ -252,11 +252,12 @@ extern int vm_swappiness;extern int remove_mapping (struct address_space *mapping,struct page *page);extern long vm_total_pages; -#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 ); +extern bool should_balance_unmapped_pages (struct zone *zone); +#ifdef CONFIG_NUMA +extern int zone_reclaim_mode;#else #define zone_reclaim_mode 0static inline int zone_reclaim (struct zone *z,gfp_t mask,unsigned int order)mm/page_alloc.c +0
-0@@ -1662,6 +1662,9 @@ zonelist_scan:unsigned long mark;int ret;Quoted 7 lines
mm/page_alloc.c zonelist_scan: · line 1667
Quoted 3 lines
mm/page_alloc.c +3
-0+if (should_balance_unmapped_pages (zone)) +wakeup_kswapd (zone, order); +Hm, I'm not sure the final vision of this feature. Does this reclaiming feature can't be called directly via balloon driver just before
alloc_page()?That is a separate patch, this is a boot paramter based control approach.
Quoted 2 lines
Do you need to keep page caches small even when there are free memory on host ?
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
The goal is to avoid duplication, as you know page cache fills itself to consume as much memory as possible. The host generally does not have a lot of free memory in a consolidated environment.
That's a point. Then, why the guest has to do _extra_ work for host even when the host says nothing ? I think trigger this by guests themselves is not very good.
I've mentioned it before, the guest keeping free memory without a large performance hit, helps, the balloon driver is able to quickly retrieve this memory if required or the guest can use this memory for some other application/task. The cached data is mostly already present in the host page cache.
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
Quoted 10 lines · On Wed, 1 Dec 2010 12:10:43 +0530 Balbir Singh <[email protected]>…
Quoted 2 lines
That's a point. Then, why the guest has to do _extra_ work for host even when the host says nothing ? I think trigger this by guests themselves is not very good.
I've mentioned it before, the guest keeping free memory without a large performance hit, helps, the balloon driver is able to quickly retrieve this memory if required or the guest can use this memory for some other application/task.
The cached data is mostly already present in the host page cache.
Why ? Are there parameters/stats which shows this is _true_ ? How we can guarantee/show it to users ?
Please add an interface to show "shared rate between guest/host" If not, any admin will not turn this on because "file cache status on host" is a black box for guest admins. I think this patch skips something important steps.
2nd point is maybe for reducing total host memory usage and for increasing the number of guests on a host. For that, this feature is useful only when all guests on a host are friendly and devoted to the health of host memory management because all setting must be done in the guest. This can be passed as even by qemu's command line argument. And _no_ benefit for the guests who reduce it's resource to help host management because there is no guarantee dropped caches are on host memory.
So, for both claim, I want to see an interface to show the number of shared pages between hosts and guests rather than imagine it.
BTW, I don't like this kind of "please give us your victim, please please please" logic. The host should be able to "steal" what it wants in force. Then, I think there should be no On/Off visible interfaces. The vm firmware should tell to turn on this if administrator of the host wants.
BTW2, please test with some other benchmarks (which read file caches.) I don't think kernel make is good test for this.
Thanks,
-Kame
--
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>