mm: change to return bool for folio_isolate_lru()
authorBaolin Wang <baolin.wang@linux.alibaba.com>
Wed, 15 Feb 2023 10:39:34 +0000 (18:39 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 20 Feb 2023 20:46:17 +0000 (12:46 -0800)
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/20230131063206.28820-1-Kuan-Ying.Lee@mediatek.com/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/Y+sTFqwMNAjDvxw3@casper.infradead.org/

Link: https://lkml.kernel.org/r/cover.1676424378.git.baolin.wang@linux.alibaba.com
Link: https://lkml.kernel.org/r/8a4e3679ed4196168efadf7ea36c038f2f7d5aa9.1676424378.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeelb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/paddr.c
mm/folio-compat.c
mm/gup.c
mm/internal.h
mm/khugepaged.c
mm/madvise.c
mm/mempolicy.c
mm/vmscan.c

index b4df9b9bcc0a1b871eff60a2eec4d8fefcefafdd..607bb69e526cf9d659274b333c921ad0f602348b 100644 (file)
@@ -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;
                }
index 18c48b55792635344668aff076d60a2376479d43..540373cf904e99de77fb7ae5837e0cbd6fc86674 100644 (file)
@@ -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)
index b0885f70579c5ac63a34d47c83ec3687e4f47345..eab18ba045dbefccd212759088d8d90f5415d02e 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -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);
index dfb37e94e140c62361091564c2870367a1cc041c..8645e8496537fe5294174ff3d94ab83afef7be6a 100644 (file)
@@ -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);
index bd54b957f69a7f27b750000cb2bfa013f04e635a..15eebab0fbb5b5244b5c6806ac8d2d0d80ec4bc8 100644 (file)
@@ -1950,7 +1950,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;
                }
index 5a5a687d03c24d79ab5ba3ce6c639b6ba8a1d999..c2202f51e9ddf6aa41b881f58a676e61b25613ab 100644 (file)
@@ -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 @@ regular_folio:
                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
index 0919c7a719d419225f00db1b093287ba6d850e94..2751bc3310fd67da2f81acff4a6567a3f67bd158 100644 (file)
@@ -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),
index 098c79129c426b6a05b016e68bd6f04513742256..9c1c5e8b24b8f56fe05d8d3883ce17ffaa2eb7f3 100644 (file)
@@ -2337,12 +2337,12 @@ move:
  * (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;