A few cleanup patches for mm
Subsystems (5)
v2 cover A few cleanup patches for mm
Hi everyone,
This series contains a few cleanup patches to remove the obsolete comments and functions, use helper macro to improve readability and so on. More details can be found in the respective changelogs. Thanks!
---
v2:
Thanks David, Oscar, Anshuman and Matthew for review and comment! Collect Reviewed-by and Acked-by tag.
3/6: Further remove NR_PCP_ORDER_WIDTH per Matthew. 8/16: Tweak changelog to better explain the issue per Oscar. 12/16: Adjust if block to match comment per David.
---
Miaohe Lin (16):
mm/page_alloc: ensure kswapd doesn't accidentally go to sleep mm/page_alloc: make zone_pcp_update() static
mm: remove obsolete macro NR_PCP_ORDER_MASK and NR_PCP_ORDER_WIDTH mm/page_alloc: remove obsolete comment in zone_statistics() mm/page_alloc: add __init annotations to
init_mem_debugging_and_hardening()
mm/page_alloc: fix freeing static percpu memory
mm: remove obsolete pgdat_is_empty()
mm/page_alloc: add missing is_migrate_isolate() check in
set_page_guard()
mm/page_alloc: use local variable zone_idx directly
mm, memory_hotplug: remove obsolete generic_free_nodedata() mm/page_alloc: make boot_nodestats static mm/page_alloc: use helper macro SZ_1{K,M} mm/page_alloc: init local variable buddy_pfn mm/page_alloc: use costly_order in WARN_ON_ONCE_GFP() mm/page_alloc: remove obsolete gfpflags_normal_context() mm/page_alloc: fix obsolete comment in deferred_pfn_valid()
include/linux/gfp.h | 23 ------------- include/linux/memory_hotplug.h | 8 ----- include/linux/mm.h | 2 +- include/linux/mmzone.h | 12 ------- mm/internal.h | 3 -- mm/page_alloc.c | 63 ++++++++++++++++------------------ 6 files changed, 31 insertions(+), 80 deletions(-)
Signature · 1 line
2.23.0
PATCH v2 1/16 mm/page_alloc: ensure kswapd doesn't accidentally go to sleep
If ALLOC_KSWAPD is set, wake_all_kswapds() will be called to ensure kswapd doesn't accidentally go to sleep. But when reserve_flags is set, alloc_flags will be overwritten and ALLOC_KSWAPD is thus lost. Preserve the ALLOC_KSWAPD flag in alloc_flags to ensure kswapd won't go to sleep accidentally.
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
@@ -5148,7 +5148,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, reserve_flags =__gfp_pfmemalloc_flags (gfp_mask);if (reserve_flags) - alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, reserve_flags); + alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, reserve_flags) | + (alloc_flags &ALLOC_KSWAPD );/* * Reset the nodemask and zonelist iterators if memory policies can be
Signature · 1 line
2.23.0
PATCH v2 2/16 mm/page_alloc: make zone_pcp_update() static
In reply to Miaohe LinSince commit b92ca18e8ca5 ("mm/page_alloc: disassociate the pcp->high from pcp->batch"), zone_pcp_update() is only used in mm/page_alloc.c. Move zone_pcp_update() up to avoid forward declaration and then make it static. No functional change intended.
--- mm/internal.h | 1 - mm/page_alloc.c | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-)
mm/internal.h +0 -1
@@ -367,7 +367,6 @@ extern int user_min_free_kbytes;extern void free_unref_page (struct page *page,unsigned int order);extern void free_unref_page_list (struct list_head *list); -extern void zone_pcp_update (struct zone *zone,int cpu_online);extern void zone_pcp_reset (struct zone *zone);extern void zone_pcp_disable (struct zone *zone);extern void zone_pcp_enable (struct zone *zone);
mm/page_alloc.c +11 -11
@@ -7234,6 +7234,17 @@ void __meminit setup_zone_pageset(struct zone *zone)zone_set_pageset_high_and_batch (zone,0 ); } +/* +* The zone indicated has a new number of managed_pages; batch sizes and percpu +* page high values need to be recalculated. +*/ +static void zone_pcp_update (struct zone *zone,int cpu_online) +{ +mutex_lock (&pcp_batch_high_lock); +zone_set_pageset_high_and_batch (zone, cpu_online); +mutex_unlock (&pcp_batch_high_lock); +} +/* * Allocate per cpu pagesets and initialize them. * Before this call only boot pagesets were available.
@@ -9465,17 +9476,6 @@ void free_contig_range(unsigned long pfn, unsigned long nr_pages) }EXPORT_SYMBOL (free_contig_range); -/* -* The zone indicated has a new number of managed_pages; batch sizes and percpu -* page high values need to be recalculated. -*/ -void zone_pcp_update (struct zone *zone,int cpu_online) -{ -mutex_lock (&pcp_batch_high_lock); -zone_set_pageset_high_and_batch (zone, cpu_online); -mutex_unlock (&pcp_batch_high_lock); -} -/* * Effectively disable pcplists for the zone by setting the high limit to 0 * and draining all cpus. A concurrent page freeing on another CPU that's about
Signature · 1 line
2.23.0
PATCH v2 3/16 mm: remove obsolete macro NR_PCP_ORDER_MASK and NR_PCP_ORDER_WIDTH
In reply to Miaohe LinSince commit 8b10b465d0e1 ("mm/page_alloc: free pages in a single pass during bulk free"), they're not used anymore. Remove them.
--- include/linux/mmzone.h | 7 ------- mm/page_alloc.c | 1 - 2 files changed, 8 deletions(-)
include/linux/mmzone.h +0 -7
@@ -564,13 +564,6 @@ enum zone_watermarks {#define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1))#define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP) -/* -* Shift to encode migratetype and order in the same integer, with order -* in the least significant bits. -*/ -#define NR_PCP_ORDER_WIDTH 8 -#define NR_PCP_ORDER_MASK ((1<<NR_PCP_ORDER_WIDTH) - 1) -#define min_wmark_pages (z) (z->_watermark[WMARK_MIN] + z->watermark_boost)#define low_wmark_pages (z) (z->_watermark[WMARK_LOW] + z->watermark_boost)#define high_wmark_pages (z) (z->_watermark[WMARK_HIGH] + z->watermark_boost)
mm/page_alloc.c +0 -1
@@ -1584,7 +1584,6 @@ static void free_pcppages_bulk(struct zone *zone, int count, order =pindex_to_order (pindex); nr_pages =1 << order; -BUILD_BUG_ON (MAX_ORDER >= (1 <<NR_PCP_ORDER_WIDTH )); do { int mt;
Signature · 1 line
2.23.0
PATCH v2 4/16 mm/page_alloc: remove obsolete comment in zone_statistics()
In reply to Miaohe LinSince commit 43c95bcc51e4 ("mm/page_alloc: reduce duration that IRQs are disabled for VM counters"), zone_statistics() is not called with interrupts disabled. Update the corresponding comment.
--- mm/page_alloc.c | 2 -- 1 file changed, 2 deletions(-)
mm/page_alloc.c +0 -2
@@ -3671,8 +3671,6 @@ void __putback_isolated_page(struct page *page, unsigned int order, int mt)/* * Update NUMA hit/miss statistics -* -* Must be called with interrupts disabled. */ static inline void zone_statistics (struct zone *preferred_zone,struct zone *z,long nr_account)
Signature · 1 line
2.23.0
PATCH v2 5/16 mm/page_alloc: add __init annotations to init_mem_debugging_and_hardening()
In reply to Miaohe LinIt's only called by mm_init(). Add __init annotations to it.
--- include/linux/mm.h | 2 +- mm/page_alloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/mm.h +1 -1
@@ -3093,7 +3093,7 @@ extern int apply_to_existing_page_range(struct mm_struct *mm, unsigned long address, unsigned long size, pte_fn_t fn, void *data); -extern void init_mem_debugging_and_hardening (void ); +extern void __init init_mem_debugging_and_hardening (void );#ifdef CONFIG_PAGE_POISONING extern void __kernel_poison_pages (struct page *page,int numpages);extern void __kernel_unpoison_pages (struct page *page,int numpages);
mm/page_alloc.c +1 -1
@@ -903,7 +903,7 @@ static inline void clear_page_guard(struct zone *zone, struct page *page,* order of appearance. So we need to first gather the full picture of what was * enabled, and then make decisions. */ -void init_mem_debugging_and_hardening (void ) +void __init init_mem_debugging_and_hardening (void ) {bool page_poisoning_requested = false;
Signature · 1 line
2.23.0
PATCH v2 6/16 mm/page_alloc: fix freeing static percpu memory
In reply to Miaohe LinThe size of struct per_cpu_zonestat can be 0 on !SMP && !NUMA. In that case, zone->per_cpu_zonestats will always equal to boot_zonestats. But in zone_pcp_reset(), zone->per_cpu_zonestats is freed via free_percpu() directly without checking against boot_zonestats first. boot_zonestats will be released by free_percpu() unexpectedly.
--- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
@@ -9505,9 +9505,11 @@ void zone_pcp_reset(struct zone *zone)drain_zonestat (zone, pzstats); }free_percpu (zone->per_cpu_pageset); -free_percpu (zone->per_cpu_zonestats); zone->per_cpu_pageset = &boot_pageset; - zone->per_cpu_zonestats = &boot_zonestats; +if (zone->per_cpu_zonestats != &boot_zonestats) { +free_percpu (zone->per_cpu_zonestats); + zone->per_cpu_zonestats = &boot_zonestats; + } } }
Signature · 1 line
2.23.0
PATCH v2 7/16 mm: remove obsolete pgdat_is_empty()
In reply to Miaohe LinThere's no caller. Remove it.
--- include/linux/mmzone.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/mmzone.h +0 -5
@@ -1241,11 +1241,6 @@ static inline unsigned long pgdat_end_pfn(pg_data_t *pgdat)return pgdat->node_start_pfn + pgdat->node_spanned_pages; } -static inline bool pgdat_is_empty (pg_data_t *pgdat) -{ -return !pgdat->node_start_pfn && !pgdat->node_spanned_pages; -} -#include <linux/memory_hotplug.h> void build_all_zonelists (pg_data_t *pgdat);
Signature · 1 line
2.23.0
PATCH v2 8/16 mm/page_alloc: add missing is_migrate_isolate() check in set_page_guard()
In reply to Miaohe LinIn MIGRATE_ISOLATE case, zone freepage state shouldn't be modified as caller will take care of it. Add missing is_migrate_isolate() here to avoid possible unbalanced freepage state. This would happen if someone isolates the block, and then we face an MCE failure/soft-offline on a page within that block. __mod_zone_freepage_state() will be triggered via below call trace which already had been triggered back when block was isolated:
take_page_off_buddy
break_down_buddy_pages
set_page_guard
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
@@ -873,7 +873,8 @@ static inline bool set_page_guard(struct zone *zone, struct page *page,INIT_LIST_HEAD (&page->buddy_list);set_page_private (page, order);/* Guard pages are not available for any usage */ -__mod_zone_freepage_state (zone, -(1 << order), migratetype); +if (!is_migrate_isolate (migratetype)) +__mod_zone_freepage_state (zone, -(1 << order), migratetype);return true; }
Signature · 1 line
2.23.0
Re: [PATCH v2 08/16] mm/page_alloc: add missing is_migrate_isolate() check in set_page_guard()
Quoted 8 lines · Miaohe Lin
In
MIGRATE_ISOLATEcase, zone freepage state shouldn't be modified as caller will take care of it. Add missingis_migrate_isolate()here to avoid possible unbalanced freepage state. This would happen if someone isolates the block, and then we face an MCE failure/soft-offline on a page within that block.__mod_zone_freepage_state()will be triggered via below call trace which already had been triggered back when block was isolated:
Quoted 8 lines
take_page_off_buddy
break_down_buddy_pages
set_page_guardFixes 06be6ff3d2ec ("mm,hwpoison: rework soft offline for free pages")Signed-off-by Miaohe Lin <[email protected]>Reviewed-by Oscar Salvador <[email protected]>---
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 9/16 mm/page_alloc: use local variable zone_idx directly
In reply to Miaohe LinUse local variable zone_idx directly since it holds the exact value of zone_idx(). No functional change intended.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -6873,7 +6873,7 @@ void __ref memmap_init_zone_device(struct zone *zone,unsigned long start = jiffies;int nid = pgdat->node_id; -if (WARN_ON_ONCE (!pgmap ||zone_idx (zone) !=ZONE_DEVICE )) +if (WARN_ON_ONCE (!pgmap || zone_idx !=ZONE_DEVICE ))return ;/*
Signature · 1 line
2.23.0
PATCH v2 10/16 mm, memory_hotplug: remove obsolete generic_free_nodedata()
In reply to Miaohe LinCommit 390511e1476e ("mm, memory_hotplug: drop arch_free_nodedata") drops the last caller of generic_free_nodedata(). Remove it too.
--- include/linux/memory_hotplug.h | 8 -------- 1 file changed, 8 deletions(-)
include/linux/memory_hotplug.h +0 -8
@@ -43,11 +43,6 @@ extern void arch_refresh_nodedata(int nid, pg_data_t *pgdat); ({ \memblock_alloc (sizeof (*pgdat),SMP_CACHE_BYTES ); \ }) -/* -* This definition is just for error path in node hotadd. -* For node hotremove, we have to replace this. - */ -#define generic_free_nodedata (pgdat) kfree(pgdat)extern pg_data_t *node_data[];static inline void arch_refresh_nodedata (int nid,pg_data_t *pgdat)
@@ -63,9 +58,6 @@ static inline pg_data_t *generic_alloc_nodedata(int nid)BUG ();return NULL ; } -static inline void generic_free_nodedata (pg_data_t *pgdat) -{ -}static inline void arch_refresh_nodedata (int nid,pg_data_t *pgdat) { }
Signature · 1 line
2.23.0
PATCH v2 11/16 mm/page_alloc: make boot_nodestats static
In reply to Miaohe LinIt's only used in mm/page_alloc.c now. Make it static.
--- mm/internal.h | 2 -- mm/page_alloc.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
mm/internal.h +0 -2
@@ -836,8 +836,6 @@ int migrate_device_coherent_page(struct page *page);*/ struct folio *try_grab_folio (struct page *page,int refs,unsigned int flags); -DECLARE_PER_CPU(struct per_cpu_nodestat, boot_nodestats); -extern bool mirrored_kernelcore;static inline bool vma_soft_dirty_enabled (struct vm_area_struct *vma)
mm/page_alloc.c +1 -1
@@ -6571,7 +6571,7 @@ static void per_cpu_pages_init(struct per_cpu_pages *pcp, struct per_cpu_zonesta#define BOOT_PAGESET_BATCH 1 static DEFINE_PER_CPU(struct per_cpu_pages, boot_pageset); static DEFINE_PER_CPU(struct per_cpu_zonestat, boot_zonestats); -DEFINE_PER_CPU (struct per_cpu_nodestat , boot_nodestats); +static DEFINE_PER_CPU(struct per_cpu_nodestat, boot_nodestats);static void __build_all_zonelists (void *data) {
Signature · 1 line
2.23.0
PATCH v2 12/16 mm/page_alloc: use helper macro SZ_1{K,M}
In reply to Miaohe LinUse helper macro SZ_1K and SZ_1M to do the size conversion. Minor readability improvement.
--- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
@@ -7048,7 +7048,7 @@ static int zone_batchsize(struct zone *zone)* size is striking a balance between allocation latency * and zone lock contention. */ - batch =min (zone_managed_pages (zone) >>10 , (1024 *1024 ) /PAGE_SIZE ); + batch =min (zone_managed_pages (zone) >>10 ,SZ_1M /PAGE_SIZE ); batch /=4 ;/* We effectively *= 4 below */ if (batch <1 ) batch =1 ;
@@ -8523,8 +8523,8 @@ void __init mem_init_print_info(void)#endif ")\n" ,K (nr_free_pages ()),K (physpages), - codesize >>10 , datasize >>10 , rosize >>10 , - (init_data_size + init_code_size) >>10 , bss_size >>10 , + codesize /SZ_1K , datasize /SZ_1K , rosize /SZ_1K , + (init_data_size + init_code_size) /SZ_1K , bss_size /SZ_1K ,K (physpages -totalram_pages () - totalcma_pages),K (totalcma_pages) #ifdef CONFIG_HIGHMEM
@@ -9049,8 +9049,8 @@ void *__init alloc_large_system_hash(const char *tablename, numentries -=arch_reserved_kernel_pages ();/* It isn't necessary when PAGE_SIZE >= 1MB */ -if (PAGE_SHIFT <20 ) - numentries =round_up (numentries, (1 <<20 )/PAGE_SIZE ); +if (PAGE_SIZE <SZ_1M ) + numentries =round_up (numentries,SZ_1M /PAGE_SIZE );#if __BITS_PER_LONG >32 if (!high_limit) {
Signature · 1 line
2.23.0
Re: [PATCH v2 12/16] mm/page_alloc: use helper macro SZ_1{K,M}
Quoted 5 lines · Miaohe Lin
Use helper macro
SZ_1KandSZ_1Mto do the size conversion. Minor readability improvement.Signed-off-by Miaohe Lin <[email protected]>---
Signature · 3 lines
Thanks, David / dhildenb
PATCH v2 13/16 mm/page_alloc: init local variable buddy_pfn
In reply to Miaohe LinThe local variable buddy_pfn could be passed to buddy_merge_likely() without initialization if the passed in order is MAX_ORDER - 1. This looks buggy but buddy_pfn won't be used in this case as there's a order >= MAX_ORDER - 2 check. Init buddy_pfn to 0 anyway to avoid possible future misuse.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -1113,7 +1113,7 @@ static inline void __free_one_page(struct page *page, int migratetype, fpi_t fpi_flags) {struct capture_control *capc =task_capc (zone); -unsigned long buddy_pfn; +unsigned long buddy_pfn =0 ;unsigned long combined_pfn;struct page *buddy;bool to_tail;
Signature · 1 line
2.23.0
PATCH v2 14/16 mm/page_alloc: use costly_order in WARN_ON_ONCE_GFP()
In reply to Miaohe LinThere's no need to check whether order > PAGE_ALLOC_COSTLY_ORDER again. Minor readability improvement.
--- mm/page_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/page_alloc.c +1 -1
@@ -5272,7 +5272,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,* so that we can identify them and convert them to something * else. */ -WARN_ON_ONCE_GFP (order >PAGE_ALLOC_COSTLY_ORDER , gfp_mask); +WARN_ON_ONCE_GFP (costly_order, gfp_mask);/* * Help non-failing allocations by giving them access to memory
Signature · 1 line
2.23.0
PATCH v2 15/16 mm/page_alloc: remove obsolete gfpflags_normal_context()
In reply to Miaohe LinSince commit dacb5d8875cc ("tcp: fix page frag corruption on page fault"), there's no caller of gfpflags_normal_context(). Remove it as this helper is strictly tied to the sk page frag usage and there won't be other user in the future.
--- include/linux/gfp.h | 23 ----------------------- 1 file changed, 23 deletions(-)
include/linux/gfp.h +0 -23
@@ -36,29 +36,6 @@ static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)return !!(gfp_flags & __GFP_DIRECT_RECLAIM); } -/** -* gfpflags_normal_context - is gfp_flags a normal sleepable context? -* @gfp_flags: gfp_flags to test -* -* Test whether @gfp_flags indicates that the allocation is from the -* %current context and allowed to sleep. -* -* An allocation being allowed to block doesn't mean it owns the %current -* context. When direct reclaim path tries to allocate memory, the -* allocation context is nested inside whatever %current was doing at the -* time of the original allocation. The nested allocation may be allowed -* to block but modifying anything %current owns can corrupt the outer -* context's expectations. -* -* %true result from this function indicates that the allocation context -* can sleep and use anything that's associated with %current. -*/ -static inline bool gfpflags_normal_context (const gfp_t gfp_flags) -{ -return (gfp_flags & (__GFP_DIRECT_RECLAIM | __GFP_MEMALLOC)) == - __GFP_DIRECT_RECLAIM; -} -#ifdef CONFIG_HIGHMEM #define OPT_ZONE_HIGHMEM ZONE_HIGHMEM#else
Signature · 1 line
2.23.0
PATCH v2 16/16 mm/page_alloc: fix obsolete comment in deferred_pfn_valid()
In reply to Miaohe LinThere are no architectures that can have holes in the memory map within a pageblock since commit 859a85ddf90e ("mm: remove pfn_valid_within() and CONFIG_HOLES_IN_ZONE"). Update the corresponding comment.
--- mm/page_alloc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
mm/page_alloc.c +1 -5
@@ -1929,11 +1929,7 @@ static inline void __init pgdat_init_report_one_done(void)/* * Returns true if page needs to be initialized or freed to buddy allocator. * -* First we check if pfn is valid on architectures where it is possible to have -* holes within pageblock_nr_pages. On systems where it is not possible, this -* function is optimized out. -* -* Then, we check if a current large page is valid by only checking the validity +* We check if a current large page is valid by only checking the validity * of the head pfn. */ static inline bool __init deferred_pfn_valid (unsigned long pfn)
Signature · 1 line
2.23.0