Remove zonelist cache and high-order watermark checking
Subsystems (8)
cover Remove zonelist cache and high-order watermark checking
From: Mel Gorman <[email protected]>
This series started with the idea to move LRU lists to pgdat but this part was more important to start with. It was written against 4.2-rc1 but applies to 4.2-rc3.
The zonelist cache has been around for a long time but it is of dubious merit with a lot of complexity. There are a few reasons why it needs help that are explained in the first patch but the most important is that a failed THP allocation can cause a zone to be treated as "full". This potentially causes unnecessary stalls, reclaim activity or remote fallbacks. Maybe the issues could be fixed but it's not worth it. The series places a small number of other micro-optimisations on top before examining watermarks.
High-order watermarks are something that can cause high-order allocations to fail even though pages are free. This was originally to protect high-order atomic allocations but there is a much better way that can be handled using migrate types. This series uses page grouping by mobility to preserve some pageblocks for high-order allocations with the size of the reservation depending on demand. kswapd awareness is maintained by examining the free lists. By patch 10 in this series, there are no high-order watermark checks while preserving the properties that motivated the introduction of the watermark checks.
An interesting side-effect of this series is that high-order atomic allocations should be a lot more reliable as long as they start before heavy fragmentation or memory pressure is encountered. This is due to the reserves being dynamically sized instead of just depending on MIGRATE_RESERVE. The traditional expected case here is atomic allocations for network buffers using jumbo frames whose devices cannot handle scatter/gather. In aggressive tests the failure rate of atomic order-3 allocations is reduced by 98%. I would be very interested in hearing from someone who uses jumbo frames with hardware that requires high-order atomic allocations to succeed that can test this series.
A potential side-effect of this series may be of interest to developers of embedded platforms. There have been a number of patches recently that were aimed at making high-order allocations fast or reliable in various different ways. Usually they came under the headings of compaction but they are likely to have hit limited success without modifying how grouping works. One patch attempting to introduce an interface that allowed userspace to dump all of memory in an attempt to make high-order allocations faster which is definitely a bad idea. Using this series they get two other options as out-of-tree patches
1. Alter patch 9 of this series to only call unreserve_highatomic_pageblock if the system is about to go OOM. This should drop the allocation failure for high-order atomic failures to 0 or near 0 in a lot of cases. Your milage will depend on the workload. Such a change would not suit mainline because it'll push a lot of workloads into reclaim in cases where the HighAtomic reserves are too large.
2. Alter patch 9 of this series to reserve space for all high-order kernel allocations, not just atomic ones. This will make the high-order allocations more reliable and in many cases faster. However, the caveat may be excessive reclaim if those reserves become a large percentage of memory. I would recommend that you still try and avoid ever depending on high-order allocations for functional correctness. Alternative keep them as short-lived as possible so they fit in a small reserve.
With or without the out-of-tree modifications, this series should work well with compaction series that aim to make more pages migratable so high-order allocations are more successful.
include/linux/cpuset.h | 6 + include/linux/gfp.h | 47 +++- include/linux/mmzone.h | 94 +------- init/main.c | 2 +- mm/huge_memory.c | 2 +- mm/internal.h | 1 + mm/page_alloc.c | 565 ++++++++++++++----------------------------------- mm/slab.c | 4 +- mm/slob.c | 4 +- mm/slub.c | 6 +- mm/vmscan.c | 4 +- mm/vmstat.c | 2 +- 12 files changed, 228 insertions(+), 509 deletions(-)
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 1/10 mm, page_alloc: Delete the zonelist_cache
From: Mel Gorman <[email protected]>
The zonelist cache (zlc) was introduced to skip over zones that were recently known to be full. At the time the paths it bypassed were the cpuset checks, the watermark calculations and zone_reclaim. The situation today is different and the complexity of zlc is harder to justify.
1) The cpuset checks are no-ops unless a cpuset is active and in general are a lot cheaper.
2) zone_reclaim is now disabled by default and I suspect that was a large source of the cost that zlc wanted to avoid. When it is enabled, it's known to be a major source of stalling when nodes fill up and it's unwise to hit every other user with the overhead.
3) Watermark checks are expensive to calculate for high-order allocation requests. Later patches in this series will reduce the cost of the watermark checking.
4) The most important issue is that in the current implementation it is possible for a failed THP allocation to mark a zone full for order-0 allocations and cause a fallback to remote nodes.
The last issue could be addressed with additional complexity but it's not clear that we need zlc at all so this patch deletes it. If stalls due to repeated zone_reclaim are ever reported as an issue then we should introduce deferring logic based on a timeout inside zone_reclaim itself and leave the page allocator fast paths alone.
Impact on page-allocator microbenchmarks is negligible as they don't hit the paths where the zlc comes into play. The impact was noticable in a workload called "stutter". One part uses a lot of anonymous memory, a second measures mmap latency and a third copies a large file. In an ideal world the latency application would not notice the mmap latency. On a 4-node machine the results of this patch are
4-node machine stutter
4.2.0-rc1 4.2.0-rc1
vanilla nozlc-v1r20
Min mmap 53.9902 ( 0.00%) 49.3629 ( 8.57%)
1st-qrtle mmap 54.6776 ( 0.00%) 54.1201 ( 1.02%)
2nd-qrtle mmap 54.9242 ( 0.00%) 54.5961 ( 0.60%)
3rd-qrtle mmap 55.1817 ( 0.00%) 54.9338 ( 0.45%)
Max-90% mmap 55.3952 ( 0.00%) 55.3929 ( 0.00%)
Max-93% mmap 55.4766 ( 0.00%) 57.5712 ( -3.78%)
Max-95% mmap 55.5522 ( 0.00%) 57.8376 ( -4.11%)
Max-99% mmap 55.7938 ( 0.00%) 63.6180 (-14.02%)
Max mmap 6344.0292 ( 0.00%) 67.2477 ( 98.94%)
Mean mmap 57.3732 ( 0.00%) 54.5680 ( 4.89%)Note the maximum stall latency which was 6 seconds and becomes 67ms with this patch applied. However, also note that it is not guaranteed this benchmark always hits pathelogical cases and the milage varies. There is a secondary impact with more direct reclaim because zones are now being considered instead of being skipped by zlc.
4.1.0 4.1.0
vanilla nozlc-v1r4Swap Ins 838 502
Swap Outs 1149395 2622895
DMA32 allocs 17839113 15863747
Normal allocs 129045707 137847920
Direct pages scanned 4070089 29046893 Kswapd pages scanned 17147837 17140694 Kswapd pages reclaimed 17146691 17139601
Direct pages reclaimed 1888879 4886630
Kswapd efficiency 99% 99%
Kswapd velocity 17523.721 17518.928
Direct efficiency 46% 16%
Direct velocity 4159.306 29687.854
Percentage direct scans 19% 62%
Page writes by reclaim 1149395.000 2622895.000
Page writes file 0 0
Page writes anon 1149395 2622895
The direct page scan and reclaim rates are noticable. It is possible this will not be a universal win on all workloads but cycling through zonelists waiting for zlc->last_full_zap to expire is not the right decision.
--- include/linux/mmzone.h | 73 ----------------- mm/page_alloc.c | 217 +------------------------------------------------ 2 files changed, 2 insertions(+), 288 deletions(-)
include/linux/mmzone.h +0 -73
@@ -585,75 +585,6 @@ static inline bool zone_is_empty(struct zone *zone)* [1] : No fallback (__GFP_THISNODE) */ #define MAX_ZONELISTS 2 - - -/* -* We cache key information from each zonelist for smaller cache -* footprint when scanning for free pages in get_page_from_freelist(). -* -* 1) The BITMAP fullzones tracks which zones in a zonelist have come -* up short of free memory since the last time (last_fullzone_zap) -* we zero'd fullzones. -* 2) The array z_to_n[] maps each zone in the zonelist to its node -* id, so that we can efficiently evaluate whether that node is -* set in the current tasks mems_allowed. -* -* Both fullzones and z_to_n[] are one-to-one with the zonelist, -* indexed by a zones offset in the zonelist zones[] array. -* -* The get_page_from_freelist() routine does two scans. During the -* first scan, we skip zones whose corresponding bit in 'fullzones' -* is set or whose corresponding node in current->mems_allowed (which -* comes from cpusets) is not set. During the second scan, we bypass -* this zonelist_cache, to ensure we look methodically at each zone. -* -* Once per second, we zero out (zap) fullzones, forcing us to -* reconsider nodes that might have regained more free memory. -* The field last_full_zap is the time we last zapped fullzones. -* -* This mechanism reduces the amount of time we waste repeatedly -* reexaming zones for free memory when they just came up low on -* memory momentarilly ago. -* -* The zonelist_cache struct members logically belong in struct -* zonelist. However, the mempolicy zonelists constructed for -* MPOL_BIND are intentionally variable length (and usually much -* shorter). A general purpose mechanism for handling structs with -* multiple variable length members is more mechanism than we want -* here. We resort to some special case hackery instead. -* -* The MPOL_BIND zonelists don't need this zonelist_cache (in good -* part because they are shorter), so we put the fixed length stuff -* at the front of the zonelist struct, ending in a variable length -* zones[], as is needed by MPOL_BIND. -* -* Then we put the optional zonelist cache on the end of the zonelist -* struct. This optional stuff is found by a 'zlcache_ptr' pointer in -* the fixed length portion at the front of the struct. This pointer -* both enables us to find the zonelist cache, and in the case of -* MPOL_BIND zonelists, (which will just set the zlcache_ptr to NULL) -* to know that the zonelist cache is not there. -* -* The end result is that struct zonelists come in two flavors: -* 1) The full, fixed length version, shown below, and -* 2) The custom zonelists for MPOL_BIND. -* The custom MPOL_BIND zonelists have a NULL zlcache_ptr and no zlcache. -* -* Even though there may be multiple CPU cores on a node modifying -* fullzones or last_full_zap in the same zonelist_cache at the same -* time, we don't lock it. This is just hint data - if it is wrong now -* and then, the allocator will still function, perhaps a bit slower. -*/ - - -struct zonelist_cache { -unsigned short z_to_n[MAX_ZONES_PER_ZONELIST ];/* zone->nid */ - DECLARE_BITMAP(fullzones, MAX_ZONES_PER_ZONELIST); /* zone full? */ -unsigned long last_full_zap;/* when last zap'd (jiffies) */ -}; -#else -#define MAX_ZONELISTS 1 -struct zonelist_cache ;#endif /*
@@ -683,11 +614,7 @@ struct zoneref {* zonelist_node_idx() - Return the index of the node for an entry */ struct zonelist { -struct zonelist_cache *zlcache_ptr;// NULL or &zlcache struct zoneref _zonerefs[MAX_ZONES_PER_ZONELIST +1 ]; -#ifdef CONFIG_NUMA -struct zonelist_cache zlcache;// optional ... -#endif };#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
mm/page_alloc.c +2 -215
316 lines not on this page · raw message
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 01/10] mm, page_alloc: Delete the zonelist_cache
Quoted 75 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The zonelist cache (zlc) was introduced to skip over zones that were recently known to be full. At the time the paths it bypassed were the cpuset checks, the watermark calculations and
zone_reclaim. The situation today is different and the complexity of zlc is harder to justify.1) The cpuset checks are no-ops unless a cpuset is active and in general are a lot cheaper.
2)
zone_reclaimis now disabled by default and I suspect that was a large source of the cost that zlc wanted to avoid. When it is enabled, it's known to be a major source of stalling when nodes fill up and it's unwise to hit every other user with the overhead.3) Watermark checks are expensive to calculate for high-order allocation requests. Later patches in this series will reduce the cost of the watermark checking.
4) The most important issue is that in the current implementation it is possible for a failed THP allocation to mark a zone full for order-0 allocations and cause a fallback to remote nodes.
The last issue could be addressed with additional complexity but it's not clear that we need zlc at all so this patch deletes it. If stalls due to repeated
zone_reclaimare ever reported as an issue then we should introduce deferring logic based on a timeout insidezone_reclaimitself and leave the page allocator fast paths alone.Impact on page-allocator microbenchmarks is negligible as they don't hit the paths where the zlc comes into play. The impact was noticable in a workload called "stutter". One part uses a lot of anonymous memory, a second measures mmap latency and a third copies a large file. In an ideal world the latency application would not notice the mmap latency. On a 4-node machine the results of this patch are
4-node machine stutter
4.2.0-rc1 4.2.0-rc1 vanilla nozlc-v1r20 Min mmap 53.9902 ( 0.00%) 49.3629 ( 8.57%) 1st-qrtle mmap 54.6776 ( 0.00%) 54.1201 ( 1.02%) 2nd-qrtle mmap 54.9242 ( 0.00%) 54.5961 ( 0.60%) 3rd-qrtle mmap 55.1817 ( 0.00%) 54.9338 ( 0.45%) Max-90% mmap 55.3952 ( 0.00%) 55.3929 ( 0.00%) Max-93% mmap 55.4766 ( 0.00%) 57.5712 ( -3.78%) Max-95% mmap 55.5522 ( 0.00%) 57.8376 ( -4.11%) Max-99% mmap 55.7938 ( 0.00%) 63.6180 (-14.02%) Max mmap 6344.0292 ( 0.00%) 67.2477 ( 98.94%) Mean mmap 57.3732 ( 0.00%) 54.5680 ( 4.89%)Note the maximum stall latency which was 6 seconds and becomes 67ms with this patch applied. However, also note that it is not guaranteed this benchmark always hits pathelogical cases and the milage varies. There is a secondary impact with more direct reclaim because zones are now being considered instead of being skipped by zlc.
4.1.0 4.1.0 vanilla nozlc-v1r4Swap Ins 838 502
Swap Outs 1149395 2622895
DMA32 allocs 17839113 15863747
Normal allocs 129045707 137847920Direct pages scanned 4070089 29046893 Kswapd pages scanned 17147837 17140694 Kswapd pages reclaimed 17146691 17139601Direct pages reclaimed 1888879 4886630
Kswapd efficiency 99% 99%
Kswapd velocity 17523.721 17518.928
Direct efficiency 46% 16%
Direct velocity 4159.306 29687.854
Percentage direct scans 19% 62%
Page writes by reclaim 1149395.000 2622895.000
Page writes file 0 0
Page writes anon 1149395 2622895
Quoted 6 lines
The direct page scan and reclaim rates are noticable. It is possible this will not be a universal win on all workloads but cycling through zonelists waiting for
zlc->last_full_zapto expire is not the right decision.Signed-off-by Mel Gorman <[email protected]>
I don't use a config that uses cpusets to restrict memory allocation anymore, but it'd be interesting to see the impact that the spinlock and cpuset hierarchy scan has for non-hardwalled allocations.
This removed the #define MAX_ZONELISTS 1 for UMA configs, which will cause build errors, but once that's fixed:
I'm glad to see this go.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 01/10] mm, page_alloc: Delete the zonelist_cache
Quoted 82 lines · David Rientjes
Quoted 80 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The zonelist cache (zlc) was introduced to skip over zones that were recently known to be full. At the time the paths it bypassed were the cpuset checks, the watermark calculations and
zone_reclaim. The situation today is different and the complexity of zlc is harder to justify.1) The cpuset checks are no-ops unless a cpuset is active and in general are a lot cheaper.
2)
zone_reclaimis now disabled by default and I suspect that was a large source of the cost that zlc wanted to avoid. When it is enabled, it's known to be a major source of stalling when nodes fill up and it's unwise to hit every other user with the overhead.3) Watermark checks are expensive to calculate for high-order allocation requests. Later patches in this series will reduce the cost of the watermark checking.
4) The most important issue is that in the current implementation it is possible for a failed THP allocation to mark a zone full for order-0 allocations and cause a fallback to remote nodes.
The last issue could be addressed with additional complexity but it's not clear that we need zlc at all so this patch deletes it. If stalls due to repeated
zone_reclaimare ever reported as an issue then we should introduce deferring logic based on a timeout insidezone_reclaimitself and leave the page allocator fast paths alone.Impact on page-allocator microbenchmarks is negligible as they don't hit the paths where the zlc comes into play. The impact was noticable in a workload called "stutter". One part uses a lot of anonymous memory, a second measures mmap latency and a third copies a large file. In an ideal world the latency application would not notice the mmap latency. On a 4-node machine the results of this patch are
4-node machine stutter
4.2.0-rc1 4.2.0-rc1 vanilla nozlc-v1r20 Min mmap 53.9902 ( 0.00%) 49.3629 ( 8.57%) 1st-qrtle mmap 54.6776 ( 0.00%) 54.1201 ( 1.02%) 2nd-qrtle mmap 54.9242 ( 0.00%) 54.5961 ( 0.60%) 3rd-qrtle mmap 55.1817 ( 0.00%) 54.9338 ( 0.45%) Max-90% mmap 55.3952 ( 0.00%) 55.3929 ( 0.00%) Max-93% mmap 55.4766 ( 0.00%) 57.5712 ( -3.78%) Max-95% mmap 55.5522 ( 0.00%) 57.8376 ( -4.11%) Max-99% mmap 55.7938 ( 0.00%) 63.6180 (-14.02%) Max mmap 6344.0292 ( 0.00%) 67.2477 ( 98.94%) Mean mmap 57.3732 ( 0.00%) 54.5680 ( 4.89%)Note the maximum stall latency which was 6 seconds and becomes 67ms with this patch applied. However, also note that it is not guaranteed this benchmark always hits pathelogical cases and the milage varies. There is a secondary impact with more direct reclaim because zones are now being considered instead of being skipped by zlc.
4.1.0 4.1.0 vanilla nozlc-v1r4Swap Ins 838 502
Swap Outs 1149395 2622895
DMA32 allocs 17839113 15863747
Normal allocs 129045707 137847920Direct pages scanned 4070089 29046893 Kswapd pages scanned 17147837 17140694 Kswapd pages reclaimed 17146691 17139601Direct pages reclaimed 1888879 4886630
Kswapd efficiency 99% 99%
Kswapd velocity 17523.721 17518.928
Direct efficiency 46% 16%
Direct velocity 4159.306 29687.854
Percentage direct scans 19% 62%
Page writes by reclaim 1149395.000 2622895.000
Page writes file 0 0
Page writes anon 1149395 2622895The direct page scan and reclaim rates are noticable. It is possible this will not be a universal win on all workloads but cycling through zonelists waiting for
zlc->last_full_zapto expire is not the right decision.
Quoted 9 lines
Quoted 1 line
Signed-off-by Mel Gorman <[email protected]>I don't use a config that uses cpusets to restrict memory allocation anymore, but it'd be interesting to see the impact that the spinlock and cpuset hierarchy scan has for non-hardwalled allocations.
This removed the #define
MAX_ZONELISTS1 for UMA configs, which will cause build errors, but once that's fixed:
The build error is now fixed. Thanks.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/10 mm, page_alloc: Remove unnecessary parameter from zone_watermark_ok_safe
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
No user of zone_watermark_ok_safe() specifies alloc_flags. This patch removes the unnecessary parameter.
--- include/linux/mmzone.h | 2 +- mm/page_alloc.c | 5 +++-- mm/vmscan.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-)
include/linux/mmzone.h +1 -1
@@ -729,7 +729,7 @@ void wakeup_kswapd(struct zone *zone, int order, enum zone_type classzone_idx);bool zone_watermark_ok (struct zone *z,unsigned int order,unsigned long mark,int classzone_idx,int alloc_flags);bool zone_watermark_ok_safe (struct zone *z,unsigned int order, -unsigned long mark,int classzone_idx,int alloc_flags); +unsigned long mark,int classzone_idx);enum memmap_context {MEMMAP_EARLY ,MEMMAP_HOTPLUG ,
mm/page_alloc.c +3 -2
@@ -2207,6 +2207,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, min -= min /2 ;if (alloc_flags &ALLOC_HARDER ) min -= min /4 ; +#ifdef CONFIG_CMA /* If allocation can't use CMA areas don't use free CMA pages */ if (!(alloc_flags &ALLOC_CMA ))
@@ -2236,14 +2237,14 @@ bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, }bool zone_watermark_ok_safe (struct zone *z,unsigned int order, -unsigned long mark,int classzone_idx,int alloc_flags) +unsigned long mark,int classzone_idx) {long free_pages =zone_page_state (z,NR_FREE_PAGES );if (z->percpu_drift_mark && free_pages < z->percpu_drift_mark) free_pages =zone_page_state_snapshot (z,NR_FREE_PAGES ); -return __zone_watermark_ok (z, order, mark, classzone_idx, alloc_flags, +return __zone_watermark_ok (z, order, mark, classzone_idx,0 , free_pages); }
mm/vmscan.c +2 -2
@@ -2454,7 +2454,7 @@ static inline bool compaction_ready(struct zone *zone, int order) balance_gap =min (low_wmark_pages (zone),DIV_ROUND_UP ( zone->managed_pages,KSWAPD_ZONE_BALANCE_GAP_RATIO )); watermark =high_wmark_pages (zone) + balance_gap + (2UL << order); - watermark_ok =zone_watermark_ok_safe (zone,0 , watermark,0 ,0 ); + watermark_ok =zone_watermark_ok_safe (zone,0 , watermark,0 );/* * If compaction is deferred, reclaim up to a point where
@@ -2937,7 +2937,7 @@ static bool zone_balanced(struct zone *zone, int order, unsigned long balance_gap, int classzone_idx) { if (!zone_watermark_ok_safe(zone, order, high_wmark_pages(zone) + - balance_gap, classzone_idx, 0)) + balance_gap, classzone_idx)) return false; if (IS_ENABLED(CONFIG_COMPACTION) && order && compaction_suitable(zone,
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/10] mm, page_alloc: Remove unnecessary parameter from zone_watermark_ok_safe
Quoted 6 lines · Mel Gorman
From: Mel Gorman <[email protected]>
No user of
zone_watermark_ok_safe()specifiesalloc_flags. This patch removes the unnecessary parameter.Signed-off-by Mel Gorman <[email protected]>
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 02/10] mm, page_alloc: Remove unnecessary parameter from zone_watermark_ok_safe
In reply to Mel GormanQuoted 6 lines · Mel Gorman
From: Mel Gorman <[email protected]>
No user of
zone_watermark_ok_safe()specifiesalloc_flags. This patch removes the unnecessary parameter.Signed-off-by Mel Gorman <[email protected]>
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/10 mm, page_alloc: Remove unnecessary recalculations for dirty zone balancing
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
File-backed pages that will be immediately dirtied are balanced between zones but it's unnecessarily expensive. Move consider_zone_balanced into the alloc_context instead of checking bitmaps multiple times.
--- mm/internal.h | 1 + mm/page_alloc.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
mm/internal.h +1 -0
@@ -129,6 +129,7 @@ struct alloc_context {int classzone_idx;int migratetype;enum zone_type high_zoneidx; +bool consider_zone_dirty; };/*
mm/page_alloc.c +6 -3
@@ -2295,8 +2295,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,struct zoneref *z;struct page *page =NULL ;struct zone *zone; -bool consider_zone_dirty = (alloc_flags &ALLOC_WMARK_LOW ) && - (gfp_mask & __GFP_WRITE);int nr_fair_skipped =0 ;bool zonelist_rescan;
@@ -2355,7 +2353,7 @@ zonelist_scan:* will require awareness of zones in the * dirty-throttling and the flusher threads. */ -if (consider_zone_dirty && !zone_dirty_ok (zone)) +if (ac->consider_zone_dirty && !zone_dirty_ok (zone))continue ; mark = zone->watermark[alloc_flags &ALLOC_WMARK_MASK ];
@@ -2995,6 +2993,10 @@ retry_cpuset:/* We set it here, as __alloc_pages_slowpath might have changed it */ ac.zonelist = zonelist; + +/* Dirty zone balancing only done in the fast path */ + ac.consider_zone_dirty = (gfp_mask & __GFP_WRITE); +/* The preferred zone is used for statistics later */ preferred_zoneref =first_zones_zonelist (ac.zonelist, ac.high_zoneidx, ac.nodemask, &ac.preferred_zone);
@@ -3012,6 +3014,7 @@ retry_cpuset:* complete. */ alloc_mask =memalloc_noio_flags (gfp_mask); + ac.consider_zone_dirty = false; page =__alloc_pages_slowpath (alloc_mask, order, &ac); }
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 03/10] mm, page_alloc: Remove unnecessary recalculations for dirty zone balancing
Quoted 7 lines · Mel Gorman
From: Mel Gorman <[email protected]>
File-backed pages that will be immediately dirtied are balanced between zones but it's unnecessarily expensive. Move
consider_zone_balancedinto thealloc_contextinstead of checking bitmaps multiple times.Signed-off-by Mel Gorman <[email protected]>
consider_zone_dirty eliminates zones over their dirty limits and zone_dirty_ok() returns true if zones are under their dirty limits, so the naming of both are a little strange. You might consider changing them while you're here.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 03/10] mm, page_alloc: Remove unnecessary recalculations for dirty zone balancing
Quoted 4 lines · David Rientjes
Quoted 2 lines · Mel Gorman
From: Mel Gorman <[email protected]>
Quoted 8 lines
Quoted 5 lines
File-backed pages that will be immediately dirtied are balanced between zones but it's unnecessarily expensive. Move
consider_zone_balancedinto thealloc_contextinstead of checking bitmaps multiple times.Signed-off-by Mel Gorman <[email protected]>Acked-by David Rientjes <[email protected]>
Thanks.
Quoted 4 lines
consider_zone_dirtyeliminates zones over their dirty limits andzone_dirty_ok()returns true if zones are under their dirty limits, so the naming of both are a little strange. You might consider changing them while you're here.
Yeah, that seems sensible. I named the struct field spread_dirty_page so the relevant check now looks like
if (ac->spread_dirty_page && !zone_dirty_ok(zone))
Alternative suggestions welcome but I think this is more meaningful than consider_zone_dirty was.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 03/10] mm, page_alloc: Remove unnecessary recalculations for dirty zone balancing
In reply to Mel GormanQuoted 7 lines · Mel Gorman
From: Mel Gorman <[email protected]>
File-backed pages that will be immediately dirtied are balanced between zones but it's unnecessarily expensive. Move
consider_zone_balancedinto thealloc_contextinstead of checking bitmaps multiple times.Signed-off-by Mel Gorman <[email protected]>
Agreed with new ac->spread_dirty_page name (or rather plural, spread_dirty_pages?) , and a nitpick below.
mm/page_alloc.c zonelist_scan:
Quoted 31 lines
--- mm/internal.h | 1 + mm/page_alloc.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)mm/internal.h +1
-0@@ -129,6 +129,7 @@ struct alloc_context {int classzone_idx;int migratetype;enum zone_type high_zoneidx; +bool consider_zone_dirty; };/* mm/page_alloc.c +0
-2@@ -2295,8 +2295,6 @@ get_page_from_freelist(gfp_t gfp_mask, unsigned int order, int alloc_flags,struct zoneref *z;struct page *page =NULL ;struct zone *zone; -bool consider_zone_dirty = (alloc_flags &ALLOC_WMARK_LOW ) && - (gfp_mask & __GFP_WRITE);int nr_fair_skipped =0 ;bool zonelist_rescan;@@ -2355,7 +2353,7 @@ zonelist_scan:
I've been recently suggested by mhocko to add to ~/.gitconfig
[diff "default"]
xfuncname = "^[[:alpha:]$_].*[^:]$"
So that git produces function names in hunk context instead of labels. I gladly spread this arcane knowledge :)
mm/page_alloc.c zonelist_scan: · line 2355
Quoted 3 lines
mm/page_alloc.c +0
-0* will require awareness of zones in the * dirty-throttling and the flusher threads. */
This comment (in the part not shown) mentions ALLOC_WMARK_LOW as the mechanism to distinguish fastpath from slowpath. This is no longer true, so update it too?
Quoted 18 lines
mm/page_alloc.c +5
-1-if (consider_zone_dirty && !zone_dirty_ok (zone)) +if (ac->consider_zone_dirty && !zone_dirty_ok (zone))continue ; mark = zone->watermark[alloc_flags &ALLOC_WMARK_MASK ];@@ -2995,6 +2993,10 @@ retry_cpuset:/* We set it here, as __alloc_pages_slowpath might have changed it */ ac.zonelist = zonelist; + +/* Dirty zone balancing only done in the fast path */ + ac.consider_zone_dirty = (gfp_mask & __GFP_WRITE); +/* The preferred zone is used for statistics later */ preferred_zoneref =first_zones_zonelist (ac.zonelist, ac.high_zoneidx, ac.nodemask, &ac.preferred_zone);
mm/page_alloc.c retry_cpuset: · line 3020
Quoted 7 lines
mm/page_alloc.c +1
-0@@ -3012,6 +3014,7 @@ retry_cpuset:* complete. */ alloc_mask =memalloc_noio_flags (gfp_mask); + ac.consider_zone_dirty = false; page =__alloc_pages_slowpath (alloc_mask, order, &ac); }
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/10 mm, page_alloc: Remove unnecessary taking of a seqlock when cpusets are disabled
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
There is a seqcounter that protects spurious allocation fails when a task is changing the allowed nodes in a cpuset. There is no need to check the seqcounter until a cpuset exists.
--- include/linux/cpuset.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/linux/cpuset.h +6 -0
@@ -104,6 +104,9 @@ extern void cpuset_print_task_mems_allowed(struct task_struct *p);*/ static inline unsigned int read_mems_allowed_begin (void ) { +if (!cpusets_enabled ()) +return 0 ; +return read_seqcount_begin (¤t->mems_allowed_seq); }
@@ -115,6 +118,9 @@ static inline unsigned int read_mems_allowed_begin(void)*/ static inline bool read_mems_allowed_retry (unsigned int seq) { +if (!cpusets_enabled ()) +return false; +return read_seqcount_retry (¤t->mems_allowed_seq, seq); }
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/10] mm, page_alloc: Remove unnecessary taking of a seqlock when cpusets are disabled
Quoted 7 lines · Mel Gorman
From: Mel Gorman <[email protected]>
There is a seqcounter that protects spurious allocation fails when a task is changing the allowed nodes in a cpuset. There is no need to check the seqcounter until a cpuset exists.
Signed-off-by Mel Gorman <[email protected]>
but there's a typo in your email address in the signed-off-by line. Nice to know you actually type them by hand though :)
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 04/10] mm, page_alloc: Remove unnecessary taking of a seqlock when cpusets are disabled
In reply to Mel GormanQuoted 5 lines · Mel Gorman
From: Mel Gorman <[email protected]>
There is a seqcounter that protects spurious allocation fails when a task is changing the allowed nodes in a cpuset. There is no need to check the seqcounter until a cpuset exists.
If cpusets become enabled betwen _begin and _retry, then it will retry due to comparing with 0, but not crash, so it's safe.
Quoted 1 line
Signed-off-by Mel Gorman <[email protected]>
Quoted 20 lines
--- include/linux/cpuset.h | 6 ++++++ 1 file changed, 6 insertions(+)include/linux/cpuset.h +3
-0@@ -104,6 +104,9 @@ extern void cpuset_print_task_mems_allowed(struct task_struct *p);*/ static inline unsigned int read_mems_allowed_begin (void ) { +if (!cpusets_enabled ()) +return 0 ; +return read_seqcount_begin (¤t->mems_allowed_seq); }
include/linux/cpuset.h static inline unsigned int read_mems_allowed_begin(void) · line 126
Quoted 9 lines
include/linux/cpuset.h +3
-0@@ -115,6 +118,9 @@ static inline unsigned int read_mems_allowed_begin(void)*/ static inline bool read_mems_allowed_retry (unsigned int seq) { +if (!cpusets_enabled ()) +return false; +return read_seqcount_retry (¤t->mems_allowed_seq, seq); }
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/10 mm, page_alloc: Remove unnecessary updating of GFP flags during normal operation
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
During boot and suspend there is a restriction on the allowed GFP flags. During boot it prevents blocking operations before the scheduler is active. During suspend it is to avoid IO operations when storage is unavailable. The restriction on the mask is applied in some allocator hot-paths during normal operation which is wasteful. Use jump labels to only update the GFP mask when it is restricted.
--- include/linux/gfp.h | 33 ++++++++++++++++++++++++++++----- init/main.c | 2 +- mm/page_alloc.c | 21 +++++++-------------- mm/slab.c | 4 ++-- mm/slob.c | 4 ++-- mm/slub.c | 6 +++--- 6 files changed, 43 insertions(+), 27 deletions(-)
include/linux/gfp.h +28 -5
@@ -394,12 +394,35 @@ static inline void page_alloc_init_late(void)/* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what -* GFP flags are used before interrupts are enabled. Once interrupts are -* enabled, it is set to __GFP_BITS_MASK while the system is running. During -* hibernation, it is used by PM to avoid I/O during memory allocation while -* devices are suspended. +* GFP flags are used before interrupts are enabled. During hibernation, it is +* used by PM to avoid I/O during memory allocation while devices are suspended. */ -extern gfp_t gfp_allowed_mask; +extern gfp_t __gfp_allowed_mask; + +/* Only update the gfp_mask when it is restricted */ +extern struct static_key gfp_restricted_key; + +static inline gfp_t gfp_allowed_mask (gfp_t gfp_mask) +{ +if (static_key_false (&gfp_restricted_key)) +return gfp_mask; + +return gfp_mask & __gfp_allowed_mask; +} + +static inline void unrestrict_gfp_allowed_mask (void ) +{ +WARN_ON (!static_key_enabled (&gfp_restricted_key)); + __gfp_allowed_mask = __GFP_BITS_MASK; +static_key_slow_dec (&gfp_restricted_key); +} + +static inline void restrict_gfp_allowed_mask (gfp_t gfp_mask) +{ +WARN_ON (static_key_enabled (&gfp_restricted_key)); + __gfp_allowed_mask = gfp_mask; +static_key_slow_inc (&gfp_restricted_key); +}/* Returns true if the gfp_mask allows use of ALLOC_NO_WATERMARK */ bool gfp_pfmemalloc_allowed (gfp_t gfp_mask);
init/main.c +1 -1
@@ -983,7 +983,7 @@ static noinline void __init kernel_init_freeable(void)wait_for_completion (&kthreadd_done);/* Now the scheduler is fully set up and can do blocking allocations */ - gfp_allowed_mask = __GFP_BITS_MASK; +unrestrict_gfp_allowed_mask ();/* * init can allocate pages on any node
mm/page_alloc.c +7 -14
@@ -124,7 +124,9 @@ unsigned long totalcma_pages __read_mostly;unsigned long dirty_balance_reserve__read_mostly ;int percpu_pagelist_fraction; -gfp_t gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; + +gfp_t __gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; +struct static_key gfp_restricted_key__read_mostly =STATIC_KEY_INIT_TRUE ;#ifdef CONFIG_PM_SLEEP /*
@@ -136,30 +138,21 @@ gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;* guaranteed not to run in parallel with that modification). */ -static gfp_t saved_gfp_mask; -void pm_restore_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&pm_mutex)); -if (saved_gfp_mask) { - gfp_allowed_mask = saved_gfp_mask; - saved_gfp_mask =0 ; - } +unrestrict_gfp_allowed_mask (); }void pm_restrict_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&pm_mutex)); -WARN_ON (saved_gfp_mask); - saved_gfp_mask = gfp_allowed_mask; - gfp_allowed_mask &= ~GFP_IOFS ; +restrict_gfp_allowed_mask (__GFP_BITS_MASK & ~GFP_IOFS ); }bool pm_suspended_storage (void ) { -if ((gfp_allowed_mask &GFP_IOFS ) ==GFP_IOFS ) -return false; -return true; +return static_key_enabled (&gfp_restricted_key); }#endif /* CONFIG_PM_SLEEP */
@@ -2968,7 +2961,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, .migratetype = gfpflags_to_migratetype(gfp_mask), }; - gfp_mask &= gfp_allowed_mask; + gfp_mask =gfp_allowed_mask (gfp_mask);lockdep_trace_alloc (gfp_mask);
mm/slab.c +2 -2
@@ -3151,7 +3151,7 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,void *ptr;int slab_node =numa_mem_id (); - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);
@@ -3239,7 +3239,7 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller)unsigned long save_flags;void *objp; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);
mm/slob.c +2 -2
@@ -430,7 +430,7 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)int align =max_t (size_t,ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN );void *ret; - gfp &= gfp_allowed_mask; + gfp =gfp_allowed_mask (gfp);lockdep_trace_alloc (gfp);
@@ -536,7 +536,7 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node) {void *b; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);
mm/slub.c +3 -3
@@ -1261,7 +1261,7 @@ static inline void kfree_hook(const void *x)static inline struct kmem_cache *slab_pre_alloc_hook (struct kmem_cache *s,gfp_t flags) { - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);might_sleep_if (flags & __GFP_WAIT);
@@ -1274,7 +1274,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s,static inline void slab_post_alloc_hook (struct kmem_cache *s,gfp_t flags,void *object) { - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);kmemcheck_slab_alloc (s, flags, object,slab_ksize (s));kmemleak_alloc_recursive (object, s->object_size,1 , s->flags, flags);memcg_kmem_put_cache (s);
@@ -1337,7 +1337,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)struct kmem_cache_order_objects oo = s->oo;gfp_t alloc_gfp; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);if (flags & __GFP_WAIT)local_irq_enable ();
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/10] mm, page_alloc: Remove unnecessary updating of GFP flags during normal operation
Quoted 10 lines · Mel Gorman
From: Mel Gorman <[email protected]>
During boot and suspend there is a restriction on the allowed GFP flags. During boot it prevents blocking operations before the scheduler is active. During suspend it is to avoid IO operations when storage is unavailable. The restriction on the mask is applied in some allocator hot-paths during normal operation which is wasteful. Use jump labels to only update the GFP mask when it is restricted.
Signed-off-by Mel Gorman <[email protected]>
[+CC Peterz, not trimmed due to that]
Quoted 23 lines
--- include/linux/gfp.h | 33 ++++++++++++++++++++++++++++----- init/main.c | 2 +- mm/page_alloc.c | 21 +++++++-------------- mm/slab.c | 4 ++-- mm/slob.c | 4 ++-- mm/slub.c | 6 +++--- 6 files changed, 43 insertions(+), 27 deletions(-)include/linux/gfp.h +2
-4@@ -394,12 +394,35 @@ static inline void page_alloc_init_late(void)/* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what -* GFP flags are used before interrupts are enabled. Once interrupts are -* enabled, it is set to __GFP_BITS_MASK while the system is running. During -* hibernation, it is used by PM to avoid I/O during memory allocation while -* devices are suspended. +* GFP flags are used before interrupts are enabled. During hibernation, it is +* used by PM to avoid I/O during memory allocation while devices are suspended.
include/linux/gfp.h static inline void page_alloc_init_late(void) · line 407
Quoted 10 lines
include/linux/gfp.h +8
-1*/ -extern gfp_t gfp_allowed_mask; +extern gfp_t __gfp_allowed_mask; + +/* Only update the gfp_mask when it is restricted */ +extern struct static_key gfp_restricted_key; + +static inline gfp_t gfp_allowed_mask (gfp_t gfp_mask) +{ +if (static_key_false (&gfp_restricted_key))
This is where it uses static_key_false()...
Quoted 39 lines
include/linux/gfp.h +18
-0+return gfp_mask; + +return gfp_mask & __gfp_allowed_mask; +} + +static inline void unrestrict_gfp_allowed_mask (void ) +{ +WARN_ON (!static_key_enabled (&gfp_restricted_key)); + __gfp_allowed_mask = __GFP_BITS_MASK; +static_key_slow_dec (&gfp_restricted_key); +} + +static inline void restrict_gfp_allowed_mask (gfp_t gfp_mask) +{ +WARN_ON (static_key_enabled (&gfp_restricted_key)); + __gfp_allowed_mask = gfp_mask; +static_key_slow_inc (&gfp_restricted_key); +}/* Returns true if the gfp_mask allows use of ALLOC_NO_WATERMARK */ bool gfp_pfmemalloc_allowed (gfp_t gfp_mask);init/main.c +1
-1@@ -983,7 +983,7 @@ static noinline void __init kernel_init_freeable(void)wait_for_completion (&kthreadd_done);/* Now the scheduler is fully set up and can do blocking allocations */ - gfp_allowed_mask = __GFP_BITS_MASK; +unrestrict_gfp_allowed_mask ();/* * init can allocate pages on any node mm/page_alloc.c +0
-0
mm/page_alloc.c unsigned long totalcma_pages __read_mostly; · line 129
Quoted 7 lines
mm/page_alloc.c +3
-1@@ -124,7 +124,9 @@ unsigned long totalcma_pages __read_mostly;unsigned long dirty_balance_reserve__read_mostly ;int percpu_pagelist_fraction; -gfp_t gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; + +gfp_t __gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; +struct static_key gfp_restricted_key__read_mostly =STATIC_KEY_INIT_TRUE ;
... and here it's combined with STATIC_KEY_INIT_TRUE. I've suspected that this is not allowed, which Peter confirmed on IRC.
It's however true that the big comment at the top of include/linux/jump_label.h only explicitly talks about combining static_key_false() and static_key_true().
I'm not sure what's the correct idiom for a default-false static key which however has to start as true on boot (Peter said such cases do exist)...
Quoted 114 lines
mm/page_alloc.c +4
-13#ifdef CONFIG_PM_SLEEP /* @@ -136,30 +138,21 @@ gfp_t gfp_allowed_mask __read_mostly = GFP_BOOT_MASK;* guaranteed not to run in parallel with that modification). */ -static gfp_t saved_gfp_mask; -void pm_restore_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&pm_mutex)); -if (saved_gfp_mask) { - gfp_allowed_mask = saved_gfp_mask; - saved_gfp_mask =0 ; - } +unrestrict_gfp_allowed_mask (); }void pm_restrict_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&pm_mutex)); -WARN_ON (saved_gfp_mask); - saved_gfp_mask = gfp_allowed_mask; - gfp_allowed_mask &= ~GFP_IOFS ; +restrict_gfp_allowed_mask (__GFP_BITS_MASK & ~GFP_IOFS ); }bool pm_suspended_storage (void ) { -if ((gfp_allowed_mask &GFP_IOFS ) ==GFP_IOFS ) -return false; -return true; +return static_key_enabled (&gfp_restricted_key); }#endif /* CONFIG_PM_SLEEP */ @@ -2968,7 +2961,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, .migratetype = gfpflags_to_migratetype(gfp_mask), }; - gfp_mask &= gfp_allowed_mask; + gfp_mask =gfp_allowed_mask (gfp_mask);lockdep_trace_alloc (gfp_mask);mm/slab.c +2
-2@@ -3151,7 +3151,7 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,void *ptr;int slab_node =numa_mem_id (); - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);@@ -3239,7 +3239,7 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller)unsigned long save_flags;void *objp; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);mm/slob.c +2
-2@@ -430,7 +430,7 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)int align =max_t (size_t,ARCH_KMALLOC_MINALIGN ,ARCH_SLAB_MINALIGN );void *ret; - gfp &= gfp_allowed_mask; + gfp =gfp_allowed_mask (gfp);lockdep_trace_alloc (gfp);@@ -536,7 +536,7 @@ static void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node) {void *b; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);mm/slub.c +2
-2@@ -1261,7 +1261,7 @@ static inline void kfree_hook(const void *x)static inline struct kmem_cache *slab_pre_alloc_hook (struct kmem_cache *s,gfp_t flags) { - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);lockdep_trace_alloc (flags);might_sleep_if (flags & __GFP_WAIT);@@ -1274,7 +1274,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s,static inline void slab_post_alloc_hook (struct kmem_cache *s,gfp_t flags,void *object) { - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);kmemcheck_slab_alloc (s, flags, object,slab_ksize (s));kmemleak_alloc_recursive (object, s->object_size,1 , s->flags, flags);memcg_kmem_put_cache (s);
mm/slub.c static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node) · line 1343
Quoted 8 lines
mm/slub.c +1
-1@@ -1337,7 +1337,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)struct kmem_cache_order_objects oo = s->oo;gfp_t alloc_gfp; - flags &= gfp_allowed_mask; + flags =gfp_allowed_mask (flags);if (flags & __GFP_WAIT)local_irq_enable ();
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/10] mm, page_alloc: Remove unnecessary updating of GFP flags during normal operation
Quoted 11 lines · Vlastimil Babka
include/linux/gfp.h static inline void page_alloc_init_late(void) · line 407
Quoted 3 lines
include/linux/gfp.h +3
-0+static inline gfp_t gfp_allowed_mask (gfp_t gfp_mask) +{ +if (static_key_false (&gfp_restricted_key))This is where it uses
static_key_false()...Quoted 1 line
+struct
static_keygfp_restricted_key__read_mostly=STATIC_KEY_INIT_TRUE;... and here it's combined with
STATIC_KEY_INIT_TRUE. I've suspected that this is not allowed, which Peter confirmed on IRC.
Quoted 6 lines
It's however true that the big comment at the top of
include/linux/jump_label.honly explicitly talks about combiningstatic_key_false()andstatic_key_true().I'm not sure what's the correct idiom for a default-false static key which however has to start as true on boot (Peter said such cases do exist)...
There currently isn't one. But see the patchset I just send to address this:
lkml.kernel.org/r/[email protected]
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 05/10] mm, page_alloc: Remove unnecessary updating of GFP flags during normal operation
In reply to Vlastimil BabkaQuoted 5 lines · Vlastimil Babka
Quoted 5 lines
mm/page_alloc.c +0
-0@@ -124,7 +124,9 @@ unsigned long totalcma_pages __read_mostly;unsigned long dirty_balance_reserve__read_mostly ;
Quoted 9 lines
mm/page_alloc.c unsigned long totalcma_pages __read_mostly; · line 129
Quoted 5 lines
mm/page_alloc.c +3
-1int percpu_pagelist_fraction; -gfp_t gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; + +gfp_t __gfp_allowed_mask__read_mostly =GFP_BOOT_MASK ; +struct static_key gfp_restricted_key__read_mostly =STATIC_KEY_INIT_TRUE ;... and here it's combined with
STATIC_KEY_INIT_TRUE. I've suspected that this is not allowed, which Peter confirmed on IRC.
Thanks because I was not aware of hazards of that nature. I'll drop the jump-label related patches from the series until the patches related to the correct idiom are finalised. The micro-optimisations are not the main point of this series and the savings are tiny.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 6/10 mm, page_alloc: Use jump label to check if page grouping by mobility is enabled
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
The global variable page_group_by_mobility_disabled remembers if page grouping by mobility was disabled at boot time. It's more efficient to do this by jump label.
--- include/linux/gfp.h | 2 +- include/linux/mmzone.h | 7 ++++++- mm/page_alloc.c | 15 ++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-)
include/linux/gfp.h +1 -1
@@ -151,7 +151,7 @@ static inline int gfpflags_to_migratetype(const gfp_t gfp_flags) {WARN_ON ((gfp_flags &GFP_MOVABLE_MASK ) ==GFP_MOVABLE_MASK ); -if (unlikely (page_group_by_mobility_disabled)) +if (page_group_by_mobility_disabled ())return MIGRATE_UNMOVABLE ;/* Group based on mobility */
include/linux/mmzone.h +6 -1
@@ -73,7 +73,12 @@ enum {for (order =0 ; order <MAX_ORDER ; order++) \for (type =0 ; type <MIGRATE_TYPES ; type++) -extern int page_group_by_mobility_disabled; +extern struct static_key page_group_by_mobility_key; + +static inline bool page_group_by_mobility_disabled (void ) +{ +return static_key_false (&page_group_by_mobility_key); +}#define NR_MIGRATETYPE_BITS (PB_migrate_end - PB_migrate + 1)#define MIGRATETYPE_MASK ((1UL << NR_MIGRATETYPE_BITS) - 1)
mm/page_alloc.c +6 -9
@@ -228,7 +228,7 @@ EXPORT_SYMBOL(nr_node_ids);EXPORT_SYMBOL (nr_online_nodes);#endif -int page_group_by_mobility_disabled__read_mostly ; +struct static_key page_group_by_mobility_key__read_mostly =STATIC_KEY_INIT_FALSE ;#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT static inline void reset_deferred_meminit (pg_data_t *pgdat)
@@ -303,8 +303,7 @@ static inline bool update_defer_init(pg_data_t *pgdat,void set_pageblock_migratetype (struct page *page,int migratetype) { -if (unlikely (page_group_by_mobility_disabled && - migratetype <MIGRATE_PCPTYPES )) +if (page_group_by_mobility_disabled () && migratetype <MIGRATE_PCPTYPES ) migratetype =MIGRATE_UNMOVABLE ; set_pageblock_flags_group(page, (unsigned long)migratetype,
@@ -1501,7 +1500,7 @@ static bool can_steal_fallback(unsigned int order, int start_mt)if (order >= pageblock_order /2 || start_mt ==MIGRATE_RECLAIMABLE || start_mt ==MIGRATE_UNMOVABLE || - page_group_by_mobility_disabled) +page_group_by_mobility_disabled ())return true;return false;
@@ -1530,7 +1529,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,/* Claim the whole block if over half of it is free */ if (pages >= (1 << (pageblock_order-1 )) || - page_group_by_mobility_disabled) +page_group_by_mobility_disabled ())set_pageblock_migratetype (page, start_type); }
@@ -4156,15 +4155,13 @@ void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)* disabled and enable it later */ if (vm_total_pages < (pageblock_nr_pages *MIGRATE_TYPES )) - page_group_by_mobility_disabled =1 ; -else - page_group_by_mobility_disabled =0 ; +static_key_slow_inc (&page_group_by_mobility_key);pr_info ("Built %i zonelists in %s order, mobility grouping %s. " "Total pages: %ld\n" , nr_online_nodes, zonelist_order_name[current_zonelist_order], - page_group_by_mobility_disabled ?"off" :"on" , +page_group_by_mobility_disabled () ?"off" :"on" , vm_total_pages);#ifdef CONFIG_NUMA pr_info ("Policy zone: %s\n" , zone_names[policy_zone]);
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 06/10] mm, page_alloc: Use jump label to check if page grouping by mobility is enabled
Quoted 7 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The global variable
page_group_by_mobility_disabledremembers if page grouping by mobility was disabled at boot time. It's more efficient to do this by jump label.Signed-off-by Mel Gorman <[email protected]>
[+CC Peterz]
Quoted 24 lines
--- include/linux/gfp.h | 2 +- include/linux/mmzone.h | 7 ++++++- mm/page_alloc.c | 15 ++++++--------- 3 files changed, 13 insertions(+), 11 deletions(-)include/linux/gfp.h +1
-1@@ -151,7 +151,7 @@ static inline int gfpflags_to_migratetype(const gfp_t gfp_flags) {WARN_ON ((gfp_flags &GFP_MOVABLE_MASK ) ==GFP_MOVABLE_MASK ); -if (unlikely (page_group_by_mobility_disabled)) +if (page_group_by_mobility_disabled ())return MIGRATE_UNMOVABLE ;/* Group based on mobility */ include/linux/mmzone.h +0
-0
include/linux/mmzone.h enum { · line 76
Quoted 5 lines
include/linux/mmzone.h +1
-1@@ -73,7 +73,12 @@ enum {for (order =0 ; order <MAX_ORDER ; order++) \for (type =0 ; type <MIGRATE_TYPES ; type++) -extern int page_group_by_mobility_disabled; +extern struct static_key page_group_by_mobility_key;
The "disabled" part is no longer in the name, but I suspect you didn't want it to be too long?
Quoted 50 lines
include/linux/mmzone.h +5
-0+ +static inline bool page_group_by_mobility_disabled (void ) +{ +return static_key_false (&page_group_by_mobility_key); +}#define NR_MIGRATETYPE_BITS (PB_migrate_end - PB_migrate + 1)#define MIGRATETYPE_MASK ((1UL << NR_MIGRATETYPE_BITS) - 1)mm/page_alloc.c +4
-5@@ -228,7 +228,7 @@ EXPORT_SYMBOL(nr_node_ids);EXPORT_SYMBOL (nr_online_nodes);#endif -int page_group_by_mobility_disabled__read_mostly ; +struct static_key page_group_by_mobility_key__read_mostly =STATIC_KEY_INIT_FALSE ;#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT static inline void reset_deferred_meminit (pg_data_t *pgdat)@@ -303,8 +303,7 @@ static inline bool update_defer_init(pg_data_t *pgdat,void set_pageblock_migratetype (struct page *page,int migratetype) { -if (unlikely (page_group_by_mobility_disabled && - migratetype <MIGRATE_PCPTYPES )) +if (page_group_by_mobility_disabled () && migratetype <MIGRATE_PCPTYPES ) migratetype =MIGRATE_UNMOVABLE ; set_pageblock_flags_group(page, (unsigned long)migratetype,@@ -1501,7 +1500,7 @@ static bool can_steal_fallback(unsigned int order, int start_mt)if (order >= pageblock_order /2 || start_mt ==MIGRATE_RECLAIMABLE || start_mt ==MIGRATE_UNMOVABLE || - page_group_by_mobility_disabled) +page_group_by_mobility_disabled ())return true;return false;@@ -1530,7 +1529,7 @@ static void steal_suitable_fallback(struct zone *zone, struct page *page,/* Claim the whole block if over half of it is free */ if (pages >= (1 << (pageblock_order-1 )) || - page_group_by_mobility_disabled) +page_group_by_mobility_disabled ())set_pageblock_migratetype (page, start_type); }
mm/page_alloc.c void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone) · line 4158
Quoted 7 lines
mm/page_alloc.c +1
-3@@ -4156,15 +4155,13 @@ void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)* disabled and enable it later */ if (vm_total_pages < (pageblock_nr_pages *MIGRATE_TYPES )) - page_group_by_mobility_disabled =1 ; -else - page_group_by_mobility_disabled =0 ; +static_key_slow_inc (&page_group_by_mobility_key);
Um so previously, booting with little memory would disable grouping by mobility, and later hotpluging would enable it again, right? But this is now removed, and once disabled means always disabled? That can't be right, and I'm not sure about the effects of the recently introduced delayed initialization here?
Looks like the API addition that Peter just posted, would be useful here :) http://marc.info/?l=linux-kernel&m=143808996921651&w=2
mm/page_alloc.c void __ref build_all_zonelists(pg_data_t *pgdat, struct zone *zone)
Quoted 11 lines
mm/page_alloc.c +1
-1pr_info ("Built %i zonelists in %s order, mobility grouping %s. " "Total pages: %ld\n" , nr_online_nodes, zonelist_order_name[current_zonelist_order], - page_group_by_mobility_disabled ?"off" :"on" , +page_group_by_mobility_disabled () ?"off" :"on" , vm_total_pages);#ifdef CONFIG_NUMA pr_info ("Policy zone: %s\n" , zone_names[policy_zone]);
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 7/10 mm, page_alloc: Use masks and shifts when converting GFP flags to migrate types
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
This patch redefines which GFP bits are used for specifying mobility and the order of the migrate types. Once redefined it's possible to convert GFP flags to a migrate type with a simple mask and shift. The only downside is that readers of OOM kill messages and allocation failures may have been used to the existing values but scripts/gfp-translate will help.
--- include/linux/gfp.h | 12 +++++++----- include/linux/mmzone.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)
include/linux/gfp.h +7 -5
@@ -14,7 +14,7 @@ struct vm_area_struct;#define ___GFP_HIGHMEM 0x02u#define ___GFP_DMA32 0x04u#define ___GFP_MOVABLE 0x08u -#define ___GFP_WAIT 0x10u +#define ___GFP_RECLAIMABLE 0x10u#define ___GFP_HIGH 0x20u#define ___GFP_IO 0x40u#define ___GFP_FS 0x80u
@@ -29,7 +29,7 @@ struct vm_area_struct;#define ___GFP_NOMEMALLOC 0x10000u#define ___GFP_HARDWALL 0x20000u#define ___GFP_THISNODE 0x40000u -#define ___GFP_RECLAIMABLE 0x80000u +#define ___GFP_WAIT 0x80000u#define ___GFP_NOACCOUNT 0x100000u#define ___GFP_NOTRACK 0x200000u#define ___GFP_NO_KSWAPD 0x400000u
@@ -123,6 +123,7 @@ struct vm_area_struct;/* This mask makes up all the page movable related flags */ #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE) +#define GFP_MOVABLE_SHIFT 3/* Control page allocator reclaim behavior */ #define GFP_RECLAIM_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS|\
@@ -149,14 +150,15 @@ struct vm_area_struct;/* Convert GFP flags to their corresponding migrate type */ static inline int gfpflags_to_migratetype (const gfp_t gfp_flags) { -WARN_ON ((gfp_flags &GFP_MOVABLE_MASK ) ==GFP_MOVABLE_MASK ); +VM_WARN_ON ((gfp_flags &GFP_MOVABLE_MASK ) ==GFP_MOVABLE_MASK ); +BUILD_BUG_ON (1UL <<GFP_MOVABLE_SHIFT != ___GFP_MOVABLE); +BUILD_BUG_ON (___GFP_MOVABLE >>GFP_MOVABLE_SHIFT !=MIGRATE_MOVABLE );if (page_group_by_mobility_disabled ())return MIGRATE_UNMOVABLE ;/* Group based on mobility */ -return (((gfp_flags & __GFP_MOVABLE) !=0 ) <<1 ) | - ((gfp_flags & __GFP_RECLAIMABLE) !=0 ); +return (gfp_flags &GFP_MOVABLE_MASK ) >>GFP_MOVABLE_SHIFT ; }#ifdef CONFIG_HIGHMEM
include/linux/mmzone.h +1 -1
@@ -37,8 +37,8 @@enum {MIGRATE_UNMOVABLE , -MIGRATE_RECLAIMABLE ,MIGRATE_MOVABLE , +MIGRATE_RECLAIMABLE ,MIGRATE_PCPTYPES ,/* the number of types on the pcp lists */ MIGRATE_RESERVE =MIGRATE_PCPTYPES ,#ifdef CONFIG_CMA
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 8/10 mm, page_alloc: Remove MIGRATE_RESERVE
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
MIGRATE_RESERVE preserves an old property of the buddy allocator that existed prior to fragmentation avoidance -- min_free_kbytes worth of pages tended to remain free until the only alternative was to fail the allocation. At the time it was discovered that high-order atomic allocations relied on this property so MIGRATE_RESERVE was introduced. A later patch will introduce an alternative MIGRATE_HIGHATOMIC so this patch deletes MIGRATE_RESERVE and supporting code so it'll be easier to review. Note that this patch in isolation may look like a false regression if someone was bisecting high-order atomic allocation failures.
--- include/linux/mmzone.h | 10 +--- mm/huge_memory.c | 2 +- mm/page_alloc.c | 148 +++---------------------------------------------- mm/vmstat.c | 1 - 4 files changed, 11 insertions(+), 150 deletions(-)
include/linux/mmzone.h +2 -8
@@ -39,8 +39,6 @@ enum {MIGRATE_UNMOVABLE ,MIGRATE_MOVABLE ,MIGRATE_RECLAIMABLE , -MIGRATE_PCPTYPES ,/* the number of types on the pcp lists */ -MIGRATE_RESERVE =MIGRATE_PCPTYPES , #ifdef CONFIG_CMA/* * MIGRATE_CMA migration type is designed to mimic the way
@@ -63,6 +61,8 @@ enum { MIGRATE_TYPES }; +#define MIGRATE_PCPTYPES (MIGRATE_RECLAIMABLE+1) +#ifdef CONFIG_CMA # define is_migrate_cma (migratetype) unlikely((migratetype) == MIGRATE_CMA)#else
@@ -430,12 +430,6 @@ struct zone {const char *name; -/* -* Number of MIGRATE_RESERVE page block. To maintain for just -* optimization. Protected by zone->lock. -*/ -int nr_migrate_reserve_block; -#ifdef CONFIG_MEMORY_ISOLATION /* * Number of isolated pageblock. It is used to solve incorrect
mm/huge_memory.c +1 -1
@@ -113,7 +113,7 @@ static int set_recommended_min_free_kbytes(void)for_each_populated_zone (zone) nr_zones++; -/* Make sure at least 2 hugepages are free for MIGRATE_RESERVE */ +/* Ensure 2 pageblocks are free to assist fragmentation avoidance */ recommended_min = pageblock_nr_pages * nr_zones *2 ;/*
mm/page_alloc.c +8 -140
205 lines not on this page · raw message
mm/vmstat.c +0 -1
@@ -901,7 +901,6 @@ static char * const migratetype_names[MIGRATE_TYPES] = {"Unmovable" ,"Reclaimable" ,"Movable" , -"Reserve" , #ifdef CONFIG_CMA "CMA", #endif
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 08/10] mm, page_alloc: Remove MIGRATE_RESERVE
Quoted 5 lines · Mel Gorman
From: Mel Gorman <[email protected]>
MIGRATE_RESERVEpreserves an old property of the buddy allocator that existed prior to fragmentation avoidance --min_free_kbytesworth of pages tended to remain free until the only alternative was to fail the allocation. At the
^ I think you meant contiguous instead of free? Is it because
splitting chooses lowest possible order, and grouping by mobility means you might be splitting e.g. order-5 movable page instead of using order-0 unmovable page? And that the fallback heuristics specifically select highest available order? I think it's not that obvious, so worth mentioning.
Quoted 8 lines
time it was discovered that high-order atomic allocations relied on this property so
MIGRATE_RESERVEwas introduced. A later patch will introduce an alternativeMIGRATE_HIGHATOMICso this patch deletesMIGRATE_RESERVEand supporting code so it'll be easier to review. Note that this patch in isolation may look like a false regression if someone was bisecting high-order atomic allocation failures.Signed-off-by Mel Gorman <[email protected]>
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 08/10] mm, page_alloc: Remove MIGRATE_RESERVE
Quoted 8 lines · Vlastimil Babka
Quoted 5 lines · Mel Gorman
From: Mel Gorman <[email protected]>
MIGRATE_RESERVEpreserves an old property of the buddy allocator that existed prior to fragmentation avoidance --min_free_kbytesworth of pages tended to remain free until the only alternative was to fail the allocation. At the^ I think you meant contiguous instead of free?
That is exactly what I meant.
Quoted 6 lines
Is it because
splitting chooses lowest possible order, and grouping by mobility means you might be splitting e.g. order-5 movable page instead of using order-0 unmovable page? And that the fallback heuristics specifically select highest available order? I think it's not that obvious, so worth mentioning.
Yes, the commit that introduced MIGRATE_RESERVE discusses it so I didn't repeat it as the git digging is simply
1. Find the commit that introduced MIGRATE_HIGHATOMIC and see it replaced MIGRATE_RESERVE
2. Find the commit that introduced MIGRATE_RESERVE
That locates 56fd56b868f1 ("Bias the location of pages freed for min_free_kbytes in the same MAX_ORDER_NR_PAGES blocks").
Quoted 11 lines
Quoted 8 lines
time it was discovered that high-order atomic allocations relied on this property so
MIGRATE_RESERVEwas introduced. A later patch will introduce an alternativeMIGRATE_HIGHATOMICso this patch deletesMIGRATE_RESERVEand supporting code so it'll be easier to review. Note that this patch in isolation may look like a false regression if someone was bisecting high-order atomic allocation failures.Signed-off-by Mel Gorman <[email protected]>Acked-by Vlastimil Babka <[email protected]>
Thanks.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 9/10 mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on MIGRATE_RESERVE to preserve min_free_kbytes as high-order free pages for as long as possible. This patch introduces MIGRATE_HIGHATOMIC that reserves pageblocks for high-order atomic allocations. This is expected to be more reliable than MIGRATE_RESERVE was.
A MIGRATE_HIGHORDER pageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.
There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
--- include/linux/mmzone.h | 6 ++- mm/page_alloc.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++--- mm/vmstat.c | 1 + 3 files changed, 112 insertions(+), 9 deletions(-)
include/linux/mmzone.h +4 -2
@@ -39,6 +39,8 @@ enum {MIGRATE_UNMOVABLE ,MIGRATE_MOVABLE ,MIGRATE_RECLAIMABLE , +MIGRATE_PCPTYPES ,/* the number of types on the pcp lists */ +MIGRATE_HIGHATOMIC =MIGRATE_PCPTYPES , #ifdef CONFIG_CMA/* * MIGRATE_CMA migration type is designed to mimic the way
@@ -61,8 +63,6 @@ enum { MIGRATE_TYPES }; -#define MIGRATE_PCPTYPES (MIGRATE_RECLAIMABLE+1) -#ifdef CONFIG_CMA # define is_migrate_cma (migratetype) unlikely((migratetype) == MIGRATE_CMA)#else
@@ -335,6 +335,8 @@ struct zone {/* zone watermarks, access with *_wmark_pages(zone) macros */ unsigned long watermark[NR_WMARK ]; +unsigned long nr_reserved_highatomic; +/* * We don't know if the memory that we're going to allocate will be freeable * or/and it will be released eventually, so to avoid totally wasting several
mm/page_alloc.c +107 -7
185 lines not on this page · raw message
mm/vmstat.c +1 -0
@@ -901,6 +901,7 @@ static char * const migratetype_names[MIGRATE_TYPES] = {"Unmovable" ,"Reclaimable" ,"Movable" , +"HighAtomic" , #ifdef CONFIG_CMA "CMA", #endif
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 11 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.
This looked weird, until I read the implementation and realized that "an allocation request" is limited to high-order atomic allocation requests.
Quoted 21 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
Signed-off-by Mel Gorman <[email protected]>
[...]
Quoted 7 lines
mm/page_alloc.c +7
-0+/* +* Used when an allocation is about to fail under memory pressure. This +* potentially hurts the reliability of high-order allocations when under +* intense memory pressure but failed atomic allocations should be easier +* to recover from than an OOM. +*/ +static void unreserve_highatomic_pageblock (const struct alloc_context *ac)
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1616
Quoted 10 lines
mm/page_alloc.c +10
-0+{ +struct zonelist *zonelist = ac->zonelist; +unsigned long flags; +struct zoneref *z; +struct zone *zone; +struct page *page; +int order; + +for_each_zone_zonelist_nodemask (zone, z, zonelist, ac->high_zoneidx, + ac->nodemask) {
This fixed order might bias some zones over others wrt unreserving. Is it OK?
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1622
Quoted 6 lines
mm/page_alloc.c +6
-0+/* Preserve at least one pageblock */ +if (zone->nr_reserved_highatomic <= pageblock_nr_pages) +continue ; + +spin_lock_irqsave (&zone->lock, flags); +for (order =0 ; order <MAX_ORDER ; order++) {
Would it make more sense to look in descending order for a higher chance of unreserving a pageblock that's mostly free? Like the traditional page stealing does?
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1632
Quoted 10 lines
mm/page_alloc.c +10
-0+struct free_area *area = &(zone->free_area[order]); + +if (list_empty (&area->free_list[MIGRATE_HIGHATOMIC ])) +continue ; + + page =list_entry (area->free_list[MIGRATE_HIGHATOMIC ].next, + struct page, lru); + + zone->nr_reserved_highatomic -= pageblock_nr_pages; +set_pageblock_migratetype (page, ac->migratetype);
Would it make more sense to assume MIGRATE_UNMOVABLE, as high-order allocations present in the pageblock typically would be, and apply the traditional page stealing heuristics to decide if it should be changed to ac->migratetype (if that differs)?
Quoted 77 lines
mm/page_alloc.c +25
-4+move_freepages_block (zone, page, ac->migratetype); +spin_unlock_irqrestore (&zone->lock, flags); +return ; + } +spin_unlock_irqrestore (&zone->lock, flags); + } +} +/* Remove an element from the buddy allocator from the fallback list */ static inline struct page *__rmqueue_fallback (struct zone *zone,unsigned int order,int start_migratetype)@@ -1619,15 +1689,26 @@ __rmqueue_fallback(struct zone *zone, unsigned int order, int start_migratetype)return NULL ; } +static inline bool gfp_mask_atomic (gfp_t gfp_mask) +{ +return !(gfp_mask & (__GFP_WAIT | __GFP_NO_KSWAPD)); +} +/* * Do the hard work of removing an element from the buddy allocator. * Call me with the zone->lock already held. */ static struct page *__rmqueue (struct zone *zone,unsigned int order, -int migratetype) +int migratetype,gfp_t gfp_flags) {struct page *page; +if (unlikely (order &&gfp_mask_atomic (gfp_flags))) { + page =__rmqueue_smallest (zone, order,MIGRATE_HIGHATOMIC ); +if (page) + goto out; + } + page =__rmqueue_smallest (zone, order, migratetype);if (unlikely (!page)) {if (migratetype ==MIGRATE_MOVABLE )@@ -1637,6 +1718,7 @@ static struct page *__rmqueue(struct zone *zone, unsigned int order, page =__rmqueue_fallback (zone, order, migratetype); } +out:trace_mm_page_alloc_zone_locked (page, order, migratetype);return page; }@@ -1654,7 +1736,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,spin_lock (&zone->lock);for (i =0 ; i < count; ++i) { -struct page *page =__rmqueue (zone, order, migratetype); +struct page *page =__rmqueue (zone, order, migratetype,0 );if (unlikely (page ==NULL ))break ;@@ -2065,7 +2147,7 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,WARN_ON_ONCE (order >1 ); }spin_lock_irqsave (&zone->lock, flags); - page =__rmqueue (zone, order, migratetype); + page =__rmqueue (zone, order, migratetype, gfp_flags);spin_unlock (&zone->lock);if (!page) goto failed;@@ -2175,15 +2257,23 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int classzone_idx, int alloc_flags, long free_pages) { - /* free_pages may go negative - that's OK */ long min = mark;int o;long free_cma =0 ; +/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ; +
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2275
Quoted 10 lines
mm/page_alloc.c +7
-1if (alloc_flags &ALLOC_HIGH ) min -= min /2 ; -if (alloc_flags &ALLOC_HARDER ) + +/* +* If the caller is not atomic then discount the reserves. This will +* over-estimate how the atomic reserve but it avoids a search +*/ +if (likely (!(alloc_flags &ALLOC_HARDER ))) + free_pages -= z->nr_reserved_highatomic;
Hm, so in the case the maximum of 10% reserved blocks is already full, we deny the allocation access to another 10% of the memory and push it to reclaim. This seems rather excessive.
Searching would of course suck, as would attempting to replicate the handling of NR_FREE_CMA_PAGES. Sigh.
Quoted 47 lines
mm/page_alloc.c +13
-2+else min -= min /4 ;#ifdef CONFIG_CMA @@ -2372,6 +2462,14 @@ try_this_zone:if (page) {if (prep_new_page (page, order, gfp_mask, alloc_flags)) goto try_this_zone; + +/* +* If this is a high-order atomic allocation then check +* if the pageblock should be reserved for the future +*/ +if (unlikely (order && (alloc_flags &ALLOC_HARDER ))) +reserve_highatomic_pageblock (page, zone, order); +return page; } }@@ -2639,9 +2737,11 @@ retry:/* * If an allocation failed after direct reclaim, it could be because -* pages are pinned on the per-cpu lists. Drain them and try again +* pages are pinned on the per-cpu lists or in high alloc reserves. +* Shrink them them and try again */ if (!page && !drained) { +unreserve_highatomic_pageblock (ac);drain_all_pages (NULL ); drained = true; goto retry;@@ -2686,7 +2786,7 @@ static inline int gfp_to_alloc_flags(gfp_t gfp_mask) {int alloc_flags =ALLOC_WMARK_MIN |ALLOC_CPUSET ; -const bool atomic = !(gfp_mask & (__GFP_WAIT | __GFP_NO_KSWAPD)); +const bool atomic =gfp_mask_atomic (gfp_mask);/* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */ BUILD_BUG_ON (__GFP_HIGH != (__force gfp_t )ALLOC_HIGH );mm/vmstat.c +0
-0
mm/vmstat.c static char * const migratetype_names[MIGRATE_TYPES] = { · line 907
Quoted 7 lines
mm/vmstat.c +1
-0@@ -901,6 +901,7 @@ static char * const migratetype_names[MIGRATE_TYPES] = {"Unmovable" ,"Reclaimable" ,"Movable" , +"HighAtomic" , #ifdef CONFIG_CMA "CMA", #endif
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 10 lines · Vlastimil Babka
Quoted 9 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.
Quoted 6 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.This looked weird, until I read the implementation and realized that "an allocation request" is limited to high-order atomic allocation requests.
Which is an important detail for understanding the patch, thanks.
Quoted 35 lines
Quoted 21 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
Signed-off-by Mel Gorman <[email protected]>[...]
Quoted 11 lines
mm/page_alloc.c +11
-0+/* +* Used when an allocation is about to fail under memory pressure. This +* potentially hurts the reliability of high-order allocations when under +* intense memory pressure but failed atomic allocations should be easier +* to recover from than an OOM. +*/ +static void unreserve_highatomic_pageblock (const struct alloc_context *ac) +{ +struct zonelist *zonelist = ac->zonelist; +unsigned long flags; +struct zoneref *z;
Quoted 8 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1616
Quoted 6 lines
mm/page_alloc.c +6
-0+struct zone *zone; +struct page *page; +int order; + +for_each_zone_zonelist_nodemask (zone, z, zonelist, ac->high_zoneidx, + ac->nodemask) {This fixed order might bias some zones over others wrt unreserving. Is it OK?
I could not think of a situation where it mattered. It'll always be preferring highest zone over lower zones. Allocation requests that can use any zone that do not care. Allocation requests that are limited to lower zones are protected as long as possible.
Quoted 11 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1622
Quoted 7 lines
mm/page_alloc.c +6
-0+/* Preserve at least one pageblock */ +if (zone->nr_reserved_highatomic <= pageblock_nr_pages) +continue ; + +spin_lock_irqsave (&zone->lock, flags); +for (order =0 ; order <MAX_ORDER ; order++) {Would it make more sense to look in descending order for a higher chance of unreserving a pageblock that's mostly free? Like the traditional page stealing does?
I don't think it's worth the search cost. Traditional page stealing is searching because it's trying to minimise events that cause external fragmentation. Here we'd gain very little. We are under some memory pressure here, if enough pages are not free then another one will get freed shortly. Either way, I doubt the difference is measurable.
Quoted 7 lines
Quoted 7 lines
mm/page_alloc.c +7
-0+struct free_area *area = &(zone->free_area[order]); + +if (list_empty (&area->free_list[MIGRATE_HIGHATOMIC ])) +continue ; + + page =list_entry (area->free_list[MIGRATE_HIGHATOMIC ].next, + struct page, lru);
Quoted 9 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1632
Quoted 3 lines
mm/page_alloc.c +3
-0+ + zone->nr_reserved_highatomic -= pageblock_nr_pages; +set_pageblock_migratetype (page, ac->migratetype);Would it make more sense to assume
MIGRATE_UNMOVABLE, as high-order allocations present in the pageblock typically would be, and apply the traditional page stealing heuristics to decide if it should be changed toac->migratetype(if that differs)?
Superb spot, I had to think about this for a while and initially I was thinking your suggestion was a no-brainer and obviously the right thing to do.
On the pro side, it preserves the fragmentation logic because it'll force the normal page stealing logic to be applied.
On the con side, we may reassign the pageblock twice -- once to MIGRATE_UNMOVABLE and once to ac->migratetype. That one does not matter but the second con is that we inadvertly increase the number of unmovable blocks in some cases.
Lets say we default to MIGRATE_UNMOVABLE, ac->migratetype is MIGRATE_MOVABLE and there are enough free pages to satisfy the allocation but not steal the whole pageblock. The end result is that we have a new unmovable pageblock that may not be necessary. The next unmovable allocation potentially is forever. They key observation is that previously the pageblock could have been short-lived high-order allocations that could be completely free soon if it was assigned MIGRATE_MOVABLE. This may not apply when SLUB is using high-order allocations but the point still holds.
Grouping pages by mobility really needs to strive to keep the number of unmovable blocks as low as possible. If ac->migratetype is MIGRATE_UNMOVABLE then we lose nothing. If it's any other type then the current code keeps the number of unmovable blocks as low as possible.
On that basis I think the current code is fine but it needs a comment to record why it's like this.
Quoted 18 lines
Quoted 18 lines
mm/page_alloc.c +5
-2@@ -2175,15 +2257,23 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int classzone_idx, int alloc_flags, long free_pages) { - /* free_pages may go negative - that's OK */ long min = mark;int o;long free_cma =0 ; +/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ; +if (alloc_flags &ALLOC_HIGH ) min -= min /2 ; -if (alloc_flags &ALLOC_HARDER ) + +/* +* If the caller is not atomic then discount the reserves. This will
Quoted 8 lines
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2275
Quoted 4 lines
mm/page_alloc.c +4
-0+* over-estimate how the atomic reserve but it avoids a search +*/ +if (likely (!(alloc_flags &ALLOC_HARDER ))) + free_pages -= z->nr_reserved_highatomic;Hm, so in the case the maximum of 10% reserved blocks is already full, we deny the allocation access to another 10% of the memory and push it to reclaim. This seems rather excessive.
It's necessary. If normal callers can use it then the reserve fills with normal pages, the memory gets fragmented and high-order atomic allocations fail due to fragmentation. Similarly, the number of MIGRATE_HIGHORDER pageblocks cannot be unbound or everything else will be continually pushed into reclaim even if there is plenty of memory free.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 22 lines · Mel Gorman
Quoted 12 lines · Vlastimil Babka
Quoted 11 lines · Mel Gorman
mm/page_alloc.c +11
-0+/* +* Used when an allocation is about to fail under memory pressure. This +* potentially hurts the reliability of high-order allocations when under +* intense memory pressure but failed atomic allocations should be easier +* to recover from than an OOM. +*/ +static void unreserve_highatomic_pageblock (const struct alloc_context *ac) +{ +struct zonelist *zonelist = ac->zonelist; +unsigned long flags; +struct zoneref *z;Quoted 8 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1616
Quoted 6 lines
mm/page_alloc.c +6
-0+struct zone *zone; +struct page *page; +int order; + +for_each_zone_zonelist_nodemask (zone, z, zonelist, ac->high_zoneidx, + ac->nodemask) {This fixed order might bias some zones over others wrt unreserving. Is it OK?
Quoted 4 lines
I could not think of a situation where it mattered. It'll always be preferring highest zone over lower zones. Allocation requests that can use any zone that do not care. Allocation requests that are limited to lower zones are protected as long as possible.
Hmm... allocation requests will follow fair zone policy and thus the highatomic reservations will be spread fairly among all zones? Unless the allocations require lower zones of course.
But for unreservations, normal/high allocations failing under memory pressure will lead to unreserving highatomic pageblocks first in the higher zones and only then the lower zones, and that was my concern. But it's true that failing allocations that require lower zones will lead to unreserving the lower zones, so it might be ok in the end.
Quoted 13 lines
Quoted 12 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1622
Quoted 8 lines
mm/page_alloc.c +6
-0+/* Preserve at least one pageblock */ +if (zone->nr_reserved_highatomic <= pageblock_nr_pages) +continue ; + +spin_lock_irqsave (&zone->lock, flags); +for (order =0 ; order <MAX_ORDER ; order++) {Would it make more sense to look in descending order for a higher chance of unreserving a pageblock that's mostly free? Like the traditional page stealing does?
Quoted 5 lines
I don't think it's worth the search cost. Traditional page stealing is searching because it's trying to minimise events that cause external fragmentation. Here we'd gain very little. We are under some memory pressure here, if enough pages are not free then another one will get freed shortly. Either way, I doubt the difference is measurable.
Hmm, I guess...
Quoted 30 lines
Quoted 17 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1632
Quoted 11 lines
mm/page_alloc.c +10
-0+struct free_area *area = &(zone->free_area[order]); + +if (list_empty (&area->free_list[MIGRATE_HIGHATOMIC ])) +continue ; + + page =list_entry (area->free_list[MIGRATE_HIGHATOMIC ].next, + struct page, lru); + + zone->nr_reserved_highatomic -= pageblock_nr_pages; +set_pageblock_migratetype (page, ac->migratetype);Would it make more sense to assume
MIGRATE_UNMOVABLE, as high-order allocations present in the pageblock typically would be, and apply the traditional page stealing heuristics to decide if it should be changed toac->migratetype(if that differs)?Superb spot, I had to think about this for a while and initially I was thinking your suggestion was a no-brainer and obviously the right thing to do.
On the pro side, it preserves the fragmentation logic because it'll force the normal page stealing logic to be applied.
On the con side, we may reassign the pageblock twice -- once to
MIGRATE_UNMOVABLEand once toac->migratetype. That one does not matter but the second con is that we inadvertly increase the number of unmovable blocks in some cases.
Quoted 9 lines
Lets say we default to
MIGRATE_UNMOVABLE,ac->migratetypeisMIGRATE_MOVABLEand there are enough free pages to satisfy the allocation but not steal the whole pageblock. The end result is that we have a new unmovable pageblock that may not be necessary. The next unmovable allocation potentially is forever. They key observation is that previously the pageblock could have been short-lived high-order allocations that could be completely free soon if it was assignedMIGRATE_MOVABLE. This may not apply when SLUB is using high-order allocations but the point still holds.
Yeah, I see the point. The obvious counterexample is a pageblock that we design as MOVABLE and yet it contains some long-lived unmovable allocation. More unmovable allocations could lead to choosing another movable block as a fallback, while if we marked this pageblock as unmovable, they could go here and not increase fragmentation.
The problem is, we can't known which one is the case. I've toyed with an idea of MIGRATE_MIXED blocks that would be for cases where the heuristics decide that e.g. an UNMOVABLE block is empty enough to change it to MOVABLE, but still it may contain some unmovable allocations. Such pageblocks should be preferred fallbacks for future unmovable allocations before truly pristine movable pageblocks.
The scenario here could be another where MIGRATE_MIXED would make sense.
Quoted 2 lines
Grouping pages by mobility really needs to strive to keep the number of unmovable blocks as low as possible.
More precisely, the number of blocks with unmovable allocations in them. Which is much harder objective.
Quoted 34 lines
If
ac->migratetypeisMIGRATE_UNMOVABLEthen we lose nothing. If it's any other type then the current code keeps the number of unmovable blocks as low as possible.On that basis I think the current code is fine but it needs a comment to record why it's like this.
Quoted 18 lines
Quoted 18 lines
mm/page_alloc.c +5
-2@@ -2175,15 +2257,23 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int classzone_idx, int alloc_flags, long free_pages) { - /* free_pages may go negative - that's OK */ long min = mark;int o;long free_cma =0 ; +/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ; +if (alloc_flags &ALLOC_HIGH ) min -= min /2 ; -if (alloc_flags &ALLOC_HARDER ) + +/* +* If the caller is not atomic then discount the reserves. This will Quoted 8 lines
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2275
Quoted 4 lines
mm/page_alloc.c +4
-0+* over-estimate how the atomic reserve but it avoids a search +*/ +if (likely (!(alloc_flags &ALLOC_HARDER ))) + free_pages -= z->nr_reserved_highatomic;Hm, so in the case the maximum of 10% reserved blocks is already full, we deny the allocation access to another 10% of the memory and push it to reclaim. This seems rather excessive.
Quoted 5 lines
It's necessary. If normal callers can use it then the reserve fills with normal pages, the memory gets fragmented and high-order atomic allocations fail due to fragmentation. Similarly, the number of
MIGRATE_HIGHORDERpageblocks cannot be unbound or everything else will be continually pushed into reclaim even if there is plenty of memory free.
I understand denying normal allocations access to highatomic reserves via watermarks is necessary. But my concern is that for each reserved pageblock we effectively deny up to two pageblocks-worth-of-pages to normal allocations. One pageblock that is marked as MIGRATE_HIGHATOMIC, and once it becomes full, free_pages above are decreased twice - once by the pageblock becoming full, and then again by subtracting z->nr_reserved_highatomic. This extra gap is still usable by highatomic allocations, but they will also potentially mark more pageblocks highatomic and further increase the gap. In the worst case we have 10% of pageblocks marked highatomic and full, and another 10% that is only usable by highatomic allocations (but won't be marked as such), and if no more highatomic allocations come then the 10% is wasted.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 23 lines · Vlastimil Babka
Quoted 22 lines · Mel Gorman
Quoted 20 lines · Vlastimil Babka
Quoted 7 lines · Mel Gorman
mm/page_alloc.c +7
-0+/* +* Used when an allocation is about to fail under memory pressure. This +* potentially hurts the reliability of high-order allocations when under +* intense memory pressure but failed atomic allocations should be easier +* to recover from than an OOM. +*/ +static void unreserve_highatomic_pageblock (const struct alloc_context *ac)mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1616
Quoted 10 lines
mm/page_alloc.c +10
-0+{ +struct zonelist *zonelist = ac->zonelist; +unsigned long flags; +struct zoneref *z; +struct zone *zone; +struct page *page; +int order; + +for_each_zone_zonelist_nodemask (zone, z, zonelist, ac->high_zoneidx, + ac->nodemask) {This fixed order might bias some zones over others wrt unreserving. Is it OK?
Quoted 9 lines
Quoted 4 lines
I could not think of a situation where it mattered. It'll always be preferring highest zone over lower zones. Allocation requests that can use any zone that do not care. Allocation requests that are limited to lower zones are protected as long as possible.
Hmm... allocation requests will follow fair zone policy and thus the highatomic reservations will be spread fairly among all zones? Unless the allocations require lower zones of course.
Does that matter?
Quoted 6 lines
But for unreservations, normal/high allocations failing under memory pressure will lead to unreserving highatomic pageblocks first in the higher zones and only then the lower zones, and that was my concern. But it's true that failing allocations that require lower zones will lead to unreserving the lower zones, so it might be ok in the end.
Again, I don't think it matters.
Quoted 67 lines
Quoted 13 lines
Quoted 12 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1622
Quoted 8 lines
mm/page_alloc.c +6
-0+/* Preserve at least one pageblock */ +if (zone->nr_reserved_highatomic <= pageblock_nr_pages) +continue ; + +spin_lock_irqsave (&zone->lock, flags); +for (order =0 ; order <MAX_ORDER ; order++) {Would it make more sense to look in descending order for a higher chance of unreserving a pageblock that's mostly free? Like the traditional page stealing does?
Quoted 5 lines
I don't think it's worth the search cost. Traditional page stealing is searching because it's trying to minimise events that cause external fragmentation. Here we'd gain very little. We are under some memory pressure here, if enough pages are not free then another one will get freed shortly. Either way, I doubt the difference is measurable.
Hmm, I guess...
Quoted 30 lines
Quoted 17 lines
mm/page_alloc.c int find_suitable_fallback(struct free_area *area, unsigned int order, · line 1632
Quoted 11 lines
mm/page_alloc.c +10
-0+struct free_area *area = &(zone->free_area[order]); + +if (list_empty (&area->free_list[MIGRATE_HIGHATOMIC ])) +continue ; + + page =list_entry (area->free_list[MIGRATE_HIGHATOMIC ].next, + struct page, lru); + + zone->nr_reserved_highatomic -= pageblock_nr_pages; +set_pageblock_migratetype (page, ac->migratetype);Would it make more sense to assume
MIGRATE_UNMOVABLE, as high-order allocations present in the pageblock typically would be, and apply the traditional page stealing heuristics to decide if it should be changed toac->migratetype(if that differs)?Superb spot, I had to think about this for a while and initially I was thinking your suggestion was a no-brainer and obviously the right thing to do.
On the pro side, it preserves the fragmentation logic because it'll force the normal page stealing logic to be applied.
On the con side, we may reassign the pageblock twice -- once to
MIGRATE_UNMOVABLEand once toac->migratetype. That one does not matter but the second con is that we inadvertly increase the number of unmovable blocks in some cases.Quoted 9 lines
Lets say we default to
MIGRATE_UNMOVABLE,ac->migratetypeisMIGRATE_MOVABLEand there are enough free pages to satisfy the allocation but not steal the whole pageblock. The end result is that we have a new unmovable pageblock that may not be necessary. The next unmovable allocation potentially is forever. They key observation is that previously the pageblock could have been short-lived high-order allocations that could be completely free soon if it was assignedMIGRATE_MOVABLE. This may not apply when SLUB is using high-order allocations but the point still holds.Yeah, I see the point. The obvious counterexample is a pageblock that we design as MOVABLE and yet it contains some long-lived unmovable allocation. More unmovable allocations could lead to choosing another movable block as a fallback, while if we marked this pageblock as unmovable, they could go here and not increase fragmentation.
Quoted 7 lines
The problem is, we can't known which one is the case. I've toyed with an idea of
MIGRATE_MIXEDblocks that would be for cases where the heuristics decide that e.g. an UNMOVABLE block is empty enough to change it to MOVABLE, but still it may contain some unmovable allocations. Such pageblocks should be preferred fallbacks for future unmovable allocations before truly pristine movable pageblocks.
I tried that once upon a time. The number of blocks simply increased over time and there was no sensible way to recover from it. I never found a solution that worked for very long.
Quoted 18 lines
Quoted 12 lines
Quoted 11 lines
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2275
Quoted 7 lines
mm/page_alloc.c +7
-0+ +/* +* If the caller is not atomic then discount the reserves. This will +* over-estimate how the atomic reserve but it avoids a search +*/ +if (likely (!(alloc_flags &ALLOC_HARDER ))) + free_pages -= z->nr_reserved_highatomic;Hm, so in the case the maximum of 10% reserved blocks is already full, we deny the allocation access to another 10% of the memory and push it to reclaim. This seems rather excessive.
Quoted 5 lines
It's necessary. If normal callers can use it then the reserve fills with normal pages, the memory gets fragmented and high-order atomic allocations fail due to fragmentation. Similarly, the number of
MIGRATE_HIGHORDERpageblocks cannot be unbound or everything else will be continually pushed into reclaim even if there is plenty of memory free.
Quoted 12 lines
I understand denying normal allocations access to highatomic reserves via watermarks is necessary. But my concern is that for each reserved pageblock we effectively deny up to two pageblocks-worth-of-pages to normal allocations. One pageblock that is marked as
MIGRATE_HIGHATOMIC, and once it becomes full,free_pagesabove are decreased twice - once by the pageblock becoming full, and then again by subtractingz->nr_reserved_highatomic. This extra gap is still usable by highatomic allocations, but they will also potentially mark more pageblocks highatomic and further increase the gap. In the worst case we have 10% of pageblocks marked highatomic and full, and another 10% that is only usable by highatomic allocations (but won't be marked as such), and if no more highatomic allocations come then the 10% is wasted.
Similar to what I said to Joosoo, I'll drop the size of the reserves in the next revision. It brings things back in line with MIGRATE_RESERVE in terms of the amount of memory we reserve while still removing the need for high-order watermark checks. It means that the rate of atomic high-order allocation failure will remain the same after the series as before but that should not matter.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
In reply to Mel GormanHello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.
I have some concerns on this patch.
1) This patch breaks intention of __GFP_WAIT.__GFP_WAIT is used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock for MIGRATE_HIGHATOMIC makes atomic allocation (~__GFP_WAIT) more successful than allocation with __GFP_WAIT in many situation. It breaks basic assumption of gfp flags and doesn't make any sense.
2) Who care about success of high-order atomic allocation with this reliability?
In case of allocation without __GFP_WAIT, requestor preare sufficient fallback method. They just want to success if it is easily successful. They don't want to succeed allocation with paying great cost that slow down general workload by this patch that can be accidentally reserve too much memory.
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.
When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 6 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
Quoted 6 lines
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.
There is some missing information to justify benchmark result. Especially, I'd like to know:
1) Detailed system setup (CPU, MEMORY, etc...)
2) Total number of attempt of GFP_ATOMIC allocation request
I don't know how you modify stutter benchmark in mmtests but it looks like there is no delay when continually requesting GFP_ATOMIC allocation. 1G of order-3 allocation request without delay seems insane to me. Could you tell me how you modify that benchmark for this patch?
Quoted 6 lines
There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
I don't think this is theoritical side-effects. It can happen easily. Recently, network subsystem makes some of their high-order allocation request ~_GFP_WAIT (fb05e7a89f50: net: don't wait for order-3 page allocation). And, I've submitted similar patch for slub today (mm/slub: don't wait for high-order page allocation). That makes system atomic high-order allocation request more and this side-effect can be possible in many situation.
Thanks.
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 14 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
Quoted 8 lines
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.
Currently allocation requests that do not specify __GFP_WAIT get the ALLOC_HARDER flag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.
Quoted 2 lines
2) Who care about success of high-order atomic allocation with this reliability?
Historically network configurations with large MTUs that could not scatter gather. These days network will also attempt atomic order-3 allocations to reduce overhead. SLUB also attempts atomic high-order allocations to reduce overhead. It's why MIGRATE_RESERVE exists at all so the intent of the patch is to preserve what MIGRATE_RESERVE was for but do it better.
Quoted 6 lines
In case of allocation without
__GFP_WAIT, requestor preare sufficient fallback method. They just want to success if it is easily successful. They don't want to succeed allocation with paying great cost that slow down general workload by this patch that can be accidentally reserve too much memory.
Not necessary true. In the historical case, the network request was atomic because it was from IRQ context and could not sleep.
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
Quoted 13 lines
Quoted 6 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
Quoted 6 lines
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.
Quoted 4 lines
There is some missing information to justify benchmark result. Especially, I'd like to know:
1) Detailed system setup (CPU, MEMORY, etc...)
CPUs were 8 core Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz with 8G of RAM.
Quoted 2 lines
2) Total number of attempt of
GFP_ATOMICallocation request
Each attempt was between 1 and 1G randomly as described already.
Quoted 6 lines
I don't know how you modify stutter benchmark in mmtests but it looks like there is no delay when continually requesting
GFP_ATOMICallocation.
1G of order-3 allocation request without delay seems insane to me. Could you tell me how you modify that benchmark for this patch?
The stutter benchmark was not modified. The watch-stress-highorder-atomic monitor was run in parallel and that's what is doing the allocation. It's true that up to 1G of order-3 allocations without delay would be insane in a normal situation. The point was to show an extreme case where atomic allocations were used and to test whether the reserves held up or not.
Quoted 7 lines
Quoted 6 lines
There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
Quoted 8 lines
I don't think this is theoritical side-effects. It can happen easily. Recently, network subsystem makes some of their high-order allocation request ~_GFP_WAIT (
fb05e7a89f50: net: don't wait for order-3 page allocation). And, I've submitted similar patch for slub today (mm/slub: don't wait for high-order page allocation). That makes system atomic high-order allocation request more and this side-effect can be possible in many situation.
The key is long-lived allocations. The network subsystem frees theirs. I was not able to trigger a situation in a variety of workloads where these happened which is why I classified it as theoritical.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 24 lines · Mel Gorman
Quoted 14 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
Quoted 8 lines
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.
Quoted 4 lines
Currently allocation requests that do not specify
__GFP_WAITget theALLOC_HARDERflag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.
I think (and said so before elsewhere) is that the problem is that we don't currently distinguish allocations that can't wait (=are really atomic and have no order-0 fallback) and allocations that just don't want to wait (=they have fallbacks). The second ones should obviously not access the current ALLOC_HARDER watermark-based reserves nor the proposed highatomic reserves.
Well we do look at __GFP_NO_KSWAPD flag to treat allocation as non-atomic, so that covers THP allocations and two drivers. But the recent networking commit fb05e7a89f50 didn't add the flag and nor does Joonsoo's slub patch use it. Either we should rename the flag and employ it where appropriate, or agree that access to reserves is orthogonal concern to waking up kswapd, and distinguish non-atomic non-__GFP_WAIT allocations differently.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 5 lines
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
It's however true that many of the "any pages free in that block" may be order-0, so they both won't be useful to high-order atomic allocations, and won't be available to other allocations, so they might remain unused.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 30 lines · Vlastimil Babka
Quoted 24 lines · Mel Gorman
Quoted 14 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
Quoted 8 lines
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.Quoted 4 lines
Currently allocation requests that do not specify
__GFP_WAITget theALLOC_HARDERflag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.
Quoted 7 lines
I think (and said so before elsewhere) is that the problem is that we don't currently distinguish allocations that can't wait (=are really atomic and have no order-0 fallback) and allocations that just don't want to wait (=they have fallbacks). The second ones should obviously not access the current
ALLOC_HARDERwatermark-based reserves nor the proposed highatomic reserves.
It's a separate issue though. There are a number of cases
1. can't wait because a spinlock is held or in interrupt
2. does not want to wait because a fallback option is available
3. does not want to wait or wake kswapd because a fallback option is available
4. should not fail as it would cause major difficulties
5. cannot fail because it's a functional failure
5 is never meant to occur might be the situation on embedded platforms. If this is the case then they should consider modifying MIGRATE_HIGHATOMIC in this patch series but I don't think it belongs in mainline as it has other consequences. 1-4 are a separate series.
Right now, this series does not drastically alter the concept that in some cases atomic allocations will succeed without delay when a !atomic allocation would have to reclaim.
There is certainly value to ironing out 1-4 on top and teaching SLUB, THP and networking the distinction.
Quoted 7 lines
Well we do look at
__GFP_NO_KSWAPDflag to treat allocation as non-atomic, so that covers THP allocations and two drivers. But the recent networking commitfb05e7a89f50didn't add the flag and nor does Joonsoo's slub patch use it. Either we should rename the flag and employ it where appropriate, or agree that access to reserves is orthogonal concern to waking up kswapd, and distinguish non-atomic non-__GFP_WAIT allocations differently.
Separate problem with a separate series. This one is about removing the zonelist cache due to complexity and removing an odd anomaly where allocations can fail due to how watermarks are calculated.
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 5 lines
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
Quoted 3 lines
It's however true that many of the "any pages free in that block" may be order-0, so they both won't be useful to high-order atomic allocations, and won't be available to other allocations, so they might remain unused.
I typoed lightly and missed a letter but the same outcome applies when slightly corrected -- any pages that are *freed* in that block stay free if it merges with buddies for use by high-order atomic allocations.
or else, the number of pageblocks will increase again until the 10%
limit is hit.
If the limit is hit and we are still failing then it's no different to what can happen today except it took a lot longer and was a lot harder to trigger. As the changelog pointed out, with this approach the allocation failure rate was massively reduced but not eliminated.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
In reply to Vlastimil BabkaQuoted 30 lines · Vlastimil Babka
Quoted 24 lines · Mel Gorman
Quoted 14 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
Quoted 8 lines
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.Quoted 4 lines
Currently allocation requests that do not specify
__GFP_WAITget theALLOC_HARDERflag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.
Quoted 6 lines
I think (and said so before elsewhere) is that the problem is that we don't currently distinguish allocations that can't wait (=are really atomic and have no order-0 fallback) and allocations that just don't want to wait (=they have fallbacks). The second ones should obviously not access the current
ALLOC_HARDERwatermark-based reserves nor the proposed highatomic reserves.
Yes, I agree. If we distinguish such cases, I'm not sure that this kinds of reservation is needed. It is better that atomic high-order allocation in IRQ context should prepare their own fallback such as reserving memory or low-order allocation.
Quoted 23 lines
Well we do look at
__GFP_NO_KSWAPDflag to treat allocation as non-atomic, so that covers THP allocations and two drivers. But the recent networking commitfb05e7a89f50didn't add the flag and nor does Joonsoo's slub patch use it. Either we should rename the flag and employ it where appropriate, or agree that access to reserves is orthogonal concern to waking up kswapd, and distinguish non-atomic non-__GFP_WAIT allocations differently.Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 5 lines
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
Quoted 4 lines
It's however true that many of the "any pages free in that block" may be order-0, so they both won't be useful to high-order atomic allocations, and won't be available to other allocations, so they might remain unused.
Agreed.
Thanks.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
In reply to Mel GormanQuoted 24 lines · Mel Gorman
Quoted 14 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
Quoted 8 lines
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.
Quoted 4 lines
Currently allocation requests that do not specify
__GFP_WAITget theALLOC_HARDERflag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.
I know that. It's matter of magnitute. If your patch is applied, GFP_ATOMIC almost succeed and there is no merit to use GFP_WAIT. If user can easily bypass big overhead from reclaim/compaction through GFP_ATOMIC allocation, they will decide to use GFP_ATOMIC flag rather than adding GFP_WAIT.
Quoted 9 lines
Quoted 3 lines
2) Who care about success of high-order atomic allocation with this reliability?
Historically network configurations with large MTUs that could not scatter gather. These days network will also attempt atomic order-3 allocations to reduce overhead. SLUB also attempts atomic high-order allocations to reduce overhead. It's why
MIGRATE_RESERVEexists at all so the intent of the patch is to preserve whatMIGRATE_RESERVEwas for but do it better.
Normally, SLUB doesn't rely on success of high-order allocation. So, don't need to such reliability. It can fallback to low-order allocation. Moreover, we can get such benefit of high-order allocation by using kcompactd as suggested by Vlastimil soon.
Quoted 9 lines
Quoted 6 lines
In case of allocation without
__GFP_WAIT, requestor preare sufficient fallback method. They just want to success if it is easily successful. They don't want to succeed allocation with paying great cost that slow down general workload by this patch that can be accidentally reserve too much memory.Not necessary true. In the historical case, the network request was atomic because it was from IRQ context and could not sleep.
If some of atomic high-order allocation requestor rely on success of atomic high-order allocation, they should be changed as reserving how much they need. Not, here MM. MM can't do anything if allocation is requested in IRQ context. Reserving a lot of memory to guarantee them doesn't make sense. And, I don't see any recent claim to guarantee such allocation more reliable.
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 5 lines
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
It really depends on luck.
Quoted 16 lines
Quoted 16 lines
Quoted 6 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
Quoted 6 lines
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.There is some missing information to justify benchmark result. Especially, I'd like to know:
Quoted 8 lines
Quoted 1 line
1) Detailed system setup (CPU, MEMORY, etc...)
CPUs were 8 core Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz with 8G of RAM.
Quoted 2 lines
2) Total number of attempt of
GFP_ATOMICallocation requestEach attempt was between 1 and 1G randomly as described already.
So, number of attempt was randomly choosen, but, number of failure is static. Please describe same level of statistics. Am I missing something?
Quoted 7 lines
Quoted 6 lines
I don't know how you modify stutter benchmark in mmtests but it looks like there is no delay when continually requesting
GFP_ATOMICallocation.
1G of order-3 allocation request without delay seems insane to me. Could you tell me how you modify that benchmark for this patch?
Quoted 5 lines
The stutter benchmark was not modified. The watch-stress-highorder-atomic monitor was run in parallel and that's what is doing the allocation. It's true that up to 1G of order-3 allocations without delay would be insane in a normal situation. The point was to show an extreme case where atomic allocations were used and to test whether the reserves held up or not.
You may change MAX_BURST in stap script to certain value that 1G successive attemtps is possible. 1G of order-3 atomic allocation without delay isn't really helpful benchmark, because it really doesn't reflect any real world situation. Even if extreme case, it should reflect real world situation at some point.
If number of successive attemtps is back to the realistic value, such large failure happens?
Quoted 18 lines
Quoted 9 lines
Quoted 8 lines
There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
Quoted 8 lines
I don't think this is theoritical side-effects. It can happen easily. Recently, network subsystem makes some of their high-order allocation request ~_GFP_WAIT (
fb05e7a89f50: net: don't wait for order-3 page allocation). And, I've submitted similar patch for slub today (mm/slub: don't wait for high-order page allocation). That makes system atomic high-order allocation request more and this side-effect can be possible in many situation.
Quoted 3 lines
The key is long-lived allocations. The network subsystem frees theirs. I was not able to trigger a situation in a variety of workloads where these happened which is why I classified it as theoritical.
SLUB allocation would be long-lived.
Thanks.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 09/10] mm, page_alloc: Reserve pageblocks for high-order atomic allocations on demand
Quoted 25 lines · Joonsoo Kim
Quoted 24 lines · Mel Gorman
Quoted 22 lines · Joonsoo Kim
Hello, Mel.
Quoted 8 lines · Mel Gorman
From: Mel Gorman <[email protected]>
High-order watermark checking exists for two reasons -- kswapd high-order awareness and protection for high-order atomic requests. Historically we depended on
MIGRATE_RESERVEto preservemin_free_kbytesas high-order free pages for as long as possible. This patch introducesMIGRATE_HIGHATOMICthat reserves pageblocks for high-order atomic allocations. This is expected to be more reliable thanMIGRATE_RESERVEwas.I have some concerns on this patch.
1) This patch breaks intention of
__GFP_WAIT.__GFP_WAITis used when we want to succeed allocation even if we need to do some reclaim/compaction work. That implies importance of allocation success. But, reserved pageblock forMIGRATE_HIGHATOMICmakes atomic allocation (~__GFP_WAIT) more successful than allocation with__GFP_WAITin many situation. It breaks basic assumption of gfp flags and doesn't make any sense.
Quoted 7 lines
Quoted 4 lines
Currently allocation requests that do not specify
__GFP_WAITget theALLOC_HARDERflag which allows them to dip further into watermark reserves. It already is the case that there are corner cases where a high atomic allocation can succeed when a non-atomic allocation would reclaim.I know that. It's matter of magnitute. If your patch is applied,
GFP_ATOMICalmost succeed and there is no merit to useGFP_WAIT.
Yes there is. If the reserves are too high then it will unnecessarily push order-0 allocations into reclaim. The use for atomic should be just that, atomic.
Quoted 4 lines
If user can easily bypass big overhead from reclaim/compaction through
GFP_ATOMICallocation, they will decide to useGFP_ATOMICflag rather than addingGFP_WAIT.
They overhead cannot be avoided, they simply hit failure instead. If the degree of magnitude is a problem then I can drop the reseserves from 10% to 1% so it's closer to what MIGRATE_RESERVE does today.
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
2) Who care about success of high-order atomic allocation with this reliability?
Historically network configurations with large MTUs that could not scatter gather. These days network will also attempt atomic order-3 allocations to reduce overhead. SLUB also attempts atomic high-order allocations to reduce overhead. It's why
MIGRATE_RESERVEexists at all so the intent of the patch is to preserve whatMIGRATE_RESERVEwas for but do it better.
Quoted 5 lines
Normally, SLUB doesn't rely on success of high-order allocation. So, don't need to such reliability. It can fallback to low-order allocation. Moreover, we can get such benefit of high-order allocation by using kcompactd as suggested by Vlastimil soon.
Then dropping maximum reserves to 1%. Or replicate what MIGRATE_RESERVE does and limit it to 2 pageblocks per zone.
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
In case of allocation without
__GFP_WAIT, requestor preare sufficient fallback method. They just want to success if it is easily successful. They don't want to succeed allocation with paying great cost that slow down general workload by this patch that can be accidentally reserve too much memory.Not necessary true. In the historical case, the network request was atomic because it was from IRQ context and could not sleep.
Quoted 7 lines
If some of atomic high-order allocation requestor rely on success of atomic high-order allocation, they should be changed as reserving how much they need. Not, here MM. MM can't do anything if allocation is requested in IRQ context. Reserving a lot of memory to guarantee them doesn't make sense. And, I don't see any recent claim to guarantee such allocation more reliable.
Ok, will limit to 2 pageblocks per zone on the next revision.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
A
MIGRATE_HIGHORDERpageblock is created when an allocation request steals a pageblock but limits the total number to 10% of the zone.When steals happens, pageblock already can be fragmented and we can't fully utilize this pageblock without allowing order-0 allocation. This is very waste.
Quoted 8 lines
Quoted 5 lines
If the pageblock was stolen, it implies there was at least 1 usable page of the correct order. As the pageblock is then reserved, any pages that free in that block stay free for use by high-order atomic allocations. Else, the number of pageblocks will increase again until the 10% limit is hit.
It really depends on luck.
Success of high-order allocations *always* depended on the allocation/free request stream. The series does not change that.
Quoted 20 lines
Quoted 20 lines
Quoted 13 lines
Quoted 6 lines
The pageblocks are unreserved if an allocation fails after a direct reclaim attempt.
The watermark checks account for the reserved pageblocks when the allocation request is not a high-order atomic allocation.
Quoted 6 lines
The stutter benchmark was used to evaluate this but while it was running there was a systemtap script that randomly allocated between 1 and 1G worth of order-3 pages using
GFP_ATOMIC. In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With this patch applied there were 28798 failures -- a 92% reduction. On a 4-node machine, allocation failures went from 76917 to 0 failures.Quoted 4 lines
There is some missing information to justify benchmark result. Especially, I'd like to know:
1) Detailed system setup (CPU, MEMORY, etc...)
CPUs were 8 core Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz with 8G of RAM.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
2) Total number of attempt of
GFP_ATOMICallocation requestEach attempt was between 1 and 1G randomly as described already.
So, number of attempt was randomly choosen, but, number of failure is static. Please describe same level of statistics. Am I missing something?
I reported the number of failures relative to the number of successful attempts. Reporting in greater detail would not help in any way because it'd be for one specific case. The experiences for other workloads will always be different. I'll put it another way -- what would you consider to be a meaningful test? Obviously you have something in mind.
The intent of what I did was to create a workload that is known to cause fragmentation and combine it with an unreasonable stream of atomic high-order allocations to stress the worst-case. The average case is unknowable because it depends on the workload and the requirements of the hardware.
Quoted 13 lines
Quoted 7 lines
Quoted 6 lines
I don't know how you modify stutter benchmark in mmtests but it looks like there is no delay when continually requesting
GFP_ATOMICallocation.
1G of order-3 allocation request without delay seems insane to me. Could you tell me how you modify that benchmark for this patch?Quoted 5 lines
The stutter benchmark was not modified. The watch-stress-highorder-atomic monitor was run in parallel and that's what is doing the allocation. It's true that up to 1G of order-3 allocations without delay would be insane in a normal situation. The point was to show an extreme case where atomic allocations were used and to test whether the reserves held up or not.
Quoted 6 lines
You may change
MAX_BURSTin stap script to certain value that 1G successive attemtps is possible. 1G of order-3 atomic allocation without delay isn't really helpful benchmark, because it really doesn't reflect any real world situation. Even if extreme case, it should reflect real world situation at some point.
I did not claim it was a real world situation. It was the exteme case.
Quoted 3 lines
If number of successive attemtps is back to the realistic value, such large failure happens?
It entirely depends on what you mean by realistic. The requirements of embedded are entirely different to a standard server. This is why I evaluated a potential worse-case scenario -- massive storms of atomic high-order allocations.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 6 lines
There are minor theoritical side-effects. If the system is intensively making large numbers of long-lived high-order atomic allocations then there will be a lot of reserved pageblocks. This may push some workloads into reclaim until the number of reserved pageblocks is reduced again. This problem was not observed in reclaim intensive workloads but such workloads are also not atomic high-order intensive.
I don't think this is theoritical side-effects. It can happen easily. Recently, network subsystem makes some of their high-order allocation request ~_GFP_WAIT (
fb05e7a89f50: net: don't wait for order-3 page allocation). And, I've submitted similar patch for slub today (mm/slub: don't wait for high-order page allocation). That makes system atomic high-order allocation request more and this side-effect can be possible in many situation.
Quoted 6 lines
Quoted 3 lines
The key is long-lived allocations. The network subsystem frees theirs. I was not able to trigger a situation in a variety of workloads where these happened which is why I classified it as theoritical.
SLUB allocation would be long-lived.
Will drop reserves to 2 pageblocks per zone so.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 10/10 mm, page_alloc: Only enforce watermarks for order-0 allocations
In reply to Mel GormanFrom: Mel Gorman <[email protected]>
The primary purpose of watermarks is to ensure that reclaim can always make forward progress in PF_MEMALLOC context (kswapd and direct reclaim). These assume that order-0 allocations are all that is necessary for forward progress.
High-order watermarks serve a different purpose. Kswapd had no high-order awareness before they were introduced (https://lkml.org/lkml/2004/9/5/9).
This was particularly important when there were high-order atomic requests. The watermarks both gave kswapd awareness and made a reserve for those atomic requests.
There are two important side-effects of this. The most important is that a non-atomic high-order request can fail even though free pages are available and the order-0 watermarks are ok. The second is that high-order watermark checks are expensive as the free list counts up to the requested order must be examined.
With the introduction of MIGRATE_HIGHATOMIC it is no longer necessary to have high-order watermarks. Kswapd and compaction still need high-order awareness which is handled by checking that at least one suitable high-order page is free.
In kernel 4.2-rc1 running this workload on a single-node machine there were 339574 allocation failures. With HighAtomic reserves, it drops to 28798 failures. With this patch applied, it drops to 9567 failures -- a 98% reduction compared to the vanilla kernel or 67% in comparison to having high atomic reserves with watermark checking.
The one potential side-effect of this is that in a vanilla kernel, the watermark checks may have kept a free page for an atomic allocation. Now, we are 100% relying on the HighAtomic reserves and an early allocation to have allocated them. If the first high-order atomic allocation is after the system is already heavily fragmented then it'll fail.
--- mm/page_alloc.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
mm/page_alloc.c +24 -14
@@ -2250,8 +2250,10 @@ static inline bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)#endif /* CONFIG_FAIL_PAGE_ALLOC */ /* -* Return true if free pages are above 'mark'. This takes into account the order -* of the allocation. +* Return true if free base pages are above 'mark'. For high-order checks it +* will return true of the order-0 watermark is reached and there is at least +* one free page of a suitable size. Checking now avoids taking the zone lock +* to check in the allocation paths if no pages are free. */ static bool __zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark, int classzone_idx, int alloc_flags,
@@ -2259,7 +2261,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, {long min = mark;int o; -long free_cma =0 ; +const bool atomic = (alloc_flags &ALLOC_HARDER );/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ;
@@ -2271,7 +2273,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,* If the caller is not atomic then discount the reserves. This will * over-estimate how the atomic reserve but it avoids a search */ -if (likely (!(alloc_flags &ALLOC_HARDER ))) +if (likely (!atomic)) free_pages -= z->nr_reserved_highatomic;else min -= min /4 ;
@@ -2279,22 +2281,30 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,#ifdef CONFIG_CMA /* If allocation can't use CMA areas don't use free CMA pages */ if (!(alloc_flags &ALLOC_CMA )) - free_cma =zone_page_state (z,NR_FREE_CMA_PAGES ); + free_pages -=zone_page_state (z,NR_FREE_CMA_PAGES );#endif -if (free_pages - free_cma <= min + z->lowmem_reserve[classzone_idx]) +if (free_pages <= min + z->lowmem_reserve[classzone_idx])return false; -for (o =0 ; o < order; o++) { -/* At the next order, this order's pages become unavailable */ - free_pages -= z->free_area[o].nr_free << o; -/* Require fewer higher order pages to be free */ - min >>=1 ; +/* order-0 watermarks are ok */ +if (!order) +return true; + +/* Check at least one high-order page is free */ +for (o = order; o <MAX_ORDER ; o++) { +struct free_area *area = &z->free_area[o]; +int mt; + +if (atomic && area->nr_free) +return true; -if (free_pages <= min) -return false; +for (mt =0 ; mt <MIGRATE_PCPTYPES ; mt++) { +if (!list_empty (&area->free_list[mt])) +return true; + } } -return true; +return false; } bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
Signature · 7 lines
2.4.3 -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/10] mm, page_alloc: Only enforce watermarks for order-0 allocations
On 07/20/2015 10:00 AM, Mel Gorman wrote:
[...]
Quoted 38 lines
static bool __zone_watermark_ok(struct zone *z, unsigned int order,
mm/page_alloc.c +5
-9unsigned long mark, int classzone_idx, int alloc_flags,@@ -2259,7 +2261,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, {long min = mark;int o; -long free_cma =0 ; +const bool atomic = (alloc_flags &ALLOC_HARDER );/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ;@@ -2271,7 +2273,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,* If the caller is not atomic then discount the reserves. This will * over-estimate how the atomic reserve but it avoids a search */ -if (likely (!(alloc_flags &ALLOC_HARDER ))) +if (likely (!atomic)) free_pages -= z->nr_reserved_highatomic;else min -= min /4 ;@@ -2279,22 +2281,30 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,#ifdef CONFIG_CMA /* If allocation can't use CMA areas don't use free CMA pages */ if (!(alloc_flags &ALLOC_CMA )) - free_cma =zone_page_state (z,NR_FREE_CMA_PAGES ); + free_pages -=zone_page_state (z,NR_FREE_CMA_PAGES );#endif -if (free_pages - free_cma <= min + z->lowmem_reserve[classzone_idx]) +if (free_pages <= min + z->lowmem_reserve[classzone_idx])return false; -for (o =0 ; o < order; o++) { -/* At the next order, this order's pages become unavailable */ - free_pages -= z->free_area[o].nr_free << o; -/* Require fewer higher order pages to be free */ - min >>=1 ; +/* order-0 watermarks are ok */
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2300
Quoted 10 lines
mm/page_alloc.c +10
-0+if (!order) +return true; + +/* Check at least one high-order page is free */ +for (o = order; o <MAX_ORDER ; o++) { +struct free_area *area = &z->free_area[o]; +int mt; + +if (atomic && area->nr_free) +return true;
This may be a false positive due to MIGRATE_CMA or MIGRATE_ISOLATE pages being the only free ones. But maybe it doesn't matter that much?
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2305
Quoted 7 lines
mm/page_alloc.c +4
-2-if (free_pages <= min) -return false; +for (mt =0 ; mt <MIGRATE_PCPTYPES ; mt++) { +if (!list_empty (&area->free_list[mt])) +return true; + }
This may be a false negative for ALLOC_CMA allocations, if the only free pages are of MIGRATE_CMA. Arguably that's the worse case than a false positive?
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order,
Quoted 7 lines
mm/page_alloc.c +1
-1} -return true; +return false; } bool zone_watermark_ok(struct zone *z, unsigned int order, unsigned long mark,
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/10] mm, page_alloc: Only enforce watermarks for order-0 allocations
Quoted 39 lines · Vlastimil Babka
On 07/20/2015 10:00 AM, Mel Gorman wrote:
[...]
Quoted 35 lines
static bool __zone_watermark_ok(struct zone *z, unsigned int order,
mm/page_alloc.c +4
-7unsigned long mark, int classzone_idx, int alloc_flags,@@ -2259,7 +2261,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order, {long min = mark;int o; -long free_cma =0 ; +const bool atomic = (alloc_flags &ALLOC_HARDER );/* free_pages may go negative - that's OK */ free_pages -= (1 << order) -1 ;@@ -2271,7 +2273,7 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,* If the caller is not atomic then discount the reserves. This will * over-estimate how the atomic reserve but it avoids a search */ -if (likely (!(alloc_flags &ALLOC_HARDER ))) +if (likely (!atomic)) free_pages -= z->nr_reserved_highatomic;else min -= min /4 ;@@ -2279,22 +2281,30 @@ static bool __zone_watermark_ok(struct zone *z, unsigned int order,#ifdef CONFIG_CMA /* If allocation can't use CMA areas don't use free CMA pages */ if (!(alloc_flags &ALLOC_CMA )) - free_cma =zone_page_state (z,NR_FREE_CMA_PAGES ); + free_pages -=zone_page_state (z,NR_FREE_CMA_PAGES );#endif -if (free_pages - free_cma <= min + z->lowmem_reserve[classzone_idx]) +if (free_pages <= min + z->lowmem_reserve[classzone_idx])return false; -for (o =0 ; o < order; o++) { -/* At the next order, this order's pages become unavailable */ - free_pages -= z->free_area[o].nr_free << o;
Quoted 17 lines
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2300
Quoted 13 lines
mm/page_alloc.c +11
-2-/* Require fewer higher order pages to be free */ - min >>=1 ; +/* order-0 watermarks are ok */ +if (!order) +return true; + +/* Check at least one high-order page is free */ +for (o = order; o <MAX_ORDER ; o++) { +struct free_area *area = &z->free_area[o]; +int mt; + +if (atomic && area->nr_free) +return true;This may be a false positive due to
MIGRATE_CMAorMIGRATE_ISOLATEpages being the only free ones. But maybe it doesn't matter that much?
I don't think it does. If it it's a false positive then a high-order atomic allocation may fail which is still meant to be a situation the caller can cope with.
For MIGRATE_ISOLATE, it's a transient situation.
If this can be demonstrated as a problem for users of CMA then it would be best to be certain there is a use case that requires more reliable high-order atomic allocations *and* CMA at the same time. Ordinarily, CMA users are also not atomic because they cannot migrate. If such an important use case can be identified then it's a one-liner patch and a changelog that adds
if (!IS_ENABLED(CONFIG_CMA) && atomic && area->nr_free)
Quoted 11 lines
mm/page_alloc.c static bool __zone_watermark_ok(struct zone *z, unsigned int order, · line 2305
Quoted 7 lines
mm/page_alloc.c +4
-2-if (free_pages <= min) -return false; +for (mt =0 ; mt <MIGRATE_PCPTYPES ; mt++) { +if (!list_empty (&area->free_list[mt])) +return true; + }This may be a false negative for
ALLOC_CMAallocations, if the only free pages are ofMIGRATE_CMA. Arguably that's the worse case than a false positive?
I also think this is unlikely that there are many high-order atomic allocations and CMA at the same time. If it's identified to be the case then CMA also needs to check the pageblock type inside when CONFIG_CMA is enabled. Again, it's something I would prefer to see that has a concrete use case first.
Signature · 2 lines
Mel Gorman SUSE Labs
Re: [PATCH 10/10] mm, page_alloc: Only enforce watermarks for order-0 allocations
In reply to Mel GormanQuoted 19 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The primary purpose of watermarks is to ensure that reclaim can always make forward progress in
PF_MEMALLOCcontext (kswapd and direct reclaim). These assume that order-0 allocations are all that is necessary for forward progress.High-order watermarks serve a different purpose. Kswapd had no high-order awareness before they were introduced (https://lkml.org/lkml/2004/9/5/9).
This was particularly important when there were high-order atomic requests. The watermarks both gave kswapd awareness and made a reserve for those atomic requests.There are two important side-effects of this. The most important is that a non-atomic high-order request can fail even though free pages are available and the order-0 watermarks are ok. The second is that high-order watermark checks are expensive as the free list counts up to the requested order must be examined.
Quoted 4 lines
With the introduction of
MIGRATE_HIGHATOMICit is no longer necessary to have high-order watermarks. Kswapd and compaction still need high-order awareness which is handled by checking that at least one suitable high-order page is free.
I totally agree removing watermark checking for order from PAGE_ALLOC_COSTLY_ORDER to MAX_ORDER. It doesn't make sense to maintain such high-order freepage that MM don't guarantee allocation success. For example, in my system, when there is 1 order-9 freepage, allocation request for order-9 fails because watermark check requires at least 2 order-9 freepages in order to succeed order-9 allocation.
But, I think watermark checking with order up to PAGE_ALLOC_COSTLY_ORDER is different. If we maintain just 1 high-order freepages, successive high-order allocation request that should be success always fall into allocation slow-path and go into the direct reclaim/compaction. It enlarges many workload's latency. We should prepare at least some number of freepage to handle successive high-order allocation request gracefully.
So, how about following?
1) kswapd checks watermark as is up to PAGE_ALLOC_COSTLY_ORDER. It guarantees kswapd prepares some number of high-order freepages so successive high-order allocation request will be handlded gracefully.
2) In case of !kswapd, just check whether appropriate freepage is in buddy or not.
Thanks.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/10] mm, page_alloc: Only enforce watermarks for order-0 allocations
Quoted 39 lines · Joonsoo Kim
Quoted 19 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The primary purpose of watermarks is to ensure that reclaim can always make forward progress in
PF_MEMALLOCcontext (kswapd and direct reclaim). These assume that order-0 allocations are all that is necessary for forward progress.High-order watermarks serve a different purpose. Kswapd had no high-order awareness before they were introduced (https://lkml.org/lkml/2004/9/5/9).
This was particularly important when there were high-order atomic requests. The watermarks both gave kswapd awareness and made a reserve for those atomic requests.There are two important side-effects of this. The most important is that a non-atomic high-order request can fail even though free pages are available and the order-0 watermarks are ok. The second is that high-order watermark checks are expensive as the free list counts up to the requested order must be examined.
Quoted 4 lines
With the introduction of
MIGRATE_HIGHATOMICit is no longer necessary to have high-order watermarks. Kswapd and compaction still need high-order awareness which is handled by checking that at least one suitable high-order page is free.I totally agree removing watermark checking for order from
PAGE_ALLOC_COSTLY_ORDERtoMAX_ORDER. It doesn't make sense to maintain such high-order freepage that MM don't guarantee allocation success. For example, in my system, when there is 1 order-9 freepage, allocation request for order-9 fails because watermark check requires at least 2 order-9 freepages in order to succeed order-9 allocation.But, I think watermark checking with order up to
PAGE_ALLOC_COSTLY_ORDERis different. If we maintain just 1 high-order freepages, successive high-order allocation request that should be success always fall into allocation slow-path and go into the direct reclaim/compaction. It enlarges many workload's latency. We should prepare at least some number of freepage to handle successive high-order allocation request gracefully.
Quoted 8 lines
So, how about following?
1) kswapd checks watermark as is up to
PAGE_ALLOC_COSTLY_ORDER. It guarantees kswapd prepares some number of high-order freepages so successive high-order allocation request will be handlded gracefully.
2) In case of !kswapd, just check whether appropriate freepage is in buddy or not.
If !atomic allocations use the high-order reserves then they'll fragment similarly to how they get fragmented today. It defeats the purpose of the reserve. I noted in the leader that embedded platforms may choose to carry an out-of-ftree patch that makes the reserves a kernel reserve for high-order pages but that I didn't think it was a good idea for mainline.
Your suggestion implies we have two watermark checks. The fast path which obeys watermarks in the traditional way. kswapd would use the same watermark check. The slow path would use the watermark check in this path. It is quite complex when historically it was expected that a !atomic high-order allocation request may take a long time. Furthermore, it's the case that kswapd gives up high-order reclaim requests very quickly because there were cases where a high-order request would cause kswapd to continually reclaim when the system was fragmented. I fear that your suggestion would partially reintroduce the problem in the name of trying to decrease the latency of a !atomic high-order allocation request that is expected to be expensive sometimes.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 10/10] mm, page_alloc: Only enforce watermarks for order-0 allocations
Quoted 49 lines · Mel Gorman
Quoted 39 lines · Joonsoo Kim
Quoted 19 lines · Mel Gorman
From: Mel Gorman <[email protected]>
The primary purpose of watermarks is to ensure that reclaim can always make forward progress in
PF_MEMALLOCcontext (kswapd and direct reclaim). These assume that order-0 allocations are all that is necessary for forward progress.High-order watermarks serve a different purpose. Kswapd had no high-order awareness before they were introduced (https://lkml.org/lkml/2004/9/5/9).
This was particularly important when there were high-order atomic requests. The watermarks both gave kswapd awareness and made a reserve for those atomic requests.There are two important side-effects of this. The most important is that a non-atomic high-order request can fail even though free pages are available and the order-0 watermarks are ok. The second is that high-order watermark checks are expensive as the free list counts up to the requested order must be examined.
Quoted 4 lines
With the introduction of
MIGRATE_HIGHATOMICit is no longer necessary to have high-order watermarks. Kswapd and compaction still need high-order awareness which is handled by checking that at least one suitable high-order page is free.I totally agree removing watermark checking for order from
PAGE_ALLOC_COSTLY_ORDERtoMAX_ORDER. It doesn't make sense to maintain such high-order freepage that MM don't guarantee allocation success. For example, in my system, when there is 1 order-9 freepage, allocation request for order-9 fails because watermark check requires at least 2 order-9 freepages in order to succeed order-9 allocation.But, I think watermark checking with order up to
PAGE_ALLOC_COSTLY_ORDERis different. If we maintain just 1 high-order freepages, successive high-order allocation request that should be success always fall into allocation slow-path and go into the direct reclaim/compaction. It enlarges many workload's latency. We should prepare at least some number of freepage to handle successive high-order allocation request gracefully.Quoted 8 lines
So, how about following?
1) kswapd checks watermark as is up to
PAGE_ALLOC_COSTLY_ORDER. It guarantees kswapd prepares some number of high-order freepages so successive high-order allocation request will be handlded gracefully.
2) In case of !kswapd, just check whether appropriate freepage is in buddy or not.
Quoted 5 lines
If !atomic allocations use the high-order reserves then they'll fragment similarly to how they get fragmented today. It defeats the purpose of the reserve. I noted in the leader that embedded platforms may choose to carry an out-of-ftree patch that makes the reserves a kernel reserve for high-order pages but that I didn't think it was a good idea for mainline.
I assume that your previous patch isn't merged. !atomic allocation can use reserve that kswapd makes in normal pageblock. That will fragment similarly as is, but, it isn't unsolvable problem. If compaction is enhanced, we don't need to worry about fragmentation as I experienced in embedded platform.
Quoted 6 lines
Your suggestion implies we have two watermark checks. The fast path which obeys watermarks in the traditional way. kswapd would use the same watermark check. The slow path would use the watermark check in this path. It is quite complex when historically it was expected that a !atomic high-order allocation request may take a long time. Furthermore,
Why quite complex? Watermark check already apply different threshold.
Quoted 6 lines
it's the case that kswapd gives up high-order reclaim requests very quickly because there were cases where a high-order request would cause kswapd to continually reclaim when the system was fragmented. I fear that your suggestion would partially reintroduce the problem in the name of trying to decrease the latency of a !atomic high-order allocation request that is expected to be expensive sometimes.
!atomic high-order allocation request is expected to be expensive sometimes, but, they don't want to be expensive. IMO, optimizing them is MM's duty.
Thanks.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Mel Gorman
From: Mel Gorman <[email protected]>
This series started with the idea to move LRU lists to pgdat but this part was more important to start with. It was written against 4.2-rc1 but applies to 4.2-rc3.
The zonelist cache has been around for a long time but it is of dubious merit with a lot of complexity. There are a few reasons why it needs help that are explained in the first patch but the most important is that a failed THP allocation can cause a zone to be treated as "full". This potentially causes unnecessary stalls, reclaim activity or remote fallbacks. Maybe the issues could be fixed but it's not worth it. The series places a small number of other micro-optimisations on top before examining watermarks.
Quoted 9 lines
High-order watermarks are something that can cause high-order allocations to fail even though pages are free. This was originally to protect high-order atomic allocations but there is a much better way that can be handled using migrate types. This series uses page grouping by mobility to preserve some pageblocks for high-order allocations with the size of the reservation depending on demand. kswapd awareness is maintained by examining the free lists. By patch 10 in this series, there are no high-order watermark checks while preserving the properties that motivated the introduction of the watermark checks.
I guess that removal of zonelist cache and high-order watermarks has different purpose and different set of reader. It is better to separate this two kinds of patches next time to help reviewer to see what they want to see.
Thanks.
--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 25 lines · Joonsoo Kim
Quoted 14 lines · Mel Gorman
From: Mel Gorman <[email protected]>
This series started with the idea to move LRU lists to pgdat but this part was more important to start with. It was written against 4.2-rc1 but applies to 4.2-rc3.
The zonelist cache has been around for a long time but it is of dubious merit with a lot of complexity. There are a few reasons why it needs help that are explained in the first patch but the most important is that a failed THP allocation can cause a zone to be treated as "full". This potentially causes unnecessary stalls, reclaim activity or remote fallbacks. Maybe the issues could be fixed but it's not worth it. The series places a small number of other micro-optimisations on top before examining watermarks.
Quoted 9 lines
High-order watermarks are something that can cause high-order allocations to fail even though pages are free. This was originally to protect high-order atomic allocations but there is a much better way that can be handled using migrate types. This series uses page grouping by mobility to preserve some pageblocks for high-order allocations with the size of the reservation depending on demand. kswapd awareness is maintained by examining the free lists. By patch 10 in this series, there are no high-order watermark checks while preserving the properties that motivated the introduction of the watermark checks.
Quoted 5 lines
I guess that removal of zonelist cache and high-order watermarks has different purpose and different set of reader. It is better to separate this two kinds of patches next time to help reviewer to see what they want to see.
One of the reasons zonelist existed was to avoid watermark checks in some case. The series also intends to reduce the cost of watermark checks in some cases which is why they are part of the same series. I'm not comfortable doing one without the other.
Signature · 8 lines
Mel Gorman SUSE Labs -- 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/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>