From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Matthew Wilcox <willy@infradead.org>,
Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>, Zi Yan <ziy@nvidia.com>,
"Liam R . Howlett" <liam@infradead.org>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] khugepaged: hold invalidate_lock across collapse_file() readahead
Date: Mon, 14 Sep 2026 11:14:37 +0800 [thread overview]
Message-ID: <8fbfb29d-ecbb-4561-990d-4e1a1b677d75@linux.alibaba.com> (raw)
In-Reply-To: <aqck8rfGByZhdtqT@casper.infradead.org>
On 9/14/26 6:34 AM, Matthew Wilcox wrote:
> On Sun, Sep 13, 2026 at 11:36:44PM +0700, Nguyen Ngoc Thang wrote:
>> @@ -2271,6 +2272,15 @@ static enum scan_result collapse_file(struct mm_struct *mm, unsigned long addr,
>> if (result != SCAN_SUCCEED)
>> goto out;
>>
>> + /*
>> + * Take invalidate_lock before any folio lock: the readahead below
>> + * needs it, and truncate holds it while waiting on folio locks.
>> + */
>> + if (!is_shmem) {
>> + filemap_invalidate_lock_shared(mapping);
>> + need_unlock = true;
>> + }
>
> I'm not a fan of all this surplus commentary. And what happens if e
> simultaeneously truncate a shmem file and collapse it at the same time?
> I know it doesn't use the invalidate lock, but does it go wrong in some
> other way?
IIUC, shmem uses the folio lock to synchronize truncate and collapse. It
will check whether truncation has occurred after taking the folio lock
in shmem_get_folio_gfp():
folio_lock(folio);
/* Has the folio been truncated or swapped out? */
if (unlikely(folio->mapping != inode->i_mapping)) {
folio_unlock(folio);
folio_put(folio);
goto repeat;
}
So shmem looks safe here, unless I'm missing something.
next prev parent reply other threads:[~2026-09-14 3:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 10:11 [PATCH] " Nguyen Ngoc Thang
2026-09-13 16:12 ` Lance Yang
2026-09-13 16:16 ` Lance Yang
2026-09-13 16:31 ` Zi Yan
2026-09-13 16:36 ` [PATCH v2] " Nguyen Ngoc Thang
2026-09-13 18:17 ` Andrew Morton
2026-09-13 18:48 ` Lorenzo Stoakes (ARM)
2026-09-13 18:49 ` Lorenzo Stoakes (ARM)
2026-09-14 14:19 ` David Hildenbrand (Arm)
2026-09-14 16:58 ` Mike Rapoport
2026-09-13 22:34 ` Matthew Wilcox
2026-09-14 3:14 ` Baolin Wang [this message]
2026-09-13 18:43 ` [PATCH] " Lorenzo Stoakes (ARM)
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=8fbfb29d-ecbb-4561-990d-4e1a1b677d75@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--cc=nico.pache@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=usama.arif@linux.dev \
--cc=willy@infradead.org \
--cc=ziy@nvidia.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
all inboxes | Powered by JetHome®