* [PATCH 0/3] Some cleanups for page isolation
@ 2023-02-14 3:18 Baolin Wang
2023-02-14 3:18 ` [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio Baolin Wang
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Baolin Wang @ 2023-02-14 3:18 UTC (permalink / raw)
To: akpm
Cc: torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, baolin.wang, damon, cgroups, linux-mm, linux-kernel
Hi,
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 it's better to check the negative error explicitly
for isolation to make the code more clear per Linus's suggestion in [1].
No functional changes intended in this patch series.
[1] https://lore.kernel.org/all/CAHk-=wiBrY+O-4=2mrbVyxR+hOqfdJ=Do6xoucfJ9_5az01L4Q@mail.gmail.com/
Baolin Wang (3):
mm: check negative error of folio_isolate_lru() when failed to isolate
a folio
mm: check negative error of isolate_lru_page() when failed to isolate
a page
mm: mempolicy: check negative error of isolate_hugetlb() when failed
to isolate a hugetlb
mm/damon/paddr.c | 2 +-
mm/gup.c | 2 +-
mm/khugepaged.c | 4 ++--
mm/memcontrol.c | 2 +-
mm/mempolicy.c | 2 +-
mm/migrate.c | 4 ++--
mm/migrate_device.c | 2 +-
7 files changed, 9 insertions(+), 9 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio
2023-02-14 3:18 [PATCH 0/3] Some cleanups for page isolation Baolin Wang
@ 2023-02-14 3:18 ` Baolin Wang
2023-02-14 3:18 ` [PATCH 2/3] mm: check negative error of isolate_lru_page() when failed to isolate a page Baolin Wang
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2023-02-14 3:18 UTC (permalink / raw)
To: akpm
Cc: torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, baolin.wang, damon, cgroups, linux-mm, linux-kernel
The folio_isolate_lru() will return a negative error if failed to isolate
a folio from its LRU list, thus better to check the negative error to
make the code more clear per Linus's suggestion[1].
No functional changes.
[1] https://lore.kernel.org/all/CAHk-=wiBrY+O-4=2mrbVyxR+hOqfdJ=Do6xoucfJ9_5az01L4Q@mail.gmail.com/
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/damon/paddr.c | 2 +-
mm/gup.c | 2 +-
mm/khugepaged.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index b4df9b9bcc0a..ebf3dd084af2 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -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) < 0) {
folio_put(folio);
continue;
}
diff --git a/mm/gup.c b/mm/gup.c
index b0885f70579c..7fdddd43663c 100644
--- 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) < 0)
continue;
list_add_tail(&folio->lru, movable_page_list);
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index a5d32231bfad..463dfca4b841 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -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) < 0) {
result = SCAN_DEL_PAGE_LRU;
goto out_unlock;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] mm: check negative error of isolate_lru_page() when failed to isolate a page
2023-02-14 3:18 [PATCH 0/3] Some cleanups for page isolation Baolin Wang
2023-02-14 3:18 ` [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio Baolin Wang
@ 2023-02-14 3:18 ` Baolin Wang
2023-02-14 3:18 ` [PATCH 3/3] mm: mempolicy: check negative error of isolate_hugetlb() when failed to isolate a hugetlb Baolin Wang
2023-02-14 4:50 ` [PATCH 0/3] Some cleanups for page isolation Matthew Wilcox
3 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2023-02-14 3:18 UTC (permalink / raw)
To: akpm
Cc: torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, baolin.wang, damon, cgroups, linux-mm, linux-kernel
Better to check the negative error of isolate_lru_page() when failed to
isolate a page from its LRU, which makes the code more clear.
No functional changes.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/khugepaged.c | 2 +-
mm/memcontrol.c | 2 +-
mm/migrate.c | 4 ++--
mm/migrate_device.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 463dfca4b841..99a2d993b51c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -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) < 0) {
unlock_page(page);
result = SCAN_DEL_PAGE_LRU;
goto out;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 17335459d8dc..33cad66a4132 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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) < 0)
goto put;
if (!mem_cgroup_move_account(page, false,
mc.from, mc.to)) {
diff --git a/mm/migrate.c b/mm/migrate.c
index ef68a1aff35c..eaae39564f86 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2135,7 +2135,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
head = compound_head(page);
err = isolate_lru_page(head);
- if (err)
+ if (err < 0)
goto out_putpage;
err = 1;
@@ -2541,7 +2541,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) < 0)
return 0;
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page),
diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index 6c3740318a98..1ab56b5b7914 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -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) < 0) {
src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
restore++;
continue;
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] mm: mempolicy: check negative error of isolate_hugetlb() when failed to isolate a hugetlb
2023-02-14 3:18 [PATCH 0/3] Some cleanups for page isolation Baolin Wang
2023-02-14 3:18 ` [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio Baolin Wang
2023-02-14 3:18 ` [PATCH 2/3] mm: check negative error of isolate_lru_page() when failed to isolate a page Baolin Wang
@ 2023-02-14 3:18 ` Baolin Wang
2023-02-14 4:50 ` [PATCH 0/3] Some cleanups for page isolation Matthew Wilcox
3 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2023-02-14 3:18 UTC (permalink / raw)
To: akpm
Cc: torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, baolin.wang, damon, cgroups, linux-mm, linux-kernel
Better to check the negative error of isolate_hugetlb() when failed to
isolate a hugetlb page, which makes the code more clear.
No functional changes.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/mempolicy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 0919c7a719d4..e3d87b21516b 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -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) < 0 &&
(flags & MPOL_MF_STRICT))
/*
* Failed to isolate folio but allow migrating pages
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] Some cleanups for page isolation
2023-02-14 3:18 [PATCH 0/3] Some cleanups for page isolation Baolin Wang
` (2 preceding siblings ...)
2023-02-14 3:18 ` [PATCH 3/3] mm: mempolicy: check negative error of isolate_hugetlb() when failed to isolate a hugetlb Baolin Wang
@ 2023-02-14 4:50 ` Matthew Wilcox
2023-02-14 6:49 ` Baolin Wang
3 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2023-02-14 4:50 UTC (permalink / raw)
To: Baolin Wang
Cc: akpm, torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, damon, cgroups, linux-mm, linux-kernel
On Tue, Feb 14, 2023 at 11:18:05AM +0800, Baolin Wang wrote:
> 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 it's better to check the negative error explicitly
> for isolation to make the code more clear per Linus's suggestion in [1].
Only one caller of isolate_lru_page() or folio_isolate_lru() actually
uses the errno. And the errno can only be 0 or -EBUSY. It'd be
better to change the three functions to return bool and fix
add_page_for_migration() to set the errno to -EBUSY itself.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] Some cleanups for page isolation
2023-02-14 4:50 ` [PATCH 0/3] Some cleanups for page isolation Matthew Wilcox
@ 2023-02-14 6:49 ` Baolin Wang
0 siblings, 0 replies; 6+ messages in thread
From: Baolin Wang @ 2023-02-14 6:49 UTC (permalink / raw)
To: Matthew Wilcox
Cc: akpm, torvalds, sj, hannes, mhocko, roman.gushchin, shakeelb,
muchun.song, damon, cgroups, linux-mm, linux-kernel
On 2/14/2023 12:50 PM, Matthew Wilcox wrote:
> On Tue, Feb 14, 2023 at 11:18:05AM +0800, Baolin Wang wrote:
>> 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 it's better to check the negative error explicitly
>> for isolation to make the code more clear per Linus's suggestion in [1].
>
> Only one caller of isolate_lru_page() or folio_isolate_lru() actually
> uses the errno. And the errno can only be 0 or -EBUSY. It'd be
> better to change the three functions to return bool and fix
> add_page_for_migration() to set the errno to -EBUSY itself.
Sounds reasonable to me, and I can change them to return bool in next
version. Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-02-14 6:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 3:18 [PATCH 0/3] Some cleanups for page isolation Baolin Wang
2023-02-14 3:18 ` [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio Baolin Wang
2023-02-14 3:18 ` [PATCH 2/3] mm: check negative error of isolate_lru_page() when failed to isolate a page Baolin Wang
2023-02-14 3:18 ` [PATCH 3/3] mm: mempolicy: check negative error of isolate_hugetlb() when failed to isolate a hugetlb Baolin Wang
2023-02-14 4:50 ` [PATCH 0/3] Some cleanups for page isolation Matthew Wilcox
2023-02-14 6:49 ` Baolin Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).