clean-up the migration target allocation functions
Subsystems (8)
v5 cover clean-up the migration target allocation functions
From: Joonsoo Kim <[email protected]>
This patchset clean-up the migration target allocation functions.
* Changes on v5
- remove new_non_cma_page() related patches
(implementation for memalloc_nocma_{save,restore} has a critical bug that cannot exclude CMA memory in some cases so cannot use them here. Need to fix them first.)
- introduce a wrapper to handle gfp_mask for hugetlb use it
* Changes on v4
- use full gfp_mask
- use memalloc_nocma_{save,restore} to exclude CMA memory
- separate __GFP_RECLAIM handling for THP allocation
- remove more wrapper functions
* Changes on v3
- As Vlastimil suggested, do not introduce alloc_control for hugetlb functions
- do not change the signature of migrate_pages()
- rename alloc_control to migration_target_control
* Changes on v2
- add acked-by tags
- fix missing compound_head() call for patch #3
- remove thisnode field on alloc_control and use __GFP_THISNODE directly
- fix missing __gfp_mask setup for patch
"mm/hugetlb: do not modify user provided gfp_mask"
* Cover-letter
Contributions of this patchset are:
1. unify two hugetlb alloc functions. As a result, one is remained.
2. remove one implementation for migration target allocaion
3. remove three wrapper for migration target allocation
The patchset is based on next-20200703 + revert following commits. ddc017c727e429488cccd401a7794c8152e50a5b~1..583c2617fd3244fff79ba3b445964884c5cd7780
The patchset is available on:
https://github.com/JoonsooKim/linux/tree/cleanup-migration-target-allocation-v5.00-next-20200703
Thanks.
Joonsoo Kim (9):
mm/page_isolation: prefer the node of the source page mm/migrate: move migration helper from .h to .c mm/hugetlb: unify migration callbacks
mm/migrate: clear __GFP_RECLAIM to make the migration callback
consistent with regular THP allocations
mm/migrate: make a standard migration target allocation function mm/mempolicy: use a standard migration target allocation callback mm/page_alloc: remove a wrapper for alloc_migration_target() mm/memory-failure: remove a wrapper for alloc_migration_target() mm/memory_hotplug: remove a wrapper for alloc_migration_target()
include/linux/hugetlb.h | 41 +++++++++++++++++++++++++++++++-------- include/linux/migrate.h | 34 ++++++--------------------------- mm/hugetlb.c | 35 ++------------------------------- mm/internal.h | 8 +++++++- mm/memory-failure.c | 15 ++++++--------- mm/memory_hotplug.c | 42 +++++++++++++++++++++------------------- mm/mempolicy.c | 29 ++++++---------------------- mm/migrate.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++-- mm/page_alloc.c | 8 ++++++-- mm/page_isolation.c | 5 ----- 10 files changed, 137 insertions(+), 131 deletions(-)
Signature · 1 line
2.7.4
PATCH v5 1/9 mm/page_isolation: prefer the node of the source page
From: Joonsoo Kim <[email protected]>
For locality, it's better to migrate the page to the same node rather than the node of the current caller's cpu.
--- mm/page_isolation.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/page_isolation.c +3 -1
@@ -309,5 +309,7 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,struct page *alloc_migrate_target (struct page *page,unsigned long private) { -return new_page_nodemask (page,numa_node_id (), &node_states[N_MEMORY ]); +int nid =page_to_nid (page); + +return new_page_nodemask (page, nid, &node_states[N_MEMORY ]); }
Signature · 1 line
2.7.4
PATCH v5 2/9 mm/migrate: move migration helper from .h to .c
In reply to [email protected]From: Joonsoo Kim <[email protected]>
It's not performance sensitive function. Move it to .c. This is a preparation step for future change.
--- include/linux/migrate.h | 33 +++++---------------------------- mm/migrate.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-)
include/linux/migrate.h +5 -28
@@ -31,34 +31,6 @@ enum migrate_reason {/* In mm/debug.c; also keep sync with include/trace/events/migrate.h */ extern const char *migrate_reason_names[MR_TYPES ]; -static inline struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask) -{ -gfp_t gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL; -unsigned int order =0 ; -struct page *new_page =NULL ; - -if (PageHuge (page)) -return alloc_huge_page_nodemask (page_hstate (compound_head (page)), - preferred_nid, nodemask); - -if (PageTransHuge (page)) { - gfp_mask |=GFP_TRANSHUGE ; - order =HPAGE_PMD_ORDER ; - } - -if (PageHighMem (page) || (zone_idx (page_zone (page)) ==ZONE_MOVABLE )) - gfp_mask |= __GFP_HIGHMEM; - - new_page =__alloc_pages_nodemask (gfp_mask, order, - preferred_nid, nodemask); - -if (new_page &&PageTransHuge (new_page)) -prep_transhuge_page (new_page); - -return new_page; -} -#ifdef CONFIG_MIGRATION extern void putback_movable_pages (struct list_head *l);
@@ -67,6 +39,8 @@ extern int migrate_page(struct address_space *mapping, enum migrate_mode mode);extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); +extern struct page *new_page_nodemask (struct page *page, +int preferred_nid,nodemask_t *nodemask);extern int isolate_movable_page (struct page *page,isolate_mode_t mode);extern void putback_movable_page (struct page *page);
@@ -85,6 +59,9 @@ static inline int migrate_pages(struct list_head *l, new_page_t new, free_page_t free, unsigned long private, enum migrate_mode mode, int reason) { return -ENOSYS; } +static inline struct page *new_page_nodemask (struct page *page, +int preferred_nid,nodemask_t *nodemask) + {return NULL ; }static inline int isolate_movable_page (struct page *page,isolate_mode_t mode) {return -EBUSY ; }
mm/migrate.c +29 -0
@@ -1531,6 +1531,35 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,return rc; } +struct page *new_page_nodemask (struct page *page, +int preferred_nid,nodemask_t *nodemask) +{ +gfp_t gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL; +unsigned int order =0 ; +struct page *new_page =NULL ; + +if (PageHuge (page)) +return alloc_huge_page_nodemask ( +page_hstate (compound_head (page)), + preferred_nid, nodemask); + +if (PageTransHuge (page)) { + gfp_mask |=GFP_TRANSHUGE ; + order =HPAGE_PMD_ORDER ; + } + +if (PageHighMem (page) || (zone_idx (page_zone (page)) ==ZONE_MOVABLE )) + gfp_mask |= __GFP_HIGHMEM; + + new_page =__alloc_pages_nodemask (gfp_mask, order, + preferred_nid, nodemask); + +if (new_page &&PageTransHuge (new_page)) +prep_transhuge_page (new_page); + +return new_page; +} +#ifdef CONFIG_NUMA static int store_status (int __user *status,int start,int value,int nr)
Signature · 1 line
2.7.4
PATCH v5 3/9 mm/hugetlb: unify migration callbacks
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is no difference between two migration callback functions, alloc_huge_page_node() and alloc_huge_page_nodemask(), except __GFP_THISNODE handling. It's redundant to have two almost similar functions in order to handle this flag. So, this patch tries to remove one by introducing a new argument, gfp_mask, to alloc_huge_page_nodemask().
After introducing gfp_mask argument, it's caller's job to provide correct gfp_mask. So, every callsites for alloc_huge_page_nodemask() are changed to provide gfp_mask.
Note that it's safe to remove a node id check in alloc_huge_page_node() since there is no caller passing NUMA_NO_NODE as a node id.
--- include/linux/hugetlb.h | 26 ++++++++++++++++++-------- mm/hugetlb.c | 35 ++--------------------------------- mm/mempolicy.c | 10 ++++++---- mm/migrate.c | 11 +++++++---- 4 files changed, 33 insertions(+), 49 deletions(-)
include/linux/hugetlb.h +18 -8
@@ -10,6 +10,7 @@#include <linux/list.h> #include <linux/kref.h> #include <linux/pgtable.h> +#include <linux/gfp.h> struct ctl_table ;struct user_struct ;
@@ -504,9 +505,8 @@ struct huge_bootmem_page {struct page *alloc_huge_page (struct vm_area_struct *vma,unsigned long addr,int avoid_reserve); -struct page *alloc_huge_page_node (struct hstate *h,int nid);struct page *alloc_huge_page_nodemask (struct hstate *h,int preferred_nid, -nodemask_t *nmask); +nodemask_t *nmask,gfp_t gfp_mask);struct page *alloc_huge_page_vma (struct hstate *h,struct vm_area_struct *vma,unsigned long address); struct page *alloc_migrate_huge_page(struct hstate *h, gfp_t gfp_mask,
@@ -692,6 +692,15 @@ static inline bool hugepage_movable_supported(struct hstate *h)return true; } +/* Movability of hugepages depends on migration support. */ +static inline gfp_t htlb_alloc_mask (struct hstate *h) +{ +if (hugepage_movable_supported (h)) +return GFP_HIGHUSER_MOVABLE ; +else +return GFP_HIGHUSER ; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
@@ -759,13 +768,9 @@ static inline struct page *alloc_huge_page(struct vm_area_struct *vma,return NULL ; } -static inline struct page *alloc_huge_page_node (struct hstate *h,int nid) -{ -return NULL ; -} -static inline struct page * -alloc_huge_page_nodemask (struct hstate *h,int preferred_nid,nodemask_t *nmask) +alloc_huge_page_nodemask (struct hstate *h,int preferred_nid, +nodemask_t *nmask,gfp_t gfp_mask) {return NULL ; }
@@ -878,6 +883,11 @@ static inline bool hugepage_movable_supported(struct hstate *h)return false; } +static inline gfp_t htlb_alloc_mask (struct hstate *h) +{ +return 0 ; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
mm/hugetlb.c +2 -33
@@ -1089,15 +1089,6 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, gfp_t gfp_mask,return NULL ; } -/* Movability of hugepages depends on migration support. */ -static inline gfp_t htlb_alloc_mask (struct hstate *h) -{ -if (hugepage_movable_supported (h)) -return GFP_HIGHUSER_MOVABLE ; -else -return GFP_HIGHUSER ; -} - static struct page *dequeue_huge_page_vma(struct hstate *h, struct vm_area_struct *vma, unsigned long address, int avoid_reserve,
@@ -1979,31 +1970,9 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h, }/* page migration callback function */ -struct page *alloc_huge_page_node (struct hstate *h,int nid) -{ -gfp_t gfp_mask =htlb_alloc_mask (h); -struct page *page =NULL ; - -if (nid !=NUMA_NO_NODE ) - gfp_mask |= __GFP_THISNODE; - -spin_lock (&hugetlb_lock); -if (h->free_huge_pages - h->resv_huge_pages >0 ) - page =dequeue_huge_page_nodemask (h, gfp_mask, nid,NULL ); -spin_unlock (&hugetlb_lock); - -if (!page) - page =alloc_migrate_huge_page (h, gfp_mask, nid,NULL ); - -return page; -} - -/* page migration callback function */ struct page *alloc_huge_page_nodemask (struct hstate *h,int preferred_nid, -nodemask_t *nmask) +nodemask_t *nmask,gfp_t gfp_mask) { -gfp_t gfp_mask =htlb_alloc_mask (h); -spin_lock (&hugetlb_lock);if (h->free_huge_pages - h->resv_huge_pages >0 ) {struct page *page;
@@ -2031,7 +2000,7 @@ struct page *alloc_huge_page_vma(struct hstate *h, struct vm_area_struct *vma, gfp_mask =htlb_alloc_mask (h); node =huge_node (vma, address, gfp_mask, &mpol, &nodemask); - page =alloc_huge_page_nodemask (h, node, nodemask); + page =alloc_huge_page_nodemask (h, node, nodemask, gfp_mask);mpol_cond_put (mpol);return page;
mm/mempolicy.c +6 -4
@@ -1068,10 +1068,12 @@ static int migrate_page_add(struct page *page, struct list_head *pagelist,/* page allocation callback for NUMA node migration */ struct page *alloc_new_node_page (struct page *page,unsigned long node) { -if (PageHuge (page)) -return alloc_huge_page_node (page_hstate (compound_head (page)), - node); -else if (PageTransHuge (page)) { +if (PageHuge (page)) { +struct hstate *h =page_hstate (compound_head (page)); +gfp_t gfp_mask =htlb_alloc_mask (h) | __GFP_THISNODE; + +return alloc_huge_page_nodemask (h, node,NULL , gfp_mask); + }else if (PageTransHuge (page)) {struct page *thp; thp = alloc_pages_node(node,
mm/migrate.c +7 -4
@@ -1538,10 +1538,13 @@ struct page *new_page_nodemask(struct page *page,unsigned int order =0 ;struct page *new_page =NULL ; -if (PageHuge (page)) -return alloc_huge_page_nodemask ( -page_hstate (compound_head (page)), - preferred_nid, nodemask); +if (PageHuge (page)) { +struct hstate *h =page_hstate (compound_head (page)); + + gfp_mask =htlb_alloc_mask (h); +return alloc_huge_page_nodemask (h, preferred_nid, + nodemask, gfp_mask); + }if (PageTransHuge (page)) { gfp_mask |=GFP_TRANSHUGE ;
Signature · 1 line
2.7.4
PATCH v5 4/9 mm/migrate: clear __GFP_RECLAIM to make the migration callback consistent with regular THP allocations
In reply to [email protected]From: Joonsoo Kim <[email protected]>
new_page_nodemask is a migration callback and it tries to use a common gfp flags for the target page allocation whether it is a base page or a THP. The later only adds GFP_TRANSHUGE to the given mask. This results in the allocation being slightly more aggressive than necessary because the resulting gfp mask will contain also __GFP_RECLAIM_KSWAPD. THP allocations usually exclude this flag to reduce over eager background reclaim during a high THP allocation load which has been seen during large mmaps initialization. There is no indication that this is a problem for migration as well but theoretically the same might happen when migrating large mappings to a different node. Make the migration callback consistent with regular THP allocations.
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/migrate.c +5 -0
@@ -1547,6 +1547,11 @@ struct page *new_page_nodemask(struct page *page, }if (PageTransHuge (page)) { +/* +* clear __GFP_RECALIM to make the migration callback +* consistent with regular THP allocations. +*/ + gfp_mask &= ~__GFP_RECLAIM; gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; }
Signature · 1 line
2.7.4
Re: [PATCH v5 4/9] mm/migrate: clear __GFP_RECLAIM to make the migration callback consistent with regular THP allocations
Quoted 14 lines · Joonsoo Kim
From: Joonsoo Kim <[email protected]>
new_page_nodemaskis a migration callback and it tries to use a common gfp flags for the target page allocation whether it is a base page or a THP. The later only addsGFP_TRANSHUGEto the given mask. This results in the allocation being slightly more aggressive than necessary because the resulting gfp mask will contain also__GFP_RECLAIM_KSWAPD. THP allocations usually exclude this flag to reduce over eager background reclaim during a high THP allocation load which has been seen during large mmaps initialization. There is no indication that this is a problem for migration as well but theoretically the same might happen when migrating large mappings to a different node. Make the migration callback consistent with regular THP allocations.
Quoted 1 line
Signed-off-by Joonsoo Kim <[email protected]>
Quoted 23 lines
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)mm/migrate.c +5
-0@@ -1547,6 +1547,11 @@ struct page *new_page_nodemask(struct page *page, }if (PageTransHuge (page)) { +/* +* clear __GFP_RECALIM to make the migration callback +* consistent with regular THP allocations. +*/ + gfp_mask &= ~__GFP_RECLAIM; gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; }Signature · 1 line
2.7.4
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH v5 4/9] mm/migrate: clear __GFP_RECLAIM to make the migration callback consistent with regular THP allocations
In reply to [email protected]Quoted 14 lines · On 7/13/20 8:41 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
new_page_nodemaskis a migration callback and it tries to use a common gfp flags for the target page allocation whether it is a base page or a THP. The later only addsGFP_TRANSHUGEto the given mask. This results in the allocation being slightly more aggressive than necessary because the resulting gfp mask will contain also__GFP_RECLAIM_KSWAPD. THP allocations usually exclude this flag to reduce over eager background reclaim during a high THP allocation load which has been seen during large mmaps initialization. There is no indication that this is a problem for migration as well but theoretically the same might happen when migrating large mappings to a different node. Make the migration callback consistent with regular THP allocations.
Quoted 1 line
Signed-off-by Joonsoo Kim <[email protected]>
Thanks!
Typo below (I assume Andrew will fix it)
Quoted 9 lines
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)mm/migrate.c +0
-0
mm/migrate.c struct page *new_page_nodemask(struct page *page, · line 1551
Quoted 5 lines
mm/migrate.c +2
-0@@ -1547,6 +1547,11 @@ struct page *new_page_nodemask(struct page *page, }if (PageTransHuge (page)) { +/* +* clear __GFP_RECALIM to make the migration callback
__GFP_RECLAIM
Quoted 7 lines
mm/migrate.c +3
-0+* consistent with regular THP allocations. +*/ + gfp_mask &= ~__GFP_RECLAIM; gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; }
Re: [PATCH v5 4/9] mm/migrate: clear __GFP_RECLAIM to make the migration callback consistent with regular THP allocations
Quoted 34 lines · Vlastimil Babka
Quoted 14 lines · On 7/13/20 8:41 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
new_page_nodemaskis a migration callback and it tries to use a common gfp flags for the target page allocation whether it is a base page or a THP. The later only addsGFP_TRANSHUGEto the given mask. This results in the allocation being slightly more aggressive than necessary because the resulting gfp mask will contain also__GFP_RECLAIM_KSWAPD. THP allocations usually exclude this flag to reduce over eager background reclaim during a high THP allocation load which has been seen during large mmaps initialization. There is no indication that this is a problem for migration as well but theoretically the same might happen when migrating large mappings to a different node. Make the migration callback consistent with regular THP allocations.Quoted 1 line
Signed-off-by Joonsoo Kim <[email protected]>Acked-by Vlastimil Babka <[email protected]>Thanks!
Typo below (I assume Andrew will fix it)
Quoted 11 lines
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)mm/migrate.c +0
-0@@ -1547,6 +1547,11 @@ struct page *new_page_nodemask(struct page *page, }
Quoted 6 lines
mm/migrate.c struct page *new_page_nodemask(struct page *page, · line 1551
Quoted 3 lines
mm/migrate.c +2
-0if (PageTransHuge (page)) { +/* +* clear __GFP_RECALIM to make the migration callback
__GFP_RECLAIM
Okay. Here goes a fixed version.
Thanks!
---------------------->8-----------------------------
From 6273f02fd8b8ef066c10c4a8ba54ea9efe6e70cd Mon Sep 17 00:00:00 2001
From: Joonsoo Kim <[email protected]>
Date: Mon, 6 Jul 2020 14:34:04 +0900
Subject: [PATCH v5 4/9] mm/migrate: clear __GFP_RECLAIM to make the migration
callback consistent with regular THP allocations
new_page_nodemask is a migration callback and it tries to use a common gfp flags for the target page allocation whether it is a base page or a THP. The later only adds GFP_TRANSHUGE to the given mask. This results in the allocation being slightly more aggressive than necessary because the resulting gfp mask will contain also __GFP_RECLAIM_KSWAPD. THP allocations usually exclude this flag to reduce over eager background reclaim during a high THP allocation load which has been seen during large mmaps initialization. There is no indication that this is a problem for migration as well but theoretically the same might happen when migrating large mappings to a different node. Make the migration callback consistent with regular THP allocations.
--- mm/migrate.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/migrate.c +5 -0
@@ -1547,6 +1547,11 @@ struct page *new_page_nodemask(struct page *page, }if (PageTransHuge (page)) { +/* +* clear __GFP_RECLAIM to make the migration callback +* consistent with regular THP allocations. +*/ + gfp_mask &= ~__GFP_RECLAIM; gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; }
Signature · 1 line
2.7.4
PATCH v5 5/9 mm/migrate: make a standard migration target allocation function
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There are some similar functions for migration target allocation. Since there is no fundamental difference, it's better to keep just one rather than keeping all variants. This patch implements base migration target allocation function. In the following patches, variants will be converted to use this function.
Changes should be mechanical, but, unfortunately, there are some differences. First, some callers' nodemask is assgined to NULL since NULL nodemask will be considered as all available nodes, that is, &node_states[N_MEMORY]. Second, for hugetlb page allocation, gfp_mask is redefined as regular hugetlb allocation gfp_mask plus __GFP_THISNODE if user provided gfp_mask has it. This is because future caller of this function requires to set this node constaint. Lastly, if provided nodeid is NUMA_NO_NODE, nodeid is set up to the node where migration source lives. It helps to remove simple wrappers for setting up the nodeid.
Note that PageHighmem() call in previous function is changed to open-code "is_highmem_idx()" since it provides more readability.
--- include/linux/hugetlb.h | 15 +++++++++++++++ include/linux/migrate.h | 9 +++++---- mm/internal.h | 7 +++++++ mm/memory-failure.c | 7 +++++-- mm/memory_hotplug.c | 12 ++++++++---- mm/migrate.c | 26 ++++++++++++++++---------- mm/page_isolation.c | 7 +++++-- 7 files changed, 61 insertions(+), 22 deletions(-)
include/linux/hugetlb.h +15 -0
@@ -701,6 +701,16 @@ static inline gfp_t htlb_alloc_mask(struct hstate *h)return GFP_HIGHUSER ; } +static inline gfp_t htlb_modify_alloc_mask (struct hstate *h,gfp_t gfp_mask) +{ +gfp_t modified_mask =htlb_alloc_mask (h); + +/* Some callers might want to enfoce node */ + modified_mask |= (gfp_mask & __GFP_THISNODE); + +return modified_mask; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
@@ -888,6 +898,11 @@ static inline gfp_t htlb_alloc_mask(struct hstate *h)return 0 ; } +static inline gfp_t htlb_modify_alloc_mask (struct hstate *h,gfp_t gfp_mask) +{ +return 0 ; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
include/linux/migrate.h +5 -4
@@ -10,6 +10,8 @@typedef struct page *new_page_t (struct page *page,unsigned long private);typedef void free_page_t (struct page *page,unsigned long private); +struct migration_target_control ; +/* * Return values from addresss_space_operations.migratepage(): * - negative errno on page migration failure;
@@ -39,8 +41,7 @@ extern int migrate_page(struct address_space *mapping, enum migrate_mode mode);extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); -extern struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask); +extern struct page *alloc_migration_target (struct page *page,unsigned long private);extern int isolate_movable_page (struct page *page,isolate_mode_t mode);extern void putback_movable_page (struct page *page);
@@ -59,8 +60,8 @@ static inline int migrate_pages(struct list_head *l, new_page_t new, free_page_t free, unsigned long private, enum migrate_mode mode, int reason) { return -ENOSYS; } -static inline struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask) +static inline struct page *alloc_migration_target (struct page *page, +unsigned long private) {return NULL ; }static inline int isolate_movable_page (struct page *page,isolate_mode_t mode) {return -EBUSY ; }
mm/internal.h +7 -0
@@ -614,4 +614,11 @@ static inline bool is_migrate_highatomic_page(struct page *page)void setup_zone_pageset (struct zone *zone);extern struct page *alloc_new_node_page (struct page *page,unsigned long node); + +struct migration_target_control { +int nid;/* preferred node id */ +nodemask_t *nmask; +gfp_t gfp_mask; +}; +#endif /* __MM_INTERNAL_H */
mm/memory-failure.c +5 -2
@@ -1679,9 +1679,12 @@ EXPORT_SYMBOL(unpoison_memory);static struct page *new_page (struct page *p,unsigned long private) { -int nid =page_to_nid (p); +struct migration_target_control mtc = { + .nid =page_to_nid (p), + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; -return new_page_nodemask (p, nid, &node_states[N_MEMORY ]); +return alloc_migration_target (p, (unsigned long )&mtc); }/*
mm/memory_hotplug.c +8 -4
@@ -1267,19 +1267,23 @@ static int scan_movable_pages(unsigned long start, unsigned long end,static struct page *new_node_page (struct page *page,unsigned long private) { -int nid =page_to_nid (page);nodemask_t nmask = node_states[N_MEMORY ]; +struct migration_target_control mtc = { + .nid =page_to_nid (page), + .nmask = &nmask, + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + };/* * try to allocate from a different node but reuse this node if there * are no other online nodes to be used (e.g. we are offlining a part * of the only existing node) */ -node_clear (nid, nmask); +node_clear (mtc.nid, nmask);if (nodes_empty (nmask)) -node_set (nid, nmask); +node_set (mtc.nid, nmask); -return new_page_nodemask (page, nid, &nmask); +return alloc_migration_target (page, (unsigned long )&mtc); } static int
mm/migrate.c +16 -10
@@ -1531,19 +1531,26 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,return rc; } -struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask) +struct page *alloc_migration_target (struct page *page,unsigned long private) { -gfp_t gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL; +struct migration_target_control *mtc; +gfp_t gfp_mask;unsigned int order =0 ;struct page *new_page =NULL ; +int nid; +int zidx; + + mtc = (struct migration_target_control *)private; + gfp_mask = mtc->gfp_mask; + nid = mtc->nid; +if (nid ==NUMA_NO_NODE ) + nid =page_to_nid (page);if (PageHuge (page)) {struct hstate *h =page_hstate (compound_head (page)); - gfp_mask =htlb_alloc_mask (h); -return alloc_huge_page_nodemask (h, preferred_nid, - nodemask, gfp_mask); + gfp_mask =htlb_modify_alloc_mask (h, gfp_mask); +return alloc_huge_page_nodemask (h, nid, mtc->nmask, gfp_mask); }if (PageTransHuge (page)) {
@@ -1555,12 +1562,11 @@ struct page *new_page_nodemask(struct page *page, gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; } - -if (PageHighMem (page) || (zone_idx (page_zone (page)) ==ZONE_MOVABLE )) + zidx =zone_idx (page_zone (page)); +if (is_highmem_idx (zidx) || zidx ==ZONE_MOVABLE ) gfp_mask |= __GFP_HIGHMEM; - new_page =__alloc_pages_nodemask (gfp_mask, order, - preferred_nid, nodemask); + new_page =__alloc_pages_nodemask (gfp_mask, order, nid, mtc->nmask);if (new_page &&PageTransHuge (new_page))prep_transhuge_page (new_page);
mm/page_isolation.c +5 -2
@@ -309,7 +309,10 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,struct page *alloc_migrate_target (struct page *page,unsigned long private) { -int nid =page_to_nid (page); +struct migration_target_control mtc = { + .nid =page_to_nid (page), + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; -return new_page_nodemask (page, nid, &node_states[N_MEMORY ]); +return alloc_migration_target (page, (unsigned long )&mtc); }
Signature · 1 line
2.7.4
Re: [PATCH v5 5/9] mm/migrate: make a standard migration target allocation function
Quoted 1 line · On 7/13/20 8:41 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
Nit: s/make/introduce/ in the subject, is a more common verb in this context.
Re: [PATCH v5 5/9] mm/migrate: make a standard migration target allocation function
Quoted 5 lines · Vlastimil Babka
Quoted 1 line · On 7/13/20 8:41 AM, [email protected] wrote:
From: Joonsoo Kim <[email protected]>
Nit: s/make/introduce/ in the subject, is a more common verb in this context.
Thanks for correcting!
Following is fixed version.
Thanks.
----------------->8-------------------
From e8e4533bbc56fff3a77d5bc9a40dda7a9efc83e8 Mon Sep 17 00:00:00 2001
From: Joonsoo Kim <[email protected]>
Date: Wed, 1 Jul 2020 16:19:18 +1000
Subject: [PATCH v5 5/9] mm/migrate: introduce a standard migration target
allocation function
There are some similar functions for migration target allocation. Since there is no fundamental difference, it's better to keep just one rather than keeping all variants. This patch implements base migration target allocation function. In the following patches, variants will be converted to use this function.
Changes should be mechanical, but, unfortunately, there are some differences. First, some callers' nodemask is assgined to NULL since NULL nodemask will be considered as all available nodes, that is, &node_states[N_MEMORY]. Second, for hugetlb page allocation, gfp_mask is redefined as regular hugetlb allocation gfp_mask plus __GFP_THISNODE if user provided gfp_mask has it. This is because future caller of this function requires to set this node constaint. Lastly, if provided nodeid is NUMA_NO_NODE, nodeid is set up to the node where migration source lives. It helps to remove simple wrappers for setting up the nodeid.
Note that PageHighmem() call in previous function is changed to open-code "is_highmem_idx()" since it provides more readability.
--- include/linux/hugetlb.h | 15 +++++++++++++++ include/linux/migrate.h | 9 +++++---- mm/internal.h | 7 +++++++ mm/memory-failure.c | 7 +++++-- mm/memory_hotplug.c | 12 ++++++++---- mm/migrate.c | 26 ++++++++++++++++---------- mm/page_isolation.c | 7 +++++-- 7 files changed, 61 insertions(+), 22 deletions(-)
include/linux/hugetlb.h +15 -0
@@ -701,6 +701,16 @@ static inline gfp_t htlb_alloc_mask(struct hstate *h)return GFP_HIGHUSER ; } +static inline gfp_t htlb_modify_alloc_mask (struct hstate *h,gfp_t gfp_mask) +{ +gfp_t modified_mask =htlb_alloc_mask (h); + +/* Some callers might want to enfoce node */ + modified_mask |= (gfp_mask & __GFP_THISNODE); + +return modified_mask; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
@@ -888,6 +898,11 @@ static inline gfp_t htlb_alloc_mask(struct hstate *h)return 0 ; } +static inline gfp_t htlb_modify_alloc_mask (struct hstate *h,gfp_t gfp_mask) +{ +return 0 ; +} +static inline spinlock_t *huge_pte_lockptr (struct hstate *h,struct mm_struct *mm,pte_t *pte) {
include/linux/migrate.h +5 -4
@@ -10,6 +10,8 @@typedef struct page *new_page_t (struct page *page,unsigned long private);typedef void free_page_t (struct page *page,unsigned long private); +struct migration_target_control ; +/* * Return values from addresss_space_operations.migratepage(): * - negative errno on page migration failure;
@@ -39,8 +41,7 @@ extern int migrate_page(struct address_space *mapping, enum migrate_mode mode);extern int migrate_pages (struct list_head *l,new_page_t new,free_page_t free,unsigned long private,enum migrate_mode mode,int reason); -extern struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask); +extern struct page *alloc_migration_target (struct page *page,unsigned long private);extern int isolate_movable_page (struct page *page,isolate_mode_t mode);extern void putback_movable_page (struct page *page);
@@ -59,8 +60,8 @@ static inline int migrate_pages(struct list_head *l, new_page_t new, free_page_t free, unsigned long private, enum migrate_mode mode, int reason) { return -ENOSYS; } -static inline struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask) +static inline struct page *alloc_migration_target (struct page *page, +unsigned long private) {return NULL ; }static inline int isolate_movable_page (struct page *page,isolate_mode_t mode) {return -EBUSY ; }
mm/internal.h +7 -0
@@ -614,4 +614,11 @@ static inline bool is_migrate_highatomic_page(struct page *page)void setup_zone_pageset (struct zone *zone);extern struct page *alloc_new_node_page (struct page *page,unsigned long node); + +struct migration_target_control { +int nid;/* preferred node id */ +nodemask_t *nmask; +gfp_t gfp_mask; +}; +#endif /* __MM_INTERNAL_H */
mm/memory-failure.c +5 -2
@@ -1679,9 +1679,12 @@ EXPORT_SYMBOL(unpoison_memory);static struct page *new_page (struct page *p,unsigned long private) { -int nid =page_to_nid (p); +struct migration_target_control mtc = { + .nid =page_to_nid (p), + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; -return new_page_nodemask (p, nid, &node_states[N_MEMORY ]); +return alloc_migration_target (p, (unsigned long )&mtc); }/*
mm/memory_hotplug.c +8 -4
@@ -1267,19 +1267,23 @@ static int scan_movable_pages(unsigned long start, unsigned long end,static struct page *new_node_page (struct page *page,unsigned long private) { -int nid =page_to_nid (page);nodemask_t nmask = node_states[N_MEMORY ]; +struct migration_target_control mtc = { + .nid =page_to_nid (page), + .nmask = &nmask, + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + };/* * try to allocate from a different node but reuse this node if there * are no other online nodes to be used (e.g. we are offlining a part * of the only existing node) */ -node_clear (nid, nmask); +node_clear (mtc.nid, nmask);if (nodes_empty (nmask)) -node_set (nid, nmask); +node_set (mtc.nid, nmask); -return new_page_nodemask (page, nid, &nmask); +return alloc_migration_target (page, (unsigned long )&mtc); } static int
mm/migrate.c +16 -10
@@ -1531,19 +1531,26 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,return rc; } -struct page *new_page_nodemask (struct page *page, -int preferred_nid,nodemask_t *nodemask) +struct page *alloc_migration_target (struct page *page,unsigned long private) { -gfp_t gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL; +struct migration_target_control *mtc; +gfp_t gfp_mask;unsigned int order =0 ;struct page *new_page =NULL ; +int nid; +int zidx; + + mtc = (struct migration_target_control *)private; + gfp_mask = mtc->gfp_mask; + nid = mtc->nid; +if (nid ==NUMA_NO_NODE ) + nid =page_to_nid (page);if (PageHuge (page)) {struct hstate *h =page_hstate (compound_head (page)); - gfp_mask =htlb_alloc_mask (h); -return alloc_huge_page_nodemask (h, preferred_nid, - nodemask, gfp_mask); + gfp_mask =htlb_modify_alloc_mask (h, gfp_mask); +return alloc_huge_page_nodemask (h, nid, mtc->nmask, gfp_mask); }if (PageTransHuge (page)) {
@@ -1555,12 +1562,11 @@ struct page *new_page_nodemask(struct page *page, gfp_mask |=GFP_TRANSHUGE ; order =HPAGE_PMD_ORDER ; } - -if (PageHighMem (page) || (zone_idx (page_zone (page)) ==ZONE_MOVABLE )) + zidx =zone_idx (page_zone (page)); +if (is_highmem_idx (zidx) || zidx ==ZONE_MOVABLE ) gfp_mask |= __GFP_HIGHMEM; - new_page =__alloc_pages_nodemask (gfp_mask, order, - preferred_nid, nodemask); + new_page =__alloc_pages_nodemask (gfp_mask, order, nid, mtc->nmask);if (new_page &&PageTransHuge (new_page))prep_transhuge_page (new_page);
mm/page_isolation.c +5 -2
@@ -309,7 +309,10 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,struct page *alloc_migrate_target (struct page *page,unsigned long private) { -int nid =page_to_nid (page); +struct migration_target_control mtc = { + .nid =page_to_nid (page), + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; -return new_page_nodemask (page, nid, &node_states[N_MEMORY ]); +return alloc_migration_target (page, (unsigned long )&mtc); }
Signature · 1 line
2.7.4
PATCH v5 6/9 mm/mempolicy: use a standard migration target allocation callback
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is a well-defined migration target allocation callback. Use it.
--- mm/internal.h | 1 - mm/mempolicy.c | 31 ++++++------------------------- mm/migrate.c | 8 ++++++-- 3 files changed, 12 insertions(+), 28 deletions(-)
mm/internal.h +0 -1
@@ -613,7 +613,6 @@ static inline bool is_migrate_highatomic_page(struct page *page) }void setup_zone_pageset (struct zone *zone); -extern struct page *alloc_new_node_page (struct page *page,unsigned long node);struct migration_target_control {int nid;/* preferred node id */
mm/mempolicy.c +6 -25
@@ -1065,29 +1065,6 @@ static int migrate_page_add(struct page *page, struct list_head *pagelist,return 0 ; } -/* page allocation callback for NUMA node migration */ -struct page *alloc_new_node_page (struct page *page,unsigned long node) -{ -if (PageHuge (page)) { -struct hstate *h =page_hstate (compound_head (page)); -gfp_t gfp_mask =htlb_alloc_mask (h) | __GFP_THISNODE; - -return alloc_huge_page_nodemask (h, node,NULL , gfp_mask); - }else if (PageTransHuge (page)) { -struct page *thp; - - thp =alloc_pages_node (node, - (GFP_TRANSHUGE | __GFP_THISNODE), -HPAGE_PMD_ORDER ); -if (!thp) -return NULL ; -prep_transhuge_page (thp); -return thp; - }else -return __alloc_pages_node (node,GFP_HIGHUSER_MOVABLE | - __GFP_THISNODE,0 ); -} -/* * Migrate pages from one node to a target node. * Returns error or the number of pages not migrated.
@@ -1098,6 +1075,10 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,nodemask_t nmask;LIST_HEAD (pagelist);int err =0 ; +struct migration_target_control mtc = { + .nid = dest, + .gfp_mask =GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, + };nodes_clear (nmask);node_set (source, nmask);
@@ -1112,8 +1093,8 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest, flags | MPOL_MF_DISCONTIG_OK, &pagelist);if (!list_empty (&pagelist)) { - err =migrate_pages (&pagelist, alloc_new_node_page,NULL , dest, -MIGRATE_SYNC ,MR_SYSCALL ); + err =migrate_pages (&pagelist, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_SYSCALL );if (err)putback_movable_pages (&pagelist); }
mm/migrate.c +6 -2
@@ -1591,9 +1591,13 @@ static int do_move_pages_to_node(struct mm_struct *mm, struct list_head *pagelist, int node) { int err; +struct migration_target_control mtc = { + .nid = node, + .gfp_mask =GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, + }; - err =migrate_pages (pagelist, alloc_new_node_page,NULL , node, -MIGRATE_SYNC ,MR_SYSCALL ); + err =migrate_pages (pagelist, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_SYSCALL );if (err)putback_movable_pages (pagelist);return err;
Signature · 1 line
2.7.4
PATCH v5 7/9 mm/page_alloc: remove a wrapper for alloc_migration_target()
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is a well-defined standard migration target callback. Use it directly.
--- mm/page_alloc.c | 8 ++++++-- mm/page_isolation.c | 10 ---------- 2 files changed, 6 insertions(+), 12 deletions(-)
mm/page_alloc.c +6 -2
@@ -8354,6 +8354,10 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,unsigned long pfn = start;unsigned int tries =0 ;int ret =0 ; +struct migration_target_control mtc = { + .nid =zone_to_nid (cc->zone), + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + };migrate_prep ();
@@ -8380,8 +8384,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, &cc->migratepages); cc->nr_migratepages -= nr_reclaimed; - ret =migrate_pages (&cc->migratepages, alloc_migrate_target, -NULL ,0 , cc->mode,MR_CONTIG_RANGE ); + ret =migrate_pages (&cc->migratepages, alloc_migration_target, +NULL , (unsigned long )&mtc, cc->mode,MR_CONTIG_RANGE ); }if (ret <0 ) {putback_movable_pages (&cc->migratepages);
mm/page_isolation.c +0 -10
@@ -306,13 +306,3 @@ int test_pages_isolated(unsigned long start_pfn, unsigned long end_pfn,return pfn < end_pfn ? -EBUSY :0 ; } - -struct page *alloc_migrate_target (struct page *page,unsigned long private) -{ -struct migration_target_control mtc = { - .nid =page_to_nid (page), - .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, - }; - -return alloc_migration_target (page, (unsigned long )&mtc); -}
Signature · 1 line
2.7.4
PATCH v5 8/9 mm/memory-failure: remove a wrapper for alloc_migration_target()
In reply to [email protected]From: Joonsoo Kim <[email protected]>
There is a well-defined standard migration target callback. Use it directly.
--- mm/memory-failure.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
mm/memory-failure.c +6 -12
@@ -1677,16 +1677,6 @@ int unpoison_memory(unsigned long pfn) }EXPORT_SYMBOL (unpoison_memory); -static struct page *new_page (struct page *p,unsigned long private) -{ -struct migration_target_control mtc = { - .nid =page_to_nid (p), - .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, - }; - -return alloc_migration_target (p, (unsigned long )&mtc); -} -/* * Safely get reference count of an arbitrary page. * Returns 0 for a free page, -EIO for a zero refcount page
@@ -1793,6 +1783,10 @@ static int __soft_offline_page(struct page *page)const char *msg_page[] = {"page" ,"hugepage" };bool huge =PageHuge (page);LIST_HEAD (pagelist); +struct migration_target_control mtc = { + .nid =NUMA_NO_NODE , + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + };/* * Check PageHWPoison again inside page lock because PageHWPoison
@@ -1829,8 +1823,8 @@ static int __soft_offline_page(struct page *page) }if (isolate_page (hpage, &pagelist)) { - ret =migrate_pages (&pagelist, new_page,NULL ,MPOL_MF_MOVE_ALL , -MIGRATE_SYNC ,MR_MEMORY_FAILURE ); + ret =migrate_pages (&pagelist, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_MEMORY_FAILURE );if (!ret) {bool release = !huge;
Signature · 1 line
2.7.4
PATCH v5 9/9 mm/memory_hotplug: remove a wrapper for alloc_migration_target()
In reply to [email protected]From: Joonsoo Kim <[email protected]>
To calculate the correct node to migrate the page for hotplug, we need to check node id of the page. Wrapper for alloc_migration_target() exists for this purpose.
However, Vlastimil informs that all migration source pages come from a single node. In this case, we don't need to check the node id for each page and we don't need to re-set the target nodemask for each page by using the wrapper. Set up the migration_target_control once and use it for all pages.
--- mm/memory_hotplug.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
mm/memory_hotplug.c +22 -24
@@ -1265,27 +1265,6 @@ static int scan_movable_pages(unsigned long start, unsigned long end,return 0 ; } -static struct page *new_node_page (struct page *page,unsigned long private) -{ -nodemask_t nmask = node_states[N_MEMORY ]; -struct migration_target_control mtc = { - .nid =page_to_nid (page), - .nmask = &nmask, - .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, - }; - -/* -* try to allocate from a different node but reuse this node if there -* are no other online nodes to be used (e.g. we are offlining a part -* of the only existing node) -*/ -node_clear (mtc.nid, nmask); -if (nodes_empty (nmask)) -node_set (mtc.nid, nmask); - -return alloc_migration_target (page, (unsigned long )&mtc); -} -static int do_migrate_range (unsigned long start_pfn,unsigned long end_pfn) {
@@ -1345,9 +1324,28 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)put_page (page); }if (!list_empty (&source)) { -/* Allocate a new page from the nearest neighbor node */ - ret =migrate_pages (&source, new_node_page,NULL ,0 , -MIGRATE_SYNC ,MR_MEMORY_HOTPLUG ); +nodemask_t nmask = node_states[N_MEMORY ]; +struct migration_target_control mtc = { + .nmask = &nmask, + .gfp_mask =GFP_USER | __GFP_MOVABLE | __GFP_RETRY_MAYFAIL, + }; + +/* +* We have checked that migration range is on a single zone so +* we can use the nid of the first page to all the others. +*/ + mtc.nid = page_to_nid(list_first_entry(&source, struct page, lru)); + +/* +* try to allocate from a different node but reuse this node +* if there are no other online nodes to be used (e.g. we are +* offlining a part of the only existing node) +*/ +node_clear (mtc.nid, nmask); +if (nodes_empty (nmask)) +node_set (mtc.nid, nmask); + ret =migrate_pages (&source, alloc_migration_target,NULL , + (unsigned long )&mtc,MIGRATE_SYNC ,MR_MEMORY_HOTPLUG );if (ret) {list_for_each_entry (page, &source, lru) { pr_warn("migrating pfn %lx failed ret:%d ",
Signature · 1 line
2.7.4