Skip to content

Commit 44042b4

Browse files
gormanmtorvalds
authored andcommitted
mm/page_alloc: allow high-order pages to be stored on the per-cpu lists
The per-cpu page allocator (PCP) only stores order-0 pages. This means that all THP and "cheap" high-order allocations including SLUB contends on the zone->lock. This patch extends the PCP allocator to store THP and "cheap" high-order pages. Note that struct per_cpu_pages increases in size to 256 bytes (4 cache lines) on x86-64. Note that this is not necessarily a universal performance win because of how it is implemented. High-order pages can cause pcp->high to be exceeded prematurely for lower-orders so for example, a large number of THP pages being freed could release order-0 pages from the PCP lists. Hence, much depends on the allocation/free pattern as observed by a single CPU to determine if caching helps or hurts a particular workload. That said, basic performance testing passed. The following is a netperf UDP_STREAM test which hits the relevant patches as some of the network allocations are high-order. netperf-udp 5.13.0-rc2 5.13.0-rc2 mm-pcpburst-v3r4 mm-pcphighorder-v1r7 Hmean send-64 261.46 ( 0.00%) 266.30 * 1.85%* Hmean send-128 516.35 ( 0.00%) 536.78 * 3.96%* Hmean send-256 1014.13 ( 0.00%) 1034.63 * 2.02%* Hmean send-1024 3907.65 ( 0.00%) 4046.11 * 3.54%* Hmean send-2048 7492.93 ( 0.00%) 7754.85 * 3.50%* Hmean send-3312 11410.04 ( 0.00%) 11772.32 * 3.18%* Hmean send-4096 13521.95 ( 0.00%) 13912.34 * 2.89%* Hmean send-8192 21660.50 ( 0.00%) 22730.72 * 4.94%* Hmean send-16384 31902.32 ( 0.00%) 32637.50 * 2.30%* Functionally, a patch like this is necessary to make bulk allocation of high-order pages work with similar performance to order-0 bulk allocations. The bulk allocator is not updated in this series as it would have to be determined by bulk allocation users how they want to track the order of pages allocated with the bulk allocator. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mel Gorman <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Zi Yan <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 43b02ba commit 44042b4

File tree

4 files changed

+144
-49
lines changed

4 files changed

+144
-49
lines changed

include/linux/mmzone.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ enum zone_watermarks {
333333
NR_WMARK
334334
};
335335

336+
/*
337+
* One per migratetype for each PAGE_ALLOC_COSTLY_ORDER plus one additional
338+
* for pageblock size for THP if configured.
339+
*/
340+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
341+
#define NR_PCP_THP 1
342+
#else
343+
#define NR_PCP_THP 0
344+
#endif
345+
#define NR_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1 + NR_PCP_THP))
346+
347+
/*
348+
* Shift to encode migratetype and order in the same integer, with order
349+
* in the least significant bits.
350+
*/
351+
#define NR_PCP_ORDER_WIDTH 8
352+
#define NR_PCP_ORDER_MASK ((1<<NR_PCP_ORDER_WIDTH) - 1)
353+
336354
#define min_wmark_pages(z) (z->_watermark[WMARK_MIN] + z->watermark_boost)
337355
#define low_wmark_pages(z) (z->_watermark[WMARK_LOW] + z->watermark_boost)
338356
#define high_wmark_pages(z) (z->_watermark[WMARK_HIGH] + z->watermark_boost)
@@ -349,7 +367,7 @@ struct per_cpu_pages {
349367
#endif
350368

351369
/* Lists of pages, one per migrate type stored on the pcp-lists */
352-
struct list_head lists[MIGRATE_PCPTYPES];
370+
struct list_head lists[NR_PCP_LISTS];
353371
};
354372

355373
struct per_cpu_zonestat {

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
203203
gfp_t gfp_flags);
204204
extern int user_min_free_kbytes;
205205

206-
extern void free_unref_page(struct page *page);
206+
extern void free_unref_page(struct page *page, unsigned int order);
207207
extern void free_unref_page_list(struct list_head *list);
208208

209209
extern void zone_pcp_update(struct zone *zone, int cpu_online);

0 commit comments

Comments
 (0)