Change the return value for page isolation functions
Subsystems (16)
Baolin Wang
reviewerv2 cover Change the return value for page isolation functions
Now the page isolation functions did not return a boolean to indicate success or not, instead it will return a negative error when failed to isolate a page. So below code used in most places seem a boolean success/failure thing, which can confuse people whether the isolation is successful.
if (folio_isolate_lru(folio))
continue;
Moreover the page isolation functions only return 0 or -EBUSY, and most users did not care about the negative error except for few users, thus we can convert all page isolation functions to return a boolean value, which can remove the confusion to make code more clear.
No functional changes intended in this patch series.
Changes from v1:
- Convert all isolation functions to return bool.
Baolin Wang (4):
mm: change to return bool for folio_isolate_lru()
mm: change to return bool for isolate_lru_page()
mm: hugetlb: change to return bool for isolate_hugetlb()
mm: change to return bool for isolate_movable_page()
include/linux/hugetlb.h | 6 +++--- include/linux/migrate.h | 6 +++--- mm/compaction.c | 2 +- mm/damon/paddr.c | 2 +- mm/folio-compat.c | 4 ++-- mm/gup.c | 2 +- mm/hugetlb.c | 12 ++++++++---- mm/internal.h | 4 ++-- mm/khugepaged.c | 4 ++-- mm/madvise.c | 4 ++-- mm/memcontrol.c | 4 ++-- mm/memory-failure.c | 10 +++++----- mm/memory_hotplug.c | 2 +- mm/mempolicy.c | 4 ++-- mm/migrate.c | 17 ++++++++++------- mm/migrate_device.c | 2 +- mm/vmscan.c | 10 +++++----- 17 files changed, 51 insertions(+), 44 deletions(-)
Signature · 1 line
2.27.0
Baolin Wang
reviewerPATCH v2 1/4 mm: change to return bool for folio_isolate_lru()
Now the folio_isolate_lru() did not return a boolean value to indicate isolation success or not, however below code checking the return value can make people think that it was a boolean success/failure thing, which makes people easy to make mistakes (see the fix patch[1]).
if (folio_isolate_lru(folio))
continue;
Thus it's better to check the negative error value expilictly returned by folio_isolate_lru(), which makes code more clear per Linus's suggestion[2]. Moreover Matthew suggested we can convert the isolation functions to return a boolean[3], since most users did not care about the negative error value, and can also remove the confusing of checking return value.
So this patch converts the folio_isolate_lru() to return a boolean value, which means return 'true' to indicate the folio isolation is successful, and 'false' means a failure to isolation. Meanwhile changing all users' logic of checking the isolation state.
No functional changes intended.
[1] https://lore.kernel.org/all/20230131063206.28820-1-Kuan-Ying.Lee-NuS5LvNUpcJWk0Htik3J/[email protected]/T/#u
[2] https://lore.kernel.org/all/CAHk-=wiBrY+O-4=2mrbVyxR+hOqfdJ=Do6xoucfJ9_5az01L4Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org/
[3] https://lore.kernel.org/all/Y+sTFqwMNAjDvxw3-FZi0V3Vbi30CUdFEqe4BF2D2FQJk+8+b@public.gmane.org/
--- mm/damon/paddr.c | 2 +- mm/folio-compat.c | 8 +++++++- mm/gup.c | 2 +- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/madvise.c | 4 ++-- mm/mempolicy.c | 2 +- mm/vmscan.c | 10 +++++----- 8 files changed, 19 insertions(+), 13 deletions(-)
mm/damon/paddr.c +1 -1
@@ -246,7 +246,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)folio_clear_referenced (folio);folio_test_clear_young (folio); -if (folio_isolate_lru (folio)) { +if (!folio_isolate_lru (folio)) {folio_put (folio);continue ; }
mm/folio-compat.c +7 -1
@@ -115,9 +115,15 @@ EXPORT_SYMBOL(grab_cache_page_write_begin);int isolate_lru_page (struct page *page) { +bool ret; +if (WARN_RATELIMIT (PageTail (page),"trying to isolate tail page" ))return -EBUSY ; -return folio_isolate_lru ((struct folio *)page); + ret =folio_isolate_lru ((struct folio *)page); +if (ret) +return 0 ; + +return -EBUSY ; }void putback_lru_page (struct page *page)
mm/gup.c +1 -1
@@ -1939,7 +1939,7 @@ static unsigned long collect_longterm_unpinnable_pages( drain_allow = false; } -if (folio_isolate_lru (folio)) +if (!folio_isolate_lru (folio))continue ;list_add_tail (&folio->lru, movable_page_list);
mm/internal.h +1 -1
@@ -188,7 +188,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,* in mm/vmscan.c: */ int isolate_lru_page (struct page *page); -int folio_isolate_lru (struct folio *folio); +bool folio_isolate_lru (struct folio *folio);void putback_lru_page (struct page *page);void folio_putback_lru (struct folio *folio);extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason);
mm/khugepaged.c +1 -1
@@ -2047,7 +2047,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, goto out_unlock; } -if (folio_isolate_lru (folio)) { +if (!folio_isolate_lru (folio)) { result =SCAN_DEL_PAGE_LRU ; goto out_unlock; }
mm/madvise.c +2 -2
@@ -406,7 +406,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,folio_clear_referenced (folio);folio_test_clear_young (folio);if (pageout) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {if (folio_test_unevictable (folio))folio_putback_lru (folio);else
@@ -500,7 +500,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,folio_clear_referenced (folio);folio_test_clear_young (folio);if (pageout) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {if (folio_test_unevictable (folio))folio_putback_lru (folio);else
mm/mempolicy.c +1 -1
@@ -1033,7 +1033,7 @@ static int migrate_folio_add(struct folio *folio, struct list_head *foliolist,* expensive, so check the estimated mapcount of the folio instead. */ if ((flags &MPOL_MF_MOVE_ALL ) ||folio_estimated_sharers (folio) ==1 ) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {list_add_tail (&folio->lru, foliolist); node_stat_mod_folio(folio, NR_ISOLATED_ANON + folio_is_file_lru(folio),
mm/vmscan.c +5 -5
@@ -2337,12 +2337,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan,* (2) The lru_lock must not be held. * (3) Interrupts must be enabled. * -* Return: 0 if the folio was removed from an LRU list. -* -EBUSY if the folio was not on an LRU list. +* Return: true if the folio was removed from an LRU list. +* false if the folio was not on an LRU list. */ -int folio_isolate_lru (struct folio *folio) +bool folio_isolate_lru (struct folio *folio) { -int ret = -EBUSY ; +bool ret = false;VM_BUG_ON_FOLIO (!folio_ref_count (folio), folio);
@@ -2353,7 +2353,7 @@ int folio_isolate_lru(struct folio *folio) lruvec =folio_lruvec_lock_irq (folio);lruvec_del_folio (lruvec, folio);unlock_page_lruvec_irq (lruvec); - ret =0 ; + ret = true; }return ret;
Signature · 1 line
2.27.0
Re: [PATCH v2 1/4] mm: change to return bool for folio_isolate_lru()
Quoted 177 lines · On Tue, 14 Feb 2023 21:59:29 +0800 Baolin Wang <[email protected]>…
Now the
folio_isolate_lru()did not return a boolean value to indicate isolation success or not, however below code checking the return value can make people think that it was a boolean success/failure thing, which makes people easy to make mistakes (see the fix patch[1]).if (
folio_isolate_lru(folio))continue;Thus it's better to check the negative error value expilictly returned by
folio_isolate_lru(), which makes code more clear per Linus's suggestion[2]. Moreover Matthew suggested we can convert the isolation functions to return a boolean[3], since most users did not care about the negative error value, and can also remove the confusing of checking return value.So this patch converts the
folio_isolate_lru()to return a boolean value, which means return 'true' to indicate the folio isolation is successful, and 'false' means a failure to isolation. Meanwhile changing all users' logic of checking the isolation state.No functional changes intended.
[1] https://lore.kernel.org/all/[email protected]/T/#u
[2] https://lore.kernel.org/all/CAHk-=wiBrY+O-4=2mrbVyxR+hOqfdJ=Do6xoucfJ9_5az01L4Q@mail.gmail.com/
[3] https://lore.kernel.org/all/[email protected]/Signed-off-by Baolin Wang <[email protected]>--- mm/damon/paddr.c | 2 +- mm/folio-compat.c | 8 +++++++- mm/gup.c | 2 +- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/madvise.c | 4 ++-- mm/mempolicy.c | 2 +- mm/vmscan.c | 10 +++++----- 8 files changed, 19 insertions(+), 13 deletions(-)mm/damon/paddr.c +1
-1@@ -246,7 +246,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)folio_clear_referenced (folio);folio_test_clear_young (folio); -if (folio_isolate_lru (folio)) { +if (!folio_isolate_lru (folio)) {folio_put (folio);continue ; }mm/folio-compat.c +7
-1@@ -115,9 +115,15 @@ EXPORT_SYMBOL(grab_cache_page_write_begin);int isolate_lru_page (struct page *page) { +bool ret; +if (WARN_RATELIMIT (PageTail (page),"trying to isolate tail page" ))return -EBUSY ; -return folio_isolate_lru ((struct folio *)page); + ret =folio_isolate_lru ((struct folio *)page); +if (ret) +return 0 ; + +return -EBUSY ; }void putback_lru_page (struct page *page)mm/gup.c +1
-1@@ -1939,7 +1939,7 @@ static unsigned long collect_longterm_unpinnable_pages( drain_allow = false; } -if (folio_isolate_lru (folio)) +if (!folio_isolate_lru (folio))continue ;list_add_tail (&folio->lru, movable_page_list);mm/internal.h +1
-1@@ -188,7 +188,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,* in mm/vmscan.c: */ int isolate_lru_page (struct page *page); -int folio_isolate_lru (struct folio *folio); +bool folio_isolate_lru (struct folio *folio);void putback_lru_page (struct page *page);void folio_putback_lru (struct folio *folio);extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason);mm/khugepaged.c +1
-1@@ -2047,7 +2047,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, goto out_unlock; } -if (folio_isolate_lru (folio)) { +if (!folio_isolate_lru (folio)) { result =SCAN_DEL_PAGE_LRU ; goto out_unlock; }mm/madvise.c +2
-2@@ -406,7 +406,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,folio_clear_referenced (folio);folio_test_clear_young (folio);if (pageout) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {if (folio_test_unevictable (folio))folio_putback_lru (folio);else @@ -500,7 +500,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,folio_clear_referenced (folio);folio_test_clear_young (folio);if (pageout) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {if (folio_test_unevictable (folio))folio_putback_lru (folio);else mm/mempolicy.c +1
-1@@ -1033,7 +1033,7 @@ static int migrate_folio_add(struct folio *folio, struct list_head *foliolist,* expensive, so check the estimated mapcount of the folio instead. */ if ((flags &MPOL_MF_MOVE_ALL ) ||folio_estimated_sharers (folio) ==1 ) { -if (!folio_isolate_lru (folio)) { +if (folio_isolate_lru (folio)) {list_add_tail (&folio->lru, foliolist); node_stat_mod_folio(folio, NR_ISOLATED_ANON + folio_is_file_lru(folio),mm/vmscan.c +5
-5@@ -2337,12 +2337,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan,* (2) The lru_lock must not be held. * (3) Interrupts must be enabled. * -* Return: 0 if the folio was removed from an LRU list. -* -EBUSY if the folio was not on an LRU list. +* Return: true if the folio was removed from an LRU list. +* false if the folio was not on an LRU list. */ -int folio_isolate_lru (struct folio *folio) +bool folio_isolate_lru (struct folio *folio) { -int ret = -EBUSY ; +bool ret = false;VM_BUG_ON_FOLIO (!folio_ref_count (folio), folio);@@ -2353,7 +2353,7 @@ int folio_isolate_lru(struct folio *folio) lruvec =folio_lruvec_lock_irq (folio);lruvec_del_folio (lruvec, folio);unlock_page_lruvec_irq (lruvec); - ret =0 ; + ret = true; }return ret;Signature · 1 line
2.27.0
Thanks,
SJ
Baolin Wang
reviewerPATCH v2 2/4 mm: change to return bool for isolate_lru_page()
In reply to Baolin WangThe isolate_lru_page() can only return 0 or -EBUSY, and most users did not care about the negative error of isolate_lru_page(), except one user in add_page_for_migration(). So we can convert the isolate_lru_page() to return a boolean value, which can help to make the code more clear when checking the return value of isolate_lru_page().
Also convert all users' logic of checking the isolation state.
No functional changes intended.
--- mm/folio-compat.c | 12 +++--------- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/memcontrol.c | 4 ++-- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 2 +- mm/migrate.c | 9 ++++++--- mm/migrate_device.c | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-)
mm/folio-compat.c +3 -9
@@ -113,17 +113,11 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, }EXPORT_SYMBOL (grab_cache_page_write_begin); -int isolate_lru_page (struct page *page) +bool isolate_lru_page (struct page *page) { -bool ret; -if (WARN_RATELIMIT (PageTail (page),"trying to isolate tail page" )) -return -EBUSY ; - ret =folio_isolate_lru ((struct folio *)page); -if (ret) -return 0 ; - -return -EBUSY ; +return false; +return folio_isolate_lru ((struct folio *)page); }void putback_lru_page (struct page *page)
mm/internal.h +1 -1
@@ -187,7 +187,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,/* * in mm/vmscan.c: */ -int isolate_lru_page (struct page *page); +bool isolate_lru_page (struct page *page);bool folio_isolate_lru (struct folio *folio);void putback_lru_page (struct page *page);void folio_putback_lru (struct folio *folio);
mm/khugepaged.c +1 -1
@@ -659,7 +659,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,* Isolate the page to avoid collapsing an hugepage * currently in use by the VM. */ -if (isolate_lru_page (page)) { +if (!isolate_lru_page (page)) {unlock_page (page); result =SCAN_DEL_PAGE_LRU ; goto out;
mm/memcontrol.c +2 -2
@@ -6176,7 +6176,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd, target_type =get_mctgt_type_thp (vma, addr, *pmd, &target);if (target_type ==MC_TARGET_PAGE ) { page = target.page; -if (!isolate_lru_page (page)) { +if (isolate_lru_page (page)) {if (!mem_cgroup_move_account (page, true, mc.from, mc.to)) { mc.precharge -=HPAGE_PMD_NR ;
@@ -6226,7 +6226,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd,*/ if (PageTransCompound (page)) goto put; -if (!device &&isolate_lru_page (page)) +if (!device && !isolate_lru_page (page)) goto put;if (!mem_cgroup_move_account (page, false, mc.from, mc.to)) {
mm/memory-failure.c +2 -2
@@ -846,7 +846,7 @@ static const char * const action_page_types[] = {*/ static int delete_from_lru_cache (struct page *p) { -if (!isolate_lru_page (p)) { +if (isolate_lru_page (p)) {/* * Clear sensible page flags, so that the buddy system won't * complain when the page is unpoison-and-freed.
@@ -2513,7 +2513,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)bool lru = !__PageMovable (page);if (lru) - isolated = !isolate_lru_page (page); + isolated =isolate_lru_page (page);else isolated = !isolate_movable_page (page,ISOLATE_UNEVICTABLE );
mm/memory_hotplug.c +1 -1
@@ -1668,7 +1668,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)* LRU and non-lru movable pages. */ if (PageLRU (page)) - ret =isolate_lru_page (page); + ret = !isolate_lru_page (page);else ret =isolate_movable_page (page,ISOLATE_UNEVICTABLE );if (!ret) {/* Success */
mm/migrate.c +6 -3
@@ -2132,11 +2132,14 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, } }else {struct page *head; +bool isolated; head =compound_head (page); - err =isolate_lru_page (head); -if (err) + isolated =isolate_lru_page (head); +if (!isolated) { + err = -EBUSY ; goto out_putpage; + } err =1 ;list_add_tail (&head->lru, pagelist);
@@ -2541,7 +2544,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)return 0 ; } -if (isolate_lru_page (page)) +if (!isolate_lru_page (page))return 0 ; mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page),
mm/migrate_device.c +1 -1
@@ -388,7 +388,7 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns, allow_drain = false; } -if (isolate_lru_page (page)) { +if (!isolate_lru_page (page)) { src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; restore++;continue ;
Signature · 1 line
2.27.0
SeongJae Park
maintainerRe: [PATCH v2 2/4] mm: change to return bool for isolate_lru_page()
Quoted 22 lines · On Tue, 14 Feb 2023 21:59:30 +0800 Baolin Wang <[email protected]>…
The
isolate_lru_page()can only return 0 or-EBUSY, and most users did not care about the negative error ofisolate_lru_page(), except one user inadd_page_for_migration(). So we can convert theisolate_lru_page()to return a boolean value, which can help to make the code more clear when checking the return value ofisolate_lru_page().Also convert all users' logic of checking the isolation state.
No functional changes intended.
Signed-off-by Baolin Wang <[email protected]>--- mm/folio-compat.c | 12 +++--------- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/memcontrol.c | 4 ++-- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 2 +- mm/migrate.c | 9 ++++++--- mm/migrate_device.c | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-)
[...]
mm/memory_hotplug.c do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) · line 1671
Quoted 10 lines
mm/memory_hotplug.c +1
-1@@ -1668,7 +1668,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)* LRU and non-lru movable pages. */ if (PageLRU (page)) - ret =isolate_lru_page (page); + ret = !isolate_lru_page (page);
This may change return value of this function. That is, this function will return 1 instead of -EBUSY after this change. It's not a real issue as no caller of this function takes care of the return value, though.
Thanks,
SJ
Quoted 3 lines
mm/memory_hotplug.c +0
-0else ret =isolate_movable_page (page,ISOLATE_UNEVICTABLE );if (!ret) {/* Success */
[...]
Baolin Wang
reviewerRe: [PATCH v2 2/4] mm: change to return bool for isolate_lru_page()
Quoted 25 lines · SeongJae Park
Quoted 22 lines · On Tue, 14 Feb 2023 21:59:30 +0800 Baolin Wang…
The
isolate_lru_page()can only return 0 or-EBUSY, and most users did not care about the negative error ofisolate_lru_page(), except one user inadd_page_for_migration(). So we can convert theisolate_lru_page()to return a boolean value, which can help to make the code more clear when checking the return value ofisolate_lru_page().Also convert all users' logic of checking the isolation state.
No functional changes intended.
--- mm/folio-compat.c | 12 +++--------- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/memcontrol.c | 4 ++-- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 2 +- mm/migrate.c | 9 ++++++--- mm/migrate_device.c | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-)[...]
Quoted 14 lines
mm/memory_hotplug.c do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) · line 1671
Quoted 10 lines
mm/memory_hotplug.c +1
-1@@ -1668,7 +1668,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)* LRU and non-lru movable pages. */ if (PageLRU (page)) - ret =isolate_lru_page (page); + ret = !isolate_lru_page (page);This may change return value of this function. That is, this function will return 1 instead of
-EBUSYafter this change. It's not a real issue as no caller of this function takes care of the return value, though.
Yes, I've also thought about this. OK, I can keep the original logic here by adding a new variable. Thanks.
isolated = isolate_lru_page(page);
ret = isolated ? 0 : -EBUSY;
Baolin Wang
reviewerPATCH v2 3/4 mm: hugetlb: change to return bool for isolate_hugetlb()
In reply to Baolin WangNow the isolate_hugetlb() only returns 0 or -EBUSY, and most users did not care about the negative value, thus we can convert the isolate_hugetlb() to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned by isolate_hugetlb().
No functional changes intended.
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-)
include/linux/hugetlb.h +3 -3
@@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, vm_flags_t vm_flags);long hugetlb_unreserve_pages (struct inode *inode,long start,long end,long freed); -int isolate_hugetlb (struct folio *folio,struct list_head *list); +bool isolate_hugetlb (struct folio *folio,struct list_head *list);int get_hwpoison_hugetlb_folio (struct folio *folio,bool *hugetlb,bool unpoison);int get_huge_page_for_hwpoison (unsigned long pfn,int flags,bool *migratable_cleared);
@@ -413,9 +413,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,return NULL ; } -static inline int isolate_hugetlb (struct folio *folio,struct list_head *list) +static inline bool isolate_hugetlb (struct folio *folio,struct list_head *list) { -return -EBUSY ; +return false; }static inline int get_hwpoison_hugetlb_folio (struct folio *folio,bool *hugetlb,bool unpoison)
mm/hugetlb.c +8 -4
@@ -2932,6 +2932,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,spin_unlock_irq (&hugetlb_lock); ret =isolate_hugetlb (old_folio, list);spin_lock_irq (&hugetlb_lock); +if (!ret) + ret = -EBUSY ; +else + ret =0 ; goto free_new; }else if (!folio_test_hugetlb_freed (old_folio)) {/*
@@ -3005,7 +3009,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)if (hstate_is_gigantic (h))return -ENOMEM ; -if (folio_ref_count (folio) && !isolate_hugetlb (folio, list)) +if (folio_ref_count (folio) &&isolate_hugetlb (folio, list)) ret =0 ;else if (!folio_ref_count (folio)) ret =alloc_and_dissolve_hugetlb_folio (h, folio, list);
@@ -7251,15 +7255,15 @@ __weak unsigned long hugetlb_mask_last_page(struct hstate *h)* These functions are overwritable if your architecture needs its own * behavior. */ -int isolate_hugetlb (struct folio *folio,struct list_head *list) +bool isolate_hugetlb (struct folio *folio,struct list_head *list) { -int ret =0 ; +bool ret = true;spin_lock_irq (&hugetlb_lock);if (!folio_test_hugetlb (folio) || !folio_test_hugetlb_migratable (folio) || !folio_try_get (folio)) { - ret = -EBUSY ; + ret = false; goto unlock; }folio_clear_hugetlb_migratable (folio);
mm/memory-failure.c +1 -1
@@ -2508,7 +2508,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)bool isolated = false;if (PageHuge (page)) { - isolated = !isolate_hugetlb (page_folio (page), pagelist); + isolated =isolate_hugetlb (page_folio (page), pagelist); }else {bool lru = !__PageMovable (page);
mm/mempolicy.c +1 -1
@@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,if (flags & (MPOL_MF_MOVE_ALL ) || (flags &MPOL_MF_MOVE &&folio_estimated_sharers (folio) ==1 && !hugetlb_pmd_shared (pte))) { -if (isolate_hugetlb (folio, qp->pagelist) && +if (!isolate_hugetlb (folio, qp->pagelist) && (flags &MPOL_MF_STRICT ))/* * Failed to isolate folio but allow migrating pages
mm/migrate.c +1 -1
@@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,if (PageHead (page)) { err =isolate_hugetlb (page_folio (page), pagelist);if (!err) - err =1 ; + err = -EBUSY ; } }else {struct page *head;
Signature · 1 line
2.27.0
SeongJae Park
maintainerRe: [PATCH v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb()
Quoted 47 lines · On Tue, 14 Feb 2023 21:59:31 +0800 Baolin Wang…
Now the
isolate_hugetlb()only returns 0 or-EBUSY, and most users did not care about the negative value, thus we can convert theisolate_hugetlb()to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned byisolate_hugetlb().No functional changes intended.
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-)include/linux/hugetlb.h +3
-3@@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, vm_flags_t vm_flags);long hugetlb_unreserve_pages (struct inode *inode,long start,long end,long freed); -int isolate_hugetlb (struct folio *folio,struct list_head *list); +bool isolate_hugetlb (struct folio *folio,struct list_head *list);int get_hwpoison_hugetlb_folio (struct folio *folio,bool *hugetlb,bool unpoison);int get_huge_page_for_hwpoison (unsigned long pfn,int flags,bool *migratable_cleared);@@ -413,9 +413,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,return NULL ; } -static inline int isolate_hugetlb (struct folio *folio,struct list_head *list) +static inline bool isolate_hugetlb (struct folio *folio,struct list_head *list) { -return -EBUSY ; +return false; }static inline int get_hwpoison_hugetlb_folio (struct folio *folio,bool *hugetlb,bool unpoison)mm/hugetlb.c +0
-0
mm/hugetlb.c static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, · line 2938
Quoted 7 lines
mm/hugetlb.c +4
-0@@ -2932,6 +2932,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,spin_unlock_irq (&hugetlb_lock); ret =isolate_hugetlb (old_folio, list);spin_lock_irq (&hugetlb_lock); +if (!ret) + ret = -EBUSY ; +else + ret =0 ;
This would work, but 'ret' is not 'bool' but 'int'. How about below?
ret = isolate_hugetlb(old_folio, list) ? 0 : -EBUSY;
Quoted 62 lines
mm/hugetlb.c +4
-4goto free_new; }else if (!folio_test_hugetlb_freed (old_folio)) {/* @@ -3005,7 +3009,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)if (hstate_is_gigantic (h))return -ENOMEM ; -if (folio_ref_count (folio) && !isolate_hugetlb (folio, list)) +if (folio_ref_count (folio) &&isolate_hugetlb (folio, list)) ret =0 ;else if (!folio_ref_count (folio)) ret =alloc_and_dissolve_hugetlb_folio (h, folio, list);@@ -7251,15 +7255,15 @@ __weak unsigned long hugetlb_mask_last_page(struct hstate *h)* These functions are overwritable if your architecture needs its own * behavior. */ -int isolate_hugetlb (struct folio *folio,struct list_head *list) +bool isolate_hugetlb (struct folio *folio,struct list_head *list) { -int ret =0 ; +bool ret = true;spin_lock_irq (&hugetlb_lock);if (!folio_test_hugetlb (folio) || !folio_test_hugetlb_migratable (folio) || !folio_try_get (folio)) { - ret = -EBUSY ; + ret = false; goto unlock; }folio_clear_hugetlb_migratable (folio);mm/memory-failure.c +1
-1@@ -2508,7 +2508,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)bool isolated = false;if (PageHuge (page)) { - isolated = !isolate_hugetlb (page_folio (page), pagelist); + isolated =isolate_hugetlb (page_folio (page), pagelist); }else {bool lru = !__PageMovable (page);mm/mempolicy.c +1
-1@@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,if (flags & (MPOL_MF_MOVE_ALL ) || (flags &MPOL_MF_MOVE &&folio_estimated_sharers (folio) ==1 && !hugetlb_pmd_shared (pte))) { -if (isolate_hugetlb (folio, qp->pagelist) && +if (!isolate_hugetlb (folio, qp->pagelist) && (flags &MPOL_MF_STRICT ))/* * Failed to isolate folio but allow migrating pages mm/migrate.c +0
-0
mm/migrate.c static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, · line 2131
Quoted 5 lines
mm/migrate.c +1
-1@@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,if (PageHead (page)) { err =isolate_hugetlb (page_folio (page), pagelist);if (!err) - err =1 ; + err = -EBUSY ;
Again, I think this is confusing. 'err' is 'bool', not 'int'.
Thanks,
SJ
Quoted 6 lines
mm/migrate.c +0
-0} }else {struct page *head;Signature · 1 line
2.27.0
SeongJae Park
maintainerRe: [PATCH v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb()
Quoted 21 lines · On Tue, 14 Feb 2023 18:03:24 +0000 SeongJae Park <[email protected]> wrote:
Quoted 19 lines · On Tue, 14 Feb 2023 21:59:31 +0800 Baolin Wang <[email protected]>…
Now the
isolate_hugetlb()only returns 0 or-EBUSY, and most users did not care about the negative value, thus we can convert theisolate_hugetlb()to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned byisolate_hugetlb().No functional changes intended.
Signed-off-by Baolin Wang <[email protected]>--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-)include/linux/hugetlb.h +0
-0
[...]
Quoted 4 lines
Quoted 4 lines
mm/migrate.c +0
-0
Quoted 8 lines
mm/migrate.c static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, · line 2131
Quoted 6 lines
mm/migrate.c +1
-1@@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,if (PageHead (page)) { err =isolate_hugetlb (page_folio (page), pagelist);if (!err) - err =1 ; + err = -EBUSY ;Again, I think this is confusing. 'err' is 'bool', not 'int'.
I mean, 'err' is not 'bool' but 'int', sorry. See? This confuses me ;)
Thanks,
SJ
Quoted 11 lines
Thanks,
SJQuoted 6 lines
mm/migrate.c +0
-0} }else {struct page *head;Signature · 1 line
2.27.0
Re: [PATCH v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb()
Quoted 37 lines · SeongJae Park
Quoted 21 lines · On Tue, 14 Feb 2023 18:03:24 +0000 SeongJae Park…
Quoted 19 lines · On Tue, 14 Feb 2023 21:59:31 +0800 Baolin Wang…
Now the
isolate_hugetlb()only returns 0 or-EBUSY, and most users did not care about the negative value, thus we can convert theisolate_hugetlb()to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned byisolate_hugetlb().No functional changes intended.
--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-)include/linux/hugetlb.h +0
-0[...]
Quoted 4 lines
Quoted 4 lines
mm/migrate.c +0
-0Quoted 8 lines
mm/migrate.c static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, · line 2131
Quoted 6 lines
mm/migrate.c +1
-1@@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,if (PageHead (page)) { err =isolate_hugetlb (page_folio (page), pagelist);if (!err) - err =1 ; + err = -EBUSY ;Again, I think this is confusing. 'err' is 'bool', not 'int'.
Quoted 2 lines
I mean, 'err' is not 'bool' but 'int', sorry. See? This confuses me ;)
Yes,
in the case here (and elsewhere) I like David's suggestion of using a separate bool such as 'isolated' to capture the return value of the isolate function. Then, the statement:
err = isolated ? 0 : -EBUSY;
would be pretty clear.
Signature · 1 line
Mike Kravetz
Baolin Wang
reviewerRe: [PATCH v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb()
Quoted 41 lines · Mike Kravetz
Quoted 37 lines · SeongJae Park
Quoted 21 lines · On Tue, 14 Feb 2023 18:03:24 +0000 SeongJae Park <[email protected]> wrote:
Quoted 19 lines · On Tue, 14 Feb 2023 21:59:31 +0800 Baolin Wang <[email protected]>…
Now the
isolate_hugetlb()only returns 0 or-EBUSY, and most users did not care about the negative value, thus we can convert theisolate_hugetlb()to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned byisolate_hugetlb().No functional changes intended.
Signed-off-by Baolin Wang <[email protected]>--- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-)include/linux/hugetlb.h +0
-0[...]
Quoted 4 lines
Quoted 4 lines
mm/migrate.c +0
-0Quoted 8 lines
mm/migrate.c static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, · line 2131
Quoted 6 lines
mm/migrate.c +1
-1@@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,if (PageHead (page)) { err =isolate_hugetlb (page_folio (page), pagelist);if (!err) - err =1 ; + err = -EBUSY ;Again, I think this is confusing. 'err' is 'bool', not 'int'.
Quoted 2 lines
I mean, 'err' is not 'bool' but 'int', sorry. See? This confuses me ;)
Quoted 8 lines
Yes,
in the case here (and elsewhere) I like David's suggestion of using a separate bool such as 'isolated' to capture the return value of the isolate function. Then, the statement:err = isolated ? 0 : -EBUSY;would be pretty clear.
Yes, much better, will do. Thanks.
Baolin Wang
reviewerPATCH v2 4/4 mm: change to return bool for isolate_movable_page()
In reply to Baolin WangNow the isolate_movable_page() can only return 0 or -EBUSY, and no users will care about the negative return value, thus we can convert the isolate_movable_page() to return a boolean value to make the code more clear when checking the movable page isolation state.
No functional changes intended.
--- include/linux/migrate.h | 6 +++--- mm/compaction.c | 2 +- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 4 ++-- mm/migrate.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-)
include/linux/migrate.h +3 -3
@@ -71,7 +71,7 @@ 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, unsigned int *ret_succeeded);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 bool isolate_movable_page (struct page *page,isolate_mode_t mode);int migrate_huge_page_move_mapping (struct address_space *mapping,struct folio *dst,struct folio *src);
@@ -92,8 +92,8 @@ static inline int migrate_pages(struct list_head *l, new_page_t new,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 ; } +static inline bool isolate_movable_page (struct page *page,isolate_mode_t mode) + {return false; }static inline int migrate_huge_page_move_mapping (struct address_space *mapping,struct folio *dst,struct folio *src)
mm/compaction.c +1 -1
@@ -976,7 +976,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, locked =NULL ; } -if (!isolate_movable_page (page, mode)) +if (isolate_movable_page (page, mode)) goto isolate_success; }
mm/memory-failure.c +2 -2
@@ -2515,8 +2515,8 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)if (lru) isolated =isolate_lru_page (page);else - isolated = !isolate_movable_page (page, -ISOLATE_UNEVICTABLE ); + isolated =isolate_movable_page (page, +ISOLATE_UNEVICTABLE );if (isolated) {list_add (&page->lru, pagelist);
mm/memory_hotplug.c +2 -2
@@ -1668,10 +1668,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)* LRU and non-lru movable pages. */ if (PageLRU (page)) - ret = !isolate_lru_page (page); + ret =isolate_lru_page (page);else ret =isolate_movable_page (page,ISOLATE_UNEVICTABLE ); -if (!ret) {/* Success */ +if (ret) {/* Success */ list_add_tail (&page->lru, &source);if (!__PageMovable (page)) inc_node_page_state(page, NR_ISOLATED_ANON +
mm/migrate.c +3 -3
@@ -58,7 +58,7 @@#include "internal.h" -int isolate_movable_page (struct page *page,isolate_mode_t mode) +bool isolate_movable_page (struct page *page,isolate_mode_t mode) {struct folio *folio =folio_get_nontail_page (page);const struct movable_operations *mops;
@@ -119,14 +119,14 @@ int isolate_movable_page(struct page *page, isolate_mode_t mode)folio_set_isolated (folio);folio_unlock (folio); -return 0 ; +return true; out_no_isolated:folio_unlock (folio); out_putfolio:folio_put (folio); out: -return -EBUSY ; +return false; }static void putback_movable_folio (struct folio *folio)
Signature · 1 line
2.27.0
Quoted 14 lines · Baolin Wang
Now the page isolation functions did not return a boolean to indicate success or not, instead it will return a negative error when failed to isolate a page. So below code used in most places seem a boolean success/failure thing, which can confuse people whether the isolation is successful.
if (
folio_isolate_lru(folio))continue;Moreover the page isolation functions only return 0 or
-EBUSY, and most users did not care about the negative error except for few users, thus we can convert all page isolation functions to return a boolean value, which can remove the confusion to make code more clear.
Quoted 4 lines
No functional changes intended in this patch series.
Changes from v1:
- Convert all isolation functions to return bool.
Although it's controversial if
if (!ret)
ret = -EBUSY; else ret = 0;
is really appealing to the readers eye :)
ret = ret ? 0 : -EBUSY;
It's still confusing.
would be better as
ret = isolated ? 0 : -EBUSY;
IOW, not reusing the "int ret" variable.
Signature · 3 lines
Thanks, David / dhildenb
Baolin Wang
reviewerQuoted 15 lines · David Hildenbrand
Quoted 14 lines · Baolin Wang
Now the page isolation functions did not return a boolean to indicate success or not, instead it will return a negative error when failed to isolate a page. So below code used in most places seem a boolean success/failure thing, which can confuse people whether the isolation is successful.
if (
folio_isolate_lru(folio))
continue;Moreover the page isolation functions only return 0 or
-EBUSY, and most users did not care about the negative error except for few users, thus we can convert all page isolation functions to return a boolean value, which can remove the confusion to make code more clear.
Quoted 6 lines
Quoted 4 lines
No functional changes intended in this patch series.
Changes from v1:
- Convert all isolation functions to return bool.
Thanks.
Quoted 12 lines
Although it's controversial if
if (!ret)
ret =-EBUSY;
else
ret = 0;is really appealing to the readers eye :)
ret = ret ? 0 :
-EBUSY;
Quoted 7 lines
It's still confusing.
would be better as
ret = isolated ? 0 :
-EBUSY;IOW, not reusing the "int ret" variable.
Yes, pretty clear. Will do in next version.