Skip to content

Commit be2d575

Browse files
Baolin Wangakpm00
authored andcommitted
mm: change to return bool for folio_isolate_lru()
Patch series "Change the return value for page isolation functions", v3. 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. This patch (of 4): 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]/ Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/8a4e3679ed4196168efadf7ea36c038f2f7d5aa9.1676424378.git.baolin.wang@linux.alibaba.com Signed-off-by: Baolin Wang <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Acked-by: Linus Torvalds <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Muchun Song <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Shakeel Butt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d5d4692 commit be2d575

File tree

8 files changed

+19
-13
lines changed

8 files changed

+19
-13
lines changed

mm/damon/paddr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)
246246

247247
folio_clear_referenced(folio);
248248
folio_test_clear_young(folio);
249-
if (folio_isolate_lru(folio)) {
249+
if (!folio_isolate_lru(folio)) {
250250
folio_put(folio);
251251
continue;
252252
}

mm/folio-compat.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,15 @@ EXPORT_SYMBOL(grab_cache_page_write_begin);
115115

116116
int isolate_lru_page(struct page *page)
117117
{
118+
bool ret;
119+
118120
if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page"))
119121
return -EBUSY;
120-
return folio_isolate_lru((struct folio *)page);
122+
ret = folio_isolate_lru((struct folio *)page);
123+
if (ret)
124+
return 0;
125+
126+
return -EBUSY;
121127
}
122128

123129
void putback_lru_page(struct page *page)

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ static unsigned long collect_longterm_unpinnable_pages(
19391939
drain_allow = false;
19401940
}
19411941

1942-
if (folio_isolate_lru(folio))
1942+
if (!folio_isolate_lru(folio))
19431943
continue;
19441944

19451945
list_add_tail(&folio->lru, movable_page_list);

mm/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
188188
* in mm/vmscan.c:
189189
*/
190190
int isolate_lru_page(struct page *page);
191-
int folio_isolate_lru(struct folio *folio);
191+
bool folio_isolate_lru(struct folio *folio);
192192
void putback_lru_page(struct page *page);
193193
void folio_putback_lru(struct folio *folio);
194194
extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason);

mm/khugepaged.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
19501950
goto out_unlock;
19511951
}
19521952

1953-
if (folio_isolate_lru(folio)) {
1953+
if (!folio_isolate_lru(folio)) {
19541954
result = SCAN_DEL_PAGE_LRU;
19551955
goto out_unlock;
19561956
}

mm/madvise.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
406406
folio_clear_referenced(folio);
407407
folio_test_clear_young(folio);
408408
if (pageout) {
409-
if (!folio_isolate_lru(folio)) {
409+
if (folio_isolate_lru(folio)) {
410410
if (folio_test_unevictable(folio))
411411
folio_putback_lru(folio);
412412
else
@@ -500,7 +500,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd,
500500
folio_clear_referenced(folio);
501501
folio_test_clear_young(folio);
502502
if (pageout) {
503-
if (!folio_isolate_lru(folio)) {
503+
if (folio_isolate_lru(folio)) {
504504
if (folio_test_unevictable(folio))
505505
folio_putback_lru(folio);
506506
else

mm/mempolicy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static int migrate_folio_add(struct folio *folio, struct list_head *foliolist,
10331033
* expensive, so check the estimated mapcount of the folio instead.
10341034
*/
10351035
if ((flags & MPOL_MF_MOVE_ALL) || folio_estimated_sharers(folio) == 1) {
1036-
if (!folio_isolate_lru(folio)) {
1036+
if (folio_isolate_lru(folio)) {
10371037
list_add_tail(&folio->lru, foliolist);
10381038
node_stat_mod_folio(folio,
10391039
NR_ISOLATED_ANON + folio_is_file_lru(folio),

mm/vmscan.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,12 +2337,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan,
23372337
* (2) The lru_lock must not be held.
23382338
* (3) Interrupts must be enabled.
23392339
*
2340-
* Return: 0 if the folio was removed from an LRU list.
2341-
* -EBUSY if the folio was not on an LRU list.
2340+
* Return: true if the folio was removed from an LRU list.
2341+
* false if the folio was not on an LRU list.
23422342
*/
2343-
int folio_isolate_lru(struct folio *folio)
2343+
bool folio_isolate_lru(struct folio *folio)
23442344
{
2345-
int ret = -EBUSY;
2345+
bool ret = false;
23462346

23472347
VM_BUG_ON_FOLIO(!folio_ref_count(folio), folio);
23482348

@@ -2353,7 +2353,7 @@ int folio_isolate_lru(struct folio *folio)
23532353
lruvec = folio_lruvec_lock_irq(folio);
23542354
lruvec_del_folio(lruvec, folio);
23552355
unlock_page_lruvec_irq(lruvec);
2356-
ret = 0;
2356+
ret = true;
23572357
}
23582358

23592359
return ret;

0 commit comments

Comments
 (0)