mm/khugepaged: fix dirty page handling for MADV_COLLAPSE
Subsystems (3)
v2 cover mm/khugepaged: fix dirty page handling for MADV_COLLAPSE
MADV_COLLAPSE on file-backed mappings fails with -EINVAL when TEXT pages are dirty. This may affect real scenarios: package/container updates, executing binaries immediately after writing them, etc.
The issue is that collapse_file() triggers async writeback and returns SCAN_FAIL (maps to -EINVAL), expecting khugepaged to revisit later. But MADV_COLLAPSE is synchronous and userspace expects immediate success or a clear retry signal.
Reproduction:
- Copy 2MB-aligned executable to freshly mounted XFS/ext4
- Call MADV_COLLAPSE on .text section
- First call fails with -EINVAL (text pages dirty from copy)
- Second call succeeds (async writeback completed)
Issue Report:
https://lore.kernel.org/all/[email protected]
v2:
- Move writeback to madvise_collapse() (better abstraction, proper mmap_lock handling and does VMA revalidation after I/O) (Lorenzo)
- Rename to SCAN_PAGE_DIRTY to SCAN_PAGE_NOT_CLEAN and extend its use for all dirty/writeback folio cases that previously returned incorrect results (Dev)
v1: https://lore.kernel.org/all/[email protected]
Shivank Garg (2):
mm/khugepaged: do synchronous writeback for MADV_COLLAPSE mm/khugepaged: map dirty/writeback pages failures to EAGAIN
include/trace/events/huge_memory.h | 3 ++- mm/khugepaged.c | 34 +++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-)
base-commit: 4a3f8fc3adb7046e44bd1feb2f5c5fe95296894f
Signature · 1 line
2.43.0
PATCH v2 1/2 mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
When MADV_COLLAPSE is called on file-backed mappings (e.g., executable text sections), the pages may still be dirty from recent writes and cause collapse to fail with -EINVAL. This is particularly problematic for freshly copied executables on filesystems, where page cache folios remain dirty until background writeback completes.
The current code in collapse_file() triggers async writeback via filemap_flush() and expects khugepaged to revisit the page later. However, MADV_COLLAPSE is a synchronous operation where userspace expects immediate results.
Perform synchronous writeback in madvise_collapse() before attempting collapse to avoid failing on first attempt.
--- mm/khugepaged.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
mm/khugepaged.c +26 -0
@@ -22,6 +22,7 @@#include <linux/dax.h> #include <linux/ksm.h> #include <linux/pgalloc.h> +#include <linux/backing-dev.h> #include <asm/tlb.h> #include "internal.h"
@@ -2784,6 +2785,31 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hstart = (start + ~HPAGE_PMD_MASK ) &HPAGE_PMD_MASK ; hend = end &HPAGE_PMD_MASK ; +/* +* For file-backed VMAs, perform synchronous writeback to ensure +* dirty folios are flushed before attempting collapse. This avoids +* failing on the first attempt when freshly-written executable text +* is still dirty in the page cache. +*/ +if (!vma_is_anonymous (vma) && vma->vm_file) { +struct address_space *mapping = vma->vm_file->f_mapping; + +if (mapping_can_writeback (mapping)) { +pgoff_t pgoff_start =linear_page_index (vma, hstart); +pgoff_t pgoff_end =linear_page_index (vma, hend); +loff_t lstart = (loff_t )pgoff_start <<PAGE_SHIFT ; +loff_t lend = ((loff_t )pgoff_end <<PAGE_SHIFT ) -1 ; + +mmap_read_unlock (mm); + mmap_locked = false; + +if (filemap_write_and_wait_range (mapping, lstart, lend)) { + last_fail =SCAN_FAIL ; + goto out_maybelock; + } + } + } +for (addr = hstart; addr < hend; addr +=HPAGE_PMD_SIZE ) {int result =SCAN_FAIL ;
Signature · 1 line
2.43.0
Lance Yang
reviewerRe: [PATCH V2 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
Quoted 6 lines · Shivank Garg
When
MADV_COLLAPSEis called on file-backed mappings (e.g., executable text sections), the pages may still be dirty from recent writes and cause collapse to fail with-EINVAL. This is particularly problematic for freshly copied executables on filesystems, where page cache folios remain dirty until background writeback completes.
Quoted 7 lines
The current code in
collapse_file()triggers async writeback viafilemap_flush()and expects khugepaged to revisit the page later. However,MADV_COLLAPSEis a synchronous operation where userspace expects immediate results.Perform synchronous writeback in
madvise_collapse()before attempting collapse to avoid failing on first attempt.
Thanks!
Quoted 30 lines
Reported-by Branden Moore <[email protected]>Fixes 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")Suggested-by David Hildenbrand <[email protected]>Signed-off-by Shivank Garg <[email protected]>--- mm/khugepaged.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)mm/khugepaged.c +5
-0@@ -22,6 +22,7 @@#include <linux/dax.h> #include <linux/ksm.h> #include <linux/pgalloc.h> +#include <linux/backing-dev.h> #include <asm/tlb.h> #include "internal.h" @@ -2784,6 +2785,31 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hstart = (start + ~HPAGE_PMD_MASK ) &HPAGE_PMD_MASK ; hend = end &HPAGE_PMD_MASK ; +/* +* For file-backed VMAs, perform synchronous writeback to ensure +* dirty folios are flushed before attempting collapse. This avoids +* failing on the first attempt when freshly-written executable text
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2801
Quoted 10 lines
mm/khugepaged.c +10
-0+* is still dirty in the page cache. +*/ +if (!vma_is_anonymous (vma) && vma->vm_file) { +struct address_space *mapping = vma->vm_file->f_mapping; + +if (mapping_can_writeback (mapping)) { +pgoff_t pgoff_start =linear_page_index (vma, hstart); +pgoff_t pgoff_end =linear_page_index (vma, hend); +loff_t lstart = (loff_t )pgoff_start <<PAGE_SHIFT ; +loff_t lend = ((loff_t )pgoff_end <<PAGE_SHIFT ) -1 ;
It looks like we need to hold a reference to the file here before dropping the mmap lock :)
file = get_file(vma->vm_file);
Without it, the vma could be destroyed by a concurrent munmap() while we are waiting in filemap_write_and_wait_range(), leading to a UAF on mapping, IIUC ...
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2806
Quoted 5 lines
mm/khugepaged.c +5
-0+ +mmap_read_unlock (mm); + mmap_locked = false; + +if (filemap_write_and_wait_range (mapping, lstart, lend)) {
And drop the reference :)
fput(file);
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2809
Quoted 3 lines
mm/khugepaged.c +3
-0+ last_fail =SCAN_FAIL ; + goto out_maybelock; + }
Same here :)
fput(file);
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2815
Quoted 6 lines
mm/khugepaged.c +3
-0+ } + } +for (addr = hstart; addr < hend; addr +=HPAGE_PMD_SIZE ) {int result =SCAN_FAIL ;
Cheers,
Lance
Re: [PATCH V2 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
Quoted 61 lines · Lance Yang
Quoted 6 lines · Shivank Garg
When
MADV_COLLAPSEis called on file-backed mappings (e.g., executable text sections), the pages may still be dirty from recent writes and cause collapse to fail with-EINVAL. This is particularly problematic for freshly copied executables on filesystems, where page cache folios remain dirty until background writeback completes.Quoted 7 lines
The current code in
collapse_file()triggers async writeback viafilemap_flush()and expects khugepaged to revisit the page later. However,MADV_COLLAPSEis a synchronous operation where userspace expects immediate results.Perform synchronous writeback in
madvise_collapse()before attempting collapse to avoid failing on first attempt.Thanks!
Quoted 30 lines
Reported-by Branden Moore <[email protected]>Fixes 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")Suggested-by David Hildenbrand <[email protected]>Signed-off-by Shivank Garg <[email protected]>---
mm/khugepaged.c| 26 ++++++++++++++++++++++++++1 file changed, 26 insertions(+)mm/khugepaged.c +1
-0@@ -22,6 +22,7 @@ #include <linux/dax.h> #include <linux/ksm.h> #include <linux/pgalloc.h> +#include <linux/backing-dev.h> #include <asm/tlb.h> #include "internal.h"@@ -2784,6 +2785,31 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; hend = end & HPAGE_PMD_MASK;+ /*
+ * For file-backed VMAs, perform synchronous writeback to ensure + * dirty folios are flushed before attempting collapse. This avoids + * failing on the first attempt when freshly-written executable text + * is still dirty in the page cache.
+ */Quoted 8 lines
+ if (!vma_is_anonymous(vma) &&
vma->vm_file) {
+ structaddress_space*mapping =vma->vm_file->f_mapping; +
+ if (mapping_can_writeback(mapping)) {
+pgoff_tpgoff_start=linear_page_index(vma, hstart); +pgoff_tpgoff_end=linear_page_index(vma, hend); +loff_tlstart = (loff_t)pgoff_start <<PAGE_SHIFT; +loff_tlend = ((loff_t)pgoff_end <<PAGE_SHIFT) - 1;It looks like we need to hold a reference to the file here before dropping the mmap lock :)
Quoted 5 lines
file =
get_file(vma->vm_file);Without it, the vma could be destroyed by a concurrent
munmap()while we are waiting infilemap_write_and_wait_range(), leading to a UAF on mapping, IIUC ...
Excellent catch!
Thanks for saving me from this nasty bug. I'll be more careful on file ref handling in next version.
Best Regards,
Shivank
Quoted 30 lines
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2806
Quoted 6 lines
mm/khugepaged.c +5
-0+ + mmap_read_unlock(mm); + mmap_locked = false; + + if (filemap_write_and_wait_range(mapping, lstart, lend)) {And drop the reference :)
fput(file);
Quoted 3 lines
+
last_fail=SCAN_FAIL;
+ gotoout_maybelock;
+ }Same here :)
fput(file);
Quoted 6 lines
+ }
+ }
+
for (addr = hstart; addr < hend; addr +=HPAGE_PMD_SIZE) { int result =SCAN_FAIL;Cheers,
Lance
David Hildenbrand (Red Hat)
maintainerRe: [PATCH V2 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
In reply to Shivank GargQuoted 44 lines · Shivank Garg
When
MADV_COLLAPSEis called on file-backed mappings (e.g., executable text sections), the pages may still be dirty from recent writes and cause collapse to fail with-EINVAL. This is particularly problematic for freshly copied executables on filesystems, where page cache folios remain dirty until background writeback completes.The current code in
collapse_file()triggers async writeback viafilemap_flush()and expects khugepaged to revisit the page later. However,MADV_COLLAPSEis a synchronous operation where userspace expects immediate results.Perform synchronous writeback in
madvise_collapse()before attempting collapse to avoid failing on first attempt.Reported-by Branden Moore <[email protected]>Fixes 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")Suggested-by David Hildenbrand <[email protected]>Signed-off-by Shivank Garg <[email protected]>--- mm/khugepaged.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)mm/khugepaged.c +6
-0@@ -22,6 +22,7 @@#include <linux/dax.h> #include <linux/ksm.h> #include <linux/pgalloc.h> +#include <linux/backing-dev.h> #include <asm/tlb.h> #include "internal.h" @@ -2784,6 +2785,31 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hstart = (start + ~HPAGE_PMD_MASK ) &HPAGE_PMD_MASK ; hend = end &HPAGE_PMD_MASK ; +/* +* For file-backed VMAs, perform synchronous writeback to ensure +* dirty folios are flushed before attempting collapse. This avoids +* failing on the first attempt when freshly-written executable text +* is still dirty in the page cache.
mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2802
Quoted 10 lines
mm/khugepaged.c +10
-0+*/ +if (!vma_is_anonymous (vma) && vma->vm_file) { +struct address_space *mapping = vma->vm_file->f_mapping; + +if (mapping_can_writeback (mapping)) { +pgoff_t pgoff_start =linear_page_index (vma, hstart); +pgoff_t pgoff_end =linear_page_index (vma, hend); +loff_t lstart = (loff_t )pgoff_start <<PAGE_SHIFT ; +loff_t lend = ((loff_t )pgoff_end <<PAGE_SHIFT ) -1 ; +
Hm, so we always do that, without any indication that there actually is something dirty there.
Internally filemap_write_and_wait_range() uses something called mapping_needs_writeback(), but it also applies to the complete file, not a range.
Wouldn't it be better do do that only if we detect that there is actually a dirty folio in the range?
That is, if we find any dirty folio in hpage_collapse_scan_file() and we are in madvise, do that dance here and retry?
Signature · 3 lines
Cheers David
Re: [PATCH V2 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
Quoted 56 lines · David Hildenbrand (Red Hat)
Quoted 45 lines · Shivank Garg
When
MADV_COLLAPSEis called on file-backed mappings (e.g., executable text sections), the pages may still be dirty from recent writes and cause collapse to fail with-EINVAL. This is particularly problematic for freshly copied executables on filesystems, where page cache folios remain dirty until background writeback completes.The current code in
collapse_file()triggers async writeback viafilemap_flush()and expects khugepaged to revisit the page later. However,MADV_COLLAPSEis a synchronous operation where userspace expects immediate results.Perform synchronous writeback in
madvise_collapse()before attempting collapse to avoid failing on first attempt.Reported-by Branden Moore <[email protected]>Fixes 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE")Suggested-by David Hildenbrand <[email protected]>Signed-off-by Shivank Garg <[email protected]>---
mm/khugepaged.c| 26 ++++++++++++++++++++++++++1 file changed, 26 insertions(+)mm/khugepaged.c +1
-0@@ -22,6 +22,7 @@ #include <linux/dax.h> #include <linux/ksm.h> #include <linux/pgalloc.h> +#include <linux/backing-dev.h> #include <asm/tlb.h> #include "internal.h"@@ -2784,6 +2785,31 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start, hstart = (start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; hend = end & HPAGE_PMD_MASK;+ /*
+ * For file-backed VMAs, perform synchronous writeback to ensure + * dirty folios are flushed before attempting collapse. This avoids + * failing on the first attempt when freshly-written executable text + * is still dirty in the page cache.
+ */
+ if (!vma_is_anonymous(vma) &&vma->vm_file) {
+ structaddress_space*mapping =vma->vm_file->f_mapping;mm/khugepaged.c int madvise_collapse(struct vm_area_struct *vma, unsigned long start, · line 2802
Quoted 7 lines
mm/khugepaged.c +7
-0+ + if (mapping_can_writeback(mapping)) { + pgoff_t pgoff_start = linear_page_index(vma, hstart); + pgoff_t pgoff_end = linear_page_index(vma, hend); + loff_t lstart = (loff_t)pgoff_start << PAGE_SHIFT; + loff_t lend = ((loff_t)pgoff_end << PAGE_SHIFT) - 1; +Hm, so we always do that, without any indication that there actually is something dirty there.
Quoted 6 lines
Internally
filemap_write_and_wait_range()uses something calledmapping_needs_writeback(), but it also applies to the complete file, not a range.Wouldn't it be better do do that only if we detect that there is actually a dirty folio in the range?
That is, if we find any dirty folio in
hpage_collapse_scan_file()and we are in madvise, do that dance here and retry?
Good point! This makes sense to me.
I'll send V3 with this approach.
Thanks,
Shivank
PATCH v2 2/2 mm/khugepaged: map dirty/writeback pages failures to EAGAIN
In reply to Shivank GargWhen collapse_file encounters dirty or writeback pages in file-backed mappings, it currently SCAN_FAIL which maps to -EINVAL. This is misleading as EINVAL suggests invalid arguments, whereas dirty/writeback pages represent transient conditions that may resolve on retry.
Introduce SCAN_PAGE_NOT_CLEAN to cover both dirty and writeback states, mapping it to -EAGAIN. For MADV_COLLAPSE, this provides userspace with a clear signal that retry may succeed after writeback completes, making -EAGAIN semantically correct. For khugepaged, this is harmless as it will naturally revisit the range during periodic scans after async writeback completes.
--- include/trace/events/huge_memory.h | 3 ++- mm/khugepaged.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
include/trace/events/huge_memory.h +2 -1
@@ -37,7 +37,8 @@ EM( SCAN_PAGE_HAS_PRIVATE, "page_has_private") \ EM( SCAN_STORE_FAILED, "store_failed") \ EM( SCAN_COPY_MC, "copy_poisoned_page") \ - EMe(SCAN_PAGE_FILLED, "page_filled") + EM( SCAN_PAGE_FILLED, "page_filled") \ + EMe(SCAN_PAGE_NOT_CLEAN, "page_not_clean")#undef EM#undef EMe
mm/khugepaged.c +5 -3
@@ -59,6 +59,7 @@ enum scan_result {SCAN_STORE_FAILED ,SCAN_COPY_MC ,SCAN_PAGE_FILLED , + SCAN_PAGE_NOT_CLEAN, };#define CREATE_TRACE_POINTS
@@ -1968,11 +1969,11 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,*/ xas_unlock_irq (&xas);filemap_flush (mapping); - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto xa_unlocked; }else if (folio_test_writeback (folio)) {xas_unlock_irq (&xas); - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto xa_unlocked; }else if (folio_trylock (folio)) {folio_get (folio);
@@ -2019,7 +2020,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,* folio is dirty because it hasn't been flushed * since first write. */ - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto out_unlock; }
@@ -2748,6 +2749,7 @@ static int madvise_collapse_errno(enum scan_result r)case SCAN_PAGE_LRU :case SCAN_DEL_PAGE_LRU :case SCAN_PAGE_FILLED : +case SCAN_PAGE_NOT_CLEAN :return -EAGAIN ;/* * Other: Trying again likely not to succeed / error intrinsic to
Signature · 1 line
2.43.0
Re: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
Quoted 68 lines · Shivank Garg
When
collapse_fileencounters dirty or writeback pages in file-backed mappings, it currentlySCAN_FAILwhich maps to-EINVAL. This is misleading as EINVAL suggests invalid arguments, whereas dirty/writeback pages represent transient conditions that may resolve on retry.Introduce
SCAN_PAGE_NOT_CLEANto cover both dirty and writeback states, mapping it to-EAGAIN. ForMADV_COLLAPSE, this provides userspace with a clear signal that retry may succeed after writeback completes, making-EAGAINsemantically correct. For khugepaged, this is harmless as it will naturally revisit the range during periodic scans after async writeback completes.Signed-off-by Shivank Garg <[email protected]>--- include/trace/events/huge_memory.h | 3 ++- mm/khugepaged.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-)include/trace/events/huge_memory.h +2
-1@@ -37,7 +37,8 @@ EM( SCAN_PAGE_HAS_PRIVATE, "page_has_private") \ EM( SCAN_STORE_FAILED, "store_failed") \ EM( SCAN_COPY_MC, "copy_poisoned_page") \ - EMe(SCAN_PAGE_FILLED, "page_filled") + EM( SCAN_PAGE_FILLED, "page_filled") \ + EMe(SCAN_PAGE_NOT_CLEAN, "page_not_clean")#undef EM#undef EMemm/khugepaged.c +4
-3@@ -59,6 +59,7 @@ enum scan_result {SCAN_STORE_FAILED ,SCAN_COPY_MC ,SCAN_PAGE_FILLED , + SCAN_PAGE_NOT_CLEAN, };#define CREATE_TRACE_POINTS @@ -1968,11 +1969,11 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,*/ xas_unlock_irq (&xas);filemap_flush (mapping); - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto xa_unlocked; }else if (folio_test_writeback (folio)) {xas_unlock_irq (&xas); - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto xa_unlocked; }else if (folio_trylock (folio)) {folio_get (folio);@@ -2019,7 +2020,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,* folio is dirty because it hasn't been flushed * since first write. */ - result =SCAN_FAIL ; + result =SCAN_PAGE_NOT_CLEAN ; goto out_unlock; }
mm/khugepaged.c static int madvise_collapse_errno(enum scan_result r) · line 2755
Quoted 7 lines
mm/khugepaged.c +1
-0@@ -2748,6 +2749,7 @@ static int madvise_collapse_errno(enum scan_result r)case SCAN_PAGE_LRU :case SCAN_DEL_PAGE_LRU :case SCAN_PAGE_FILLED : +case SCAN_PAGE_NOT_CLEAN :return -EAGAIN ;/* * Other: Trying again likely not to succeed / error intrinsic to
SCAN_PAGE_NOT_CLEAN is confusing - NOT_CLEAN literally means dirty, so why not SCAN_PAGE_DIRTY? Or SCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Since folio_test_writeback() is true as a result of the folio being dirty, maybe just SCAN_PAGE_DIRTY can do.
Re: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
Quoted 9 lines · Dev Jain
On 20/11/25 12:20 pm, Shivank Garg wrote:
SCAN_PAGE_NOT_CLEANis confusing -NOT_CLEANliterally means dirty, so why notSCAN_PAGE_DIRTY? OrSCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Sincefolio_test_writeback()is true as a result of the folio being dirty, maybe justSCAN_PAGE_DIRTYcan do.Reviewed-by Dev Jain <[email protected]>
Thanks for the review.
I chose not to use SCAN_PAGE_DIRTY because dirty and writeback have different meanings[1]:
Dirty: Memory that is waiting to be written back to disk
Writeback: Memory that is actively being written back to disk
[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
IIUC, a page under writeback is no longer dirty, so using SCAN_PAGE_DIRTY would be misleading for pages in the writeback state.
I considered SCAN_PAGE_DIRTY_OR_WRITEBACK initially but felt it was too long.
SCAN_PAGE_NOT_CLEAN covers both states that indicate the page is not in a clean/stable state suitable for collapse.
[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
Thanks,
Shivank
Dev Jain
reviewerRe: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
Quoted 21 lines · Shivank
Quoted 7 lines · Dev Jain
On 20/11/25 12:20 pm, Shivank Garg wrote:
SCAN_PAGE_NOT_CLEANis confusing -NOT_CLEANliterally means dirty, so why notSCAN_PAGE_DIRTY? OrSCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Sincefolio_test_writeback()is true as a result of the folio being dirty, maybe justSCAN_PAGE_DIRTYcan do.Reviewed-by Dev Jain <[email protected]>Thanks for the review.
I chose not to use
SCAN_PAGE_DIRTYbecause dirty and writeback have different meanings[1]:Dirty: Memory that is waiting to be written back to disk
Writeback: Memory that is actively being written back to disk[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
IIUC, a page under writeback is no longer dirty, so using
SCAN_PAGE_DIRTYwould be misleading for pages in the writeback state.
Quoted 6 lines
I considered
SCAN_PAGE_DIRTY_OR_WRITEBACKinitially but felt it was too long.
SCAN_PAGE_NOT_CLEANcovers both states that indicate the page is not in a clean/stable state suitable for collapse.[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
Alright, makes sense.
Quoted 3 lines
Thanks,
Shivank
Re: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
In reply to Garg, ShivankQuoted 19 lines · Shivank
Quoted 9 lines · Dev Jain
On 20/11/25 12:20 pm, Shivank Garg wrote:
SCAN_PAGE_NOT_CLEANis confusing -NOT_CLEANliterally means dirty, so why notSCAN_PAGE_DIRTY? OrSCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Sincefolio_test_writeback()is true as a result of the folio being dirty, maybe justSCAN_PAGE_DIRTYcan do.Reviewed-by Dev Jain <[email protected]>Thanks for the review.
I chose not to use
SCAN_PAGE_DIRTYbecause dirty and writeback have different meanings[1]:Dirty: Memory that is waiting to be written back to disk
Writeback: Memory that is actively being written back to disk
Quoted 6 lines
[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
IIUC, a page under writeback is no longer dirty, so using
SCAN_PAGE_DIRTYwould be misleading for pages in the writeback state.I considered
SCAN_PAGE_DIRTY_OR_WRITEBACKinitially but felt it was too long.
Nit: If SCAN_PAGE_DIRTY_OR_WRITEBACK is too verbose, how about SCAN_PAGE_DIRTY_WB?
It keeps the specificity without the length, and is arguably more descriptive than NOT_CLEAN ;)
That said, LGTM.
Quoted 8 lines
SCAN_PAGE_NOT_CLEANcovers both states that indicate the page is not in a clean/stable state suitable for collapse.[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
Thanks,
Shivank
David Hildenbrand (Red Hat)
maintainerRe: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
Quoted 22 lines · Lance Yang
Quoted 19 lines · Shivank
Quoted 9 lines · Dev Jain
On 20/11/25 12:20 pm, Shivank Garg wrote:
SCAN_PAGE_NOT_CLEANis confusing -NOT_CLEANliterally means dirty, so why notSCAN_PAGE_DIRTY? OrSCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Sincefolio_test_writeback()is true as a result of the folio being dirty, maybe justSCAN_PAGE_DIRTYcan do.Reviewed-by Dev Jain <[email protected]>Thanks for the review.
I chose not to use
SCAN_PAGE_DIRTYbecause dirty and writeback have different meanings[1]:Dirty: Memory that is waiting to be written back to disk
Writeback: Memory that is actively being written back to disk
Quoted 8 lines
Quoted 6 lines
[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
IIUC, a page under writeback is no longer dirty, so using
SCAN_PAGE_DIRTYwould be misleading for pages in the writeback state.I considered
SCAN_PAGE_DIRTY_OR_WRITEBACKinitially but felt it was too long.Nit: If
SCAN_PAGE_DIRTY_OR_WRITEBACK
I would prefer that here.
Signature · 3 lines
Cheers David
Re: [PATCH V2 2/2] mm/khugepaged: map dirty/writeback pages failures to EAGAIN
Quoted 25 lines · David Hildenbrand (Red Hat)
Quoted 24 lines · Lance Yang
Quoted 21 lines · Shivank
Quoted 9 lines · Dev Jain
On 20/11/25 12:20 pm, Shivank Garg wrote:
SCAN_PAGE_NOT_CLEANis confusing -NOT_CLEANliterally means dirty, so why notSCAN_PAGE_DIRTY? OrSCAN_PAGE_DIRTY_OR_UNDER_WRITEBACK? Sincefolio_test_writeback()is true as a result of the folio being dirty, maybe justSCAN_PAGE_DIRTYcan do.Reviewed-by Dev Jain <[email protected]>Thanks for the review.
I chose not to use
SCAN_PAGE_DIRTYbecause dirty and writeback have different meanings[1]:Dirty: Memory that is waiting to be written back to disk
Writeback: Memory that is actively being written back to disk[1] https://www.kernel.org/doc/Documentation/filesystems/proc.txt
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
IIUC, a page under writeback is no longer dirty, so using
SCAN_PAGE_DIRTYwould be misleading for pages in the writeback state.I considered
SCAN_PAGE_DIRTY_OR_WRITEBACKinitially but felt it was too long.Nit: If
SCAN_PAGE_DIRTY_OR_WRITEBACKI would prefer that here.
I agree on this.
If the consensus is SCAN_PAGE_DIRTY_OR_WRITEBACK, I'll use it in v3.
Thanks,
Shivank