linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: "Garg, Shivank" <shivankg@amd.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>, Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Nico Pache <npache@redhat.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Zach O'Keefe <zokeefe@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm/khugepaged: return EAGAIN for transient dirty pages in MADV_COLLAPSE
Date: Wed, 19 Nov 2025 18:16:28 +0000	[thread overview]
Message-ID: <0efa89a3-2080-4daa-a190-2ced8e14ed9d@lucifer.local> (raw)
In-Reply-To: <a2770a50-5732-4483-b958-4693f0f08c7e@amd.com>

On Wed, Nov 19, 2025 at 03:55:29PM +0530, Garg, Shivank wrote:
>
>
> On 11/10/2025 5:26 PM, Lorenzo Stoakes wrote:
> > Please, please, please send a cover letter when there's > 1 patch :)
> >
> > This 2/2 replying to 1/2 is a pain (not your fault that perhaps you're not aware
> > of typical mm series style but FYI :P)
> >
> Sure, will do this in V2 (posting today).
>
> > Also there is some tiny conflict on khugepaged.c in mm-new, but it's literally 1
> > #include so probably nothing to worry about.
> > > On Mon, Nov 10, 2025 at 11:32:55AM +0000, Shivank Garg wrote:
> >> When MADV_COLLAPSE encounters dirty file-backed pages, it currently
> >> returns -EINVAL, this is misleading as EINVAL suggests invalid arguments,
> >> whereas dirty pages are a transient condition that may resolve on retry.
> >>
> >> Introduce SCAN_PAGE_DIRTY and map it to -EAGAIN. For khugepaged, this
> >> is harmless as it will revisit the range after async writeback completes.
> >>
> >> Signed-off-by: Shivank Garg <shivankg@amd.com>
> >
> > With comments below addressed, LGTM so:
> >
> > Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>
> Thank you for the review.
> >
> >> ---
> >>  include/trace/events/huge_memory.h | 3 ++-
> >>  mm/khugepaged.c                    | 4 +++-
> >>  2 files changed, 5 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h
> >> index dd94d14a2427..9014a9bbe64c 100644
> >> --- a/include/trace/events/huge_memory.h
> >> +++ b/include/trace/events/huge_memory.h
> >> @@ -38,7 +38,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_DIRTY,		"page_dirty")
> >>
> >>  #undef EM
> >>  #undef EMe
> >> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> >> index d08ed6eb9ce1..7df329c9c87d 100644
> >> --- a/mm/khugepaged.c
> >> +++ b/mm/khugepaged.c
> >> @@ -60,6 +60,7 @@ enum scan_result {
> >>  	SCAN_STORE_FAILED,
> >>  	SCAN_COPY_MC,
> >>  	SCAN_PAGE_FILLED,
> >> +	SCAN_PAGE_DIRTY,
> >
> > it feels like a lot to add a scan result for this, but I mean... probably
> > actually valid.
> >
> >>  };
> >>
> >>  #define CREATE_TRACE_POINTS
> >> @@ -1967,7 +1968,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
> >>  				 */
> >>  				xas_unlock_irq(&xas);
> >>  				filemap_flush(mapping);
> >> -				result = SCAN_FAIL;
> >> +				result = SCAN_PAGE_DIRTY;
> >>  				goto xa_unlocked;
> >
> > Hmmm shmem dirty is going to be weird but we also have:
> >
> > 		if (!is_shmem && (folio_test_dirty(folio) ||
> > 				  folio_test_writeback(folio))) {
> > 			/*
> > 			 * khugepaged only works on read-only fd, so this
> > 			 * folio is dirty because it hasn't been flushed
> > 			 * since first write.
> > 			 */
> > 			result = SCAN_FAIL;
> > 			goto out_unlock;
> > 		}
> >
> > It's weird though, why would we have writeback, surely handled by swap, and
> > won't it be like anon, i.e. pretty well always dirty? This comment seems
> > copy/pasta wrong.
> >
> > We do need to at least mention in commit message that shmem is explicitly
> > excluded.
> >
>
> Looking at the code, the dirty/writeback checks where I'm making changes
> are all in the !is_shmem branch, so it only affects regular files, not
> shmem.

Yeah sorry I think I was being somehow blind to the fact that each
dirty/writeback test has !is_shmem, esp. given I literally quote it there :)

So err ignore me I think here haha

>
> Should I mention in the commit message that these changes are limited
> to regular files and don't affect shmem?

No that's fine.

>
> I'm not sure I fully understood your concern on shmem. Could you please elaborate?

Yeah I think I just misread the code after a long day :P

>
> Thanks,
> Shivank

Cheers, Lorenzo

>
>
> >
> >>  			} else if (folio_test_writeback(folio)) {
> >>  				xas_unlock_irq(&xas);
> >> @@ -2747,6 +2748,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_DIRTY:
> >>  		return -EAGAIN;
> >>  	/*
> >>  	 * Other: Trying again likely not to succeed / error intrinsic to
> >> --
> >> 2.43.0
> >>
>


  reply	other threads:[~2025-11-19 18:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10 11:32 [PATCH 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE Shivank Garg
2025-11-10 11:32 ` [PATCH 2/2] mm/khugepaged: return EAGAIN for transient dirty pages in MADV_COLLAPSE Shivank Garg
2025-11-10 11:56   ` Lorenzo Stoakes
2025-11-19 10:25     ` Garg, Shivank
2025-11-19 18:16       ` Lorenzo Stoakes [this message]
2025-11-20  7:03         ` Garg, Shivank
2025-11-10 13:46   ` Dev Jain
2025-11-19  7:00     ` Garg, Shivank
2025-11-10 12:01 ` [PATCH 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE Lorenzo Stoakes
2025-11-10 13:07   ` Garg, Shivank
2025-11-10 13:22     ` Lorenzo Stoakes
2025-11-10 16:06       ` Lorenzo Stoakes
2025-11-10 16:55         ` Zi Yan
2025-11-10 19:40           ` Garg, Shivank
2025-11-10 19:48             ` Lorenzo Stoakes
2025-11-10 19:53               ` Lorenzo Stoakes
2025-11-10 21:16                 ` Lorenzo Stoakes
2025-11-10 21:56                   ` Zi Yan
2025-11-10 22:03                     ` Lorenzo Stoakes
2025-11-11  5:26                   ` Garg, Shivank
2025-11-10 13:24   ` Dev Jain
2025-11-10 13:36     ` Lorenzo Stoakes
2025-11-11  3:41       ` Dev Jain
2025-11-10 13:47 ` Matthew Wilcox
2025-11-10 13:52   ` Lorenzo Stoakes
2025-11-10 14:17     ` Matthew Wilcox
2025-11-10 14:20     ` Garg, Shivank
2025-11-10 14:23       ` Lorenzo Stoakes
2025-11-10 14:28       ` Matthew Wilcox
2025-11-11  5:58         ` Garg, Shivank
2025-11-13 15:30           ` David Hildenbrand (Red Hat)
2025-11-10 14:00   ` David Hildenbrand (Red Hat)
2025-11-10 14:03     ` Matthew Wilcox
2025-11-10 14:05       ` Lorenzo Stoakes
2025-11-10 14:54         ` David Hildenbrand (Red Hat)
2025-11-13 14:21 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0efa89a3-2080-4daa-a190-2ced8e14ed9d@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=npache@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=ryan.roberts@arm.com \
    --cc=shivankg@amd.com \
    --cc=ziy@nvidia.com \
    --cc=zokeefe@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).