From: "Garg, Shivank" <shivankg@amd.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"David Hildenbrand (Red Hat)" <davidhildenbrandkernel@gmail.com>,
Lance Yang <lance.yang@linux.dev>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
zokeefe@google.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: madvise(MADV_COLLAPSE) fails with EINVAL on dirty file-backed text pages
Date: Fri, 7 Nov 2025 18:16:12 +0530 [thread overview]
Message-ID: <a41b57f6-08d6-4af0-8383-7ba3b90c1acb@amd.com> (raw)
In-Reply-To: <671d07a0-0041-4825-9e6e-978907cb4d29@lucifer.local>
On 11/7/2025 3:40 PM, Lorenzo Stoakes wrote:
> On Fri, Nov 07, 2025 at 10:12:02AM +0100, David Hildenbrand (Red Hat) wrote:
>>
>>>
>>> 5. Yes, I'm calling madvise(MADV_COLLAPSE) on the text portion of the executable, using the address
>>> range obtained from /proc/self/maps. IIUC, this should benefit applications by reducing ITLB pressure.
>>>
>>> I agree with the suggestions to either Return EAGAIN instead of EINVAL or At minimum, document the
>>> EINVAL return for dirty pages. I'm happy to work on a patch.
>>
>> Of course, we could detect that we are in MADV_COLLAPSE and simply writeback ourselves. After all,
>> user space asked for a collapse, and it's not khugepaged that will simple revisit it later.
>>
>> I did something similar in
>>
>> commit ab73b29efd36f8916c6cc9954e912c4723c9a1b0
>> Author: David Hildenbrand <david@redhat.com>
>> Date: Fri May 16 14:39:46 2025 +0200
>>
>> s390/uv: Improve splitting of large folios that cannot be split while dirty
>> Currently, starting a PV VM on an iomap-based filesystem with large
>> folio support, such as XFS, will not work. We'll be stuck in
>> unpack_one()->gmap_make_secure(), because we can't seem to make progress
>> splitting the large folio.
>>
>> Where I effectively use filemap_write_and_wait_range().
>>
>> It could be used early to writeback the whole range to collapse once, possibly.
>
> I agree, let's just do a sync flush unconditionally and fix this that way.
>
> This is simpler than I thought, the key bit of information is that we have
> freshly written the executable so it sits in the page cache but dirty.
>
> Thanks, Lorenzo
Thanks David for sharing the commit. This worked for me and fix is simple.
+ if (!is_shmem && !cc->is_khugepaged && mapping_can_writeback(mapping)) {
+ loff_t range_start = start << PAGE_SHIFT;
+ loff_t range_end = (end << PAGE_SHIFT) - 1;
+ int ret;
+
+ ret = filemap_write_and_wait_range(mapping, range_start, range_end);
+ if (ret) {
+ result = SCAN_FAIL;
+ goto out;
+ }
+ }
I'll do some more testing and post a cleaned-up version with proper comments; rebase on mm-next.
Thanks,
Shivank
next prev parent reply other threads:[~2025-11-07 12:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-06 12:16 Garg, Shivank
2025-11-06 12:55 ` Lance Yang
2025-11-06 13:03 ` Nico Pache
2025-11-06 16:32 ` Ryan Roberts
2025-11-06 16:55 ` Liam R. Howlett
2025-11-06 17:17 ` Lorenzo Stoakes
2025-11-06 21:05 ` David Hildenbrand (Red Hat)
2025-11-07 8:51 ` Garg, Shivank
2025-11-07 9:12 ` David Hildenbrand (Red Hat)
2025-11-07 10:09 ` Lance Yang
2025-11-07 10:10 ` Lorenzo Stoakes
2025-11-07 12:46 ` Garg, Shivank [this message]
2025-11-07 10:09 ` Lorenzo Stoakes
2025-11-07 12:50 ` Lorenzo Stoakes
2025-11-06 20:32 ` Yang Shi
2025-11-07 9:44 ` Garg, Shivank
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=a41b57f6-08d6-4af0-8383-7ba3b90c1acb@amd.com \
--to=shivankg@amd.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=davidhildenbrandkernel@gmail.com \
--cc=dev.jain@arm.com \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=npache@redhat.com \
--cc=ryan.roberts@arm.com \
--cc=vbabka@suse.cz \
--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