From: Zi Yan <ziy@nvidia.com>
To: <linux-mm@kvack.org>, Andrew Morton <akpm@linux-foundation.org>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
Hugh Dickins <hughd@google.com>,
David Hildenbrand <david@redhat.com>,
Yang Shi <yang@os.amperecomputing.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
Yu Zhao <yuzhao@google.com>, John Hubbard <jhubbard@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
<linux-kselftest@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Zi Yan <ziy@nvidia.com>, Kairui Song <kasong@tencent.com>
Subject: Re: [PATCH v9 7/8] mm/truncate: use buddy allocator like folio split for truncate operation
Date: Sat, 01 Mar 2025 22:52:59 -0500 [thread overview]
Message-ID: <56EBE3B6-99EA-470E-B2B3-92C9C13032DF@nvidia.com> (raw)
In-Reply-To: <20250226210032.2044041-8-ziy@nvidia.com>
On 26 Feb 2025, at 16:00, Zi Yan wrote:
> Instead of splitting the large folio uniformly during truncation, try to
> use buddy allocator like split at the start of truncation range to
> minimize the number of resulting folios if it is supported.
> try_folio_split() is introduced to use folio_split() if supported and fall
> back to uniform split otherwise.
>
> For example, to truncate a order-4 folio
> [0, 1, 2, 3, 4, 5, ..., 15]
> between [3, 10] (inclusive), folio_split() splits the folio to
> [0,1], [2], [3], [4..7], [8..15] and [3], [4..7] can be dropped and
> [8..15] is kept with zeros in [8..10], then another folio_split() is
> done at 10, so [8..10] can be dropped.
>
> One possible optimization is to make folio_split() to split a folio based
> on a given range, like [3..10] above. But that complicates folio_split(),
> so it will be investigated when necessary.
>
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
> Cc: Kirill A. Shuemov <kirill.shutemov@linux.intel.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Miaohe Lin <linmiaohe@huawei.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Yang Shi <yang@os.amperecomputing.com>
> Cc: Yu Zhao <yuzhao@google.com>
> Cc: Kairui Song <kasong@tencent.com>
> ---
> include/linux/huge_mm.h | 36 ++++++++++++++++++++++++++++++++++++
> mm/huge_memory.c | 6 +++---
> mm/truncate.c | 31 ++++++++++++++++++++++++++++++-
> 3 files changed, 69 insertions(+), 4 deletions(-)
>
Hi Andrew,
Can you fold the patch below to this one? I find the issue based
on the syzbot report[1].
Thanks.
[1] https://lore.kernel.org/linux-mm/67c38d10.050a0220.dc10f.016d.GAE@google.com/
From 48cef9263cda2ea7a7a80219113c5c044eb31c0c Mon Sep 17 00:00:00 2001
From: Zi Yan <ziy@nvidia.com>
Date: Sat, 1 Mar 2025 22:34:24 -0500
Subject: [PATCH] mm/truncate: make sure folio2 is large and has the same
mapping after lock
It is possible that folio2 no longer belongs to the original mapping.
Signed-off-by: Zi Yan <ziy@nvidia.com>
---
mm/truncate.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/mm/truncate.c b/mm/truncate.c
index 031d0be19f42..0790b6227512 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -244,8 +244,14 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)
if (!folio_trylock(folio2))
goto out;
- /* split result does not matter here */
- try_folio_split(folio2, split_at2, NULL);
+ /*
+ * make sure folio2 is large and does not change its mapping.
+ * Its split result does not matter here.
+ */
+ if (folio_test_large(folio2) &&
+ folio2->mapping == folio->mapping)
+ try_folio_split(folio2, split_at2, NULL);
+
folio_unlock(folio2);
out:
folio_put(folio2);
--
2.47.2
--
Best Regards,
Yan, Zi
next prev parent reply other threads:[~2025-03-02 3:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 21:00 [PATCH v9 0/8] Buddy allocator like (or non-uniform) folio split Zi Yan
2025-02-26 21:00 ` [PATCH v9 1/8] xarray: add xas_try_split() to split a multi-index entry Zi Yan
2025-02-26 21:00 ` [PATCH v9 2/8] mm/huge_memory: add two new (not yet used) functions for folio_split() Zi Yan
2025-02-27 5:55 ` Matthew Wilcox
2025-02-27 15:14 ` Matthew Wilcox
2025-02-27 15:42 ` Zi Yan
2025-03-04 11:49 ` Hugh Dickins
2025-03-04 16:20 ` Zi Yan
2025-03-04 20:29 ` Andrew Morton
2025-03-04 20:34 ` Zi Yan
2025-03-05 21:03 ` Hugh Dickins
2025-03-05 21:10 ` Zi Yan
2025-03-05 22:38 ` Hugh Dickins
2025-03-06 16:21 ` Zi Yan
2025-03-07 15:23 ` Zi Yan
2025-03-10 8:54 ` Hugh Dickins
2025-03-10 15:35 ` Zi Yan
2025-03-05 19:45 ` Zi Yan
2025-03-05 20:50 ` Hugh Dickins
2025-03-05 21:08 ` Zi Yan
2025-03-05 21:49 ` Hugh Dickins
2025-03-06 9:19 ` David Hildenbrand
2025-03-06 16:27 ` Zi Yan
2025-03-07 17:46 ` David Hildenbrand
2025-02-26 21:00 ` [PATCH v9 3/8] mm/huge_memory: move folio split common code to __folio_split() Zi Yan
2025-02-26 21:00 ` [PATCH v9 4/8] mm/huge_memory: add buddy allocator like (non-uniform) folio_split() Zi Yan
2025-02-26 21:00 ` [PATCH v9 5/8] mm/huge_memory: remove the old, unused __split_huge_page() Zi Yan
2025-02-26 21:00 ` [PATCH v9 6/8] mm/huge_memory: add folio_split() to debugfs testing interface Zi Yan
2025-02-26 21:00 ` [PATCH v9 7/8] mm/truncate: use buddy allocator like folio split for truncate operation Zi Yan
2025-03-02 3:52 ` Zi Yan [this message]
2025-02-26 21:00 ` [PATCH v9 8/8] selftests/mm: add tests for folio_split(), buddy allocator like split Zi Yan
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=56EBE3B6-99EA-470E-B2B3-92C9C13032DF@nvidia.com \
--to=ziy@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=jhubbard@nvidia.com \
--cc=kasong@tencent.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.org \
--cc=yang@os.amperecomputing.com \
--cc=yuzhao@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