Skip to content

Commit 9747b9e

Browse files
Baolin Wangakpm00
authored andcommitted
mm: hugetlb: change to return bool for isolate_hugetlb()
Now 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. [[email protected]: shorten locked section, per SeongJae Park] Link: https://lkml.kernel.org/r/12a287c5bebc13df304387087bbecc6421510849.1676424378.git.baolin.wang@linux.alibaba.com Signed-off-by: Baolin Wang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Acked-by: Linus Torvalds <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent f7f9c00 commit 9747b9e

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

include/linux/hugetlb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to,
171171
vm_flags_t vm_flags);
172172
long hugetlb_unreserve_pages(struct inode *inode, long start, long end,
173173
long freed);
174-
int isolate_hugetlb(struct folio *folio, struct list_head *list);
174+
bool isolate_hugetlb(struct folio *folio, struct list_head *list);
175175
int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison);
176176
int get_huge_page_for_hwpoison(unsigned long pfn, int flags,
177177
bool *migratable_cleared);
@@ -413,9 +413,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
413413
return NULL;
414414
}
415415

416-
static inline int isolate_hugetlb(struct folio *folio, struct list_head *list)
416+
static inline bool isolate_hugetlb(struct folio *folio, struct list_head *list)
417417
{
418-
return -EBUSY;
418+
return false;
419419
}
420420

421421
static inline int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison)

mm/hugetlb.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,12 +2925,15 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h,
29252925
*/
29262926
goto free_new;
29272927
} else if (folio_ref_count(old_folio)) {
2928+
bool isolated;
2929+
29282930
/*
29292931
* Someone has grabbed the folio, try to isolate it here.
29302932
* Fail with -EBUSY if not possible.
29312933
*/
29322934
spin_unlock_irq(&hugetlb_lock);
2933-
ret = isolate_hugetlb(old_folio, list);
2935+
isolated = isolate_hugetlb(old_folio, list);
2936+
ret = isolated ? 0 : -EBUSY;
29342937
spin_lock_irq(&hugetlb_lock);
29352938
goto free_new;
29362939
} else if (!folio_test_hugetlb_freed(old_folio)) {
@@ -3005,7 +3008,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list)
30053008
if (hstate_is_gigantic(h))
30063009
return -ENOMEM;
30073010

3008-
if (folio_ref_count(folio) && !isolate_hugetlb(folio, list))
3011+
if (folio_ref_count(folio) && isolate_hugetlb(folio, list))
30093012
ret = 0;
30103013
else if (!folio_ref_count(folio))
30113014
ret = alloc_and_dissolve_hugetlb_folio(h, folio, list);
@@ -7251,15 +7254,15 @@ __weak unsigned long hugetlb_mask_last_page(struct hstate *h)
72517254
* These functions are overwritable if your architecture needs its own
72527255
* behavior.
72537256
*/
7254-
int isolate_hugetlb(struct folio *folio, struct list_head *list)
7257+
bool isolate_hugetlb(struct folio *folio, struct list_head *list)
72557258
{
7256-
int ret = 0;
7259+
bool ret = true;
72577260

72587261
spin_lock_irq(&hugetlb_lock);
72597262
if (!folio_test_hugetlb(folio) ||
72607263
!folio_test_hugetlb_migratable(folio) ||
72617264
!folio_try_get(folio)) {
7262-
ret = -EBUSY;
7265+
ret = false;
72637266
goto unlock;
72647267
}
72657268
folio_clear_hugetlb_migratable(folio);

mm/memory-failure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)
25082508
bool isolated = false;
25092509

25102510
if (PageHuge(page)) {
2511-
isolated = !isolate_hugetlb(page_folio(page), pagelist);
2511+
isolated = isolate_hugetlb(page_folio(page), pagelist);
25122512
} else {
25132513
bool lru = !__PageMovable(page);
25142514

mm/mempolicy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask,
609609
if (flags & (MPOL_MF_MOVE_ALL) ||
610610
(flags & MPOL_MF_MOVE && folio_estimated_sharers(folio) == 1 &&
611611
!hugetlb_pmd_shared(pte))) {
612-
if (isolate_hugetlb(folio, qp->pagelist) &&
612+
if (!isolate_hugetlb(folio, qp->pagelist) &&
613613
(flags & MPOL_MF_STRICT))
614614
/*
615615
* Failed to isolate folio but allow migrating pages

mm/migrate.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
20952095
struct vm_area_struct *vma;
20962096
struct page *page;
20972097
int err;
2098+
bool isolated;
20982099

20992100
mmap_read_lock(mm);
21002101
err = -EFAULT;
@@ -2126,13 +2127,11 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
21262127

21272128
if (PageHuge(page)) {
21282129
if (PageHead(page)) {
2129-
err = isolate_hugetlb(page_folio(page), pagelist);
2130-
if (!err)
2131-
err = 1;
2130+
isolated = isolate_hugetlb(page_folio(page), pagelist);
2131+
err = isolated ? 1 : -EBUSY;
21322132
}
21332133
} else {
21342134
struct page *head;
2135-
bool isolated;
21362135

21372136
head = compound_head(page);
21382137
isolated = isolate_lru_page(head);

0 commit comments

Comments
 (0)