Skip to content

Commit f7f9c00

Browse files
Baolin Wangakpm00
authored andcommitted
mm: change to return bool for isolate_lru_page()
The 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. Link: https://lkml.kernel.org/r/3074c1ab628d9dbf139b33f248a8bc253a3f95f0.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]> Acked-by: Linus Torvalds <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent be2d575 commit f7f9c00

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

mm/folio-compat.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,11 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping,
113113
}
114114
EXPORT_SYMBOL(grab_cache_page_write_begin);
115115

116-
int isolate_lru_page(struct page *page)
116+
bool isolate_lru_page(struct page *page)
117117
{
118-
bool ret;
119-
120118
if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"))
121-
return -EBUSY;
122-
ret = folio_isolate_lru((struct folio *)page);
123-
if (ret)
124-
return 0;
125-
126-
return -EBUSY;
119+
return false;
120+
return folio_isolate_lru((struct folio *)page);
127121
}
128122

129123
void putback_lru_page(struct page *page)

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
187187
/*
188188
* in mm/vmscan.c:
189189
*/
190-
int isolate_lru_page(struct page *page);
190+
bool isolate_lru_page(struct page *page);
191191
bool folio_isolate_lru(struct folio *folio);
192192
void putback_lru_page(struct page *page);
193193
void folio_putback_lru(struct folio *folio);

mm/khugepaged.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
636636
* Isolate the page to avoid collapsing an hugepage
637637
* currently in use by the VM.
638638
*/
639-
if (isolate_lru_page(page)) {
639+
if (!isolate_lru_page(page)) {
640640
unlock_page(page);
641641
result = SCAN_DEL_PAGE_LRU;
642642
goto out;

mm/memcontrol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6176,7 +6176,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd,
61766176
target_type = get_mctgt_type_thp(vma, addr, *pmd, &target);
61776177
if (target_type == MC_TARGET_PAGE) {
61786178
page = target.page;
6179-
if (!isolate_lru_page(page)) {
6179+
if (isolate_lru_page(page)) {
61806180
if (!mem_cgroup_move_account(page, true,
61816181
mc.from, mc.to)) {
61826182
mc.precharge -= HPAGE_PMD_NR;
@@ -6226,7 +6226,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd,
62266226
*/
62276227
if (PageTransCompound(page))
62286228
goto put;
6229-
if (!device && isolate_lru_page(page))
6229+
if (!device && !isolate_lru_page(page))
62306230
goto put;
62316231
if (!mem_cgroup_move_account(page, false,
62326232
mc.from, mc.to)) {

mm/memory-failure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ static const char * const action_page_types[] = {
846846
*/
847847
static int delete_from_lru_cache(struct page *p)
848848
{
849-
if (!isolate_lru_page(p)) {
849+
if (isolate_lru_page(p)) {
850850
/*
851851
* Clear sensible page flags, so that the buddy system won't
852852
* complain when the page is unpoison-and-freed.
@@ -2513,7 +2513,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist)
25132513
bool lru = !__PageMovable(page);
25142514

25152515
if (lru)
2516-
isolated = !isolate_lru_page(page);
2516+
isolated = isolate_lru_page(page);
25172517
else
25182518
isolated = !isolate_movable_page(page,
25192519
ISOLATE_UNEVICTABLE);

mm/memory_hotplug.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
16321632

16331633
for (pfn = start_pfn; pfn < end_pfn; pfn++) {
16341634
struct folio *folio;
1635+
bool isolated;
16351636

16361637
if (!pfn_valid(pfn))
16371638
continue;
@@ -1667,9 +1668,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
16671668
* We can skip free pages. And we can deal with pages on
16681669
* LRU and non-lru movable pages.
16691670
*/
1670-
if (PageLRU(page))
1671-
ret = isolate_lru_page(page);
1672-
else
1671+
if (PageLRU(page)) {
1672+
isolated = isolate_lru_page(page);
1673+
ret = isolated ? 0 : -EBUSY;
1674+
} else
16731675
ret = isolate_movable_page(page, ISOLATE_UNEVICTABLE);
16741676
if (!ret) { /* Success */
16751677
list_add_tail(&page->lru, &source);

mm/migrate.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,11 +2132,14 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
21322132
}
21332133
} else {
21342134
struct page *head;
2135+
bool isolated;
21352136

21362137
head = compound_head(page);
2137-
err = isolate_lru_page(head);
2138-
if (err)
2138+
isolated = isolate_lru_page(head);
2139+
if (!isolated) {
2140+
err = -EBUSY;
21392141
goto out_putpage;
2142+
}
21402143

21412144
err = 1;
21422145
list_add_tail(&head->lru, pagelist);
@@ -2541,7 +2544,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page)
25412544
return 0;
25422545
}
25432546

2544-
if (isolate_lru_page(page))
2547+
if (!isolate_lru_page(page))
25452548
return 0;
25462549

25472550
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page),

mm/migrate_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns,
388388
allow_drain = false;
389389
}
390390

391-
if (isolate_lru_page(page)) {
391+
if (!isolate_lru_page(page)) {
392392
src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
393393
restore++;
394394
continue;

0 commit comments

Comments
 (0)