Subject: do not display compaction-related stats when !CONFIG_COMPACTION From: Mel Gorman Although compaction can be disabled from .config, the vmstat entries still exist. This patch removes the vmstat entries. As page_alloc.c refers directly to the counters, the patch introduces __alloc_pages_direct_compact() to isolate use of the counters. Signed-off-by: Mel Gorman Cc: Minchan Kim Cc: KAMEZAWA Hiroyuki Cc: KOSAKI Motohiro Cc: Christoph Lameter Cc: Andrea Arcangeli Cc: Rik van Riel Signed-off-by: Andrew Morton --- diff -puN include/linux/vmstat.h~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction include/linux/vmstat.h --- a/include/linux/vmstat.h~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction +++ a/include/linux/vmstat.h @@ -43,8 +43,10 @@ enum vm_event_item { PGPGIN, PGPGOUT, PS KSWAPD_LOW_WMARK_HIT_QUICKLY, KSWAPD_HIGH_WMARK_HIT_QUICKLY, KSWAPD_SKIP_CONGESTION_WAIT, PAGEOUTRUN, ALLOCSTALL, PGROTATED, +#ifdef CONFIG_COMPACTION COMPACTBLOCKS, COMPACTPAGES, COMPACTPAGEFAILED, COMPACTSTALL, COMPACTFAIL, COMPACTSUCCESS, +#endif #ifdef CONFIG_HUGETLB_PAGE HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL, #endif diff -puN mm/page_alloc.c~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction mm/page_alloc.c --- a/mm/page_alloc.c~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction +++ a/mm/page_alloc.c @@ -1756,6 +1756,59 @@ out: return page; } +#ifdef CONFIG_COMPACTION +/* Try memory compaction for high-order allocations before reclaim */ +static struct page * +__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, + struct zonelist *zonelist, enum zone_type high_zoneidx, + nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone, + int migratetype, unsigned long *did_some_progress) +{ + struct page *page; + + if (!order) + return NULL; + + *did_some_progress = try_to_compact_pages(zonelist, order, gfp_mask, + nodemask); + if (*did_some_progress != COMPACT_SKIPPED) { + + /* Page migration frees to the PCP lists but we want merging */ + drain_pages(get_cpu()); + put_cpu(); + + page = get_page_from_freelist(gfp_mask, nodemask, + order, zonelist, high_zoneidx, + alloc_flags, preferred_zone, + migratetype); + if (page) { + __count_vm_event(COMPACTSUCCESS); + return page; + } + + /* + * It's bad if compaction run occurs and fails. + * The most likely reason is that pages exist, + * but not enough to satisfy watermarks. + */ + count_vm_event(COMPACTFAIL); + + cond_resched(); + } + + return NULL; +} +#else +static inline struct page * +__alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, + struct zonelist *zonelist, enum zone_type high_zoneidx, + nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone, + int migratetype, unsigned long *did_some_progress) +{ + return NULL; +} +#endif /* CONFIG_COMPACTION */ + /* The really slow allocator path where we enter direct reclaim */ static inline struct page * __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, @@ -1975,6 +2028,15 @@ rebalance: if (test_thread_flag(TIF_MEMDIE) && !(gfp_mask & __GFP_NOFAIL)) goto nopage; + /* Try direct compaction */ + page = __alloc_pages_direct_compact(gfp_mask, order, + zonelist, high_zoneidx, + nodemask, + alloc_flags, preferred_zone, + migratetype, &did_some_progress); + if (page) + goto got_pg; + /* Try direct reclaim and then allocating */ page = __alloc_pages_direct_reclaim(gfp_mask, order, zonelist, high_zoneidx, diff -puN mm/vmstat.c~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction mm/vmstat.c --- a/mm/vmstat.c~mm-compaction-do-not-display-compaction-related-stats-when-config_compaction +++ a/mm/vmstat.c @@ -902,12 +902,14 @@ static const char * const vmstat_text[] "pgrotated", +#ifdef CONFIG_COMPACTION "compact_blocks_moved", "compact_pages_moved", "compact_pagemigrate_failed", "compact_stall", "compact_fail", "compact_success", +#endif #ifdef CONFIG_HUGETLB_PAGE "htlb_buddy_alloc_success",