From: Nhat Pham <nphamcs@gmail.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org>,
Kemeng Shi <shikemeng@huaweicloud.com>,
Kairui Song <kasong@tencent.com>, Baoquan He <bhe@redhat.com>,
Barry Song <baohua@kernel.org>, Chris Li <chrisl@kernel.org>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
David Hildenbrand <david@redhat.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Ying Huang <ying.huang@linux.alibaba.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/4] mm, swap: do not perform synchronous discard during allocation
Date: Tue, 7 Oct 2025 16:52:43 -0700 [thread overview]
Message-ID: <CAKEwX=PisWyb-Gt=n7ZBPNTNjbRNM5F5j4LE4NoRgTUB+2ZV-w@mail.gmail.com> (raw)
In-Reply-To: <20251007-swap-clean-after-swap-table-p1-v1-1-74860ef8ba74@tencent.com>
On Mon, Oct 6, 2025 at 1:03 PM Kairui Song <ryncsn@gmail.com> wrote:
>
> From: Kairui Song <kasong@tencent.com>
>
> Since commit 1b7e90020eb77 ("mm, swap: use percpu cluster as allocation
> fast path"), swap allocation is protected by a local lock, which means
> we can't do any sleeping calls during allocation.
>
> However, the discard routine is not taken well care of. When the swap
> allocator failed to find any usable cluster, it would look at the
> pending discard cluster and try to issue some blocking discards. It may
> not necessarily sleep, but the cond_resched at the bio layer indicates
> this is wrong when combined with a local lock. And the bio GFP flag used
> for discard bio is also wrong (not atomic).
>
> It's arguable whether this synchronous discard is helpful at all. In
> most cases, the async discard is good enough. And the swap allocator is
> doing very differently at organizing the clusters since the recent
> change, so it is very rare to see discard clusters piling up.
>
> So far, no issues have been observed or reported with typical SSD setups
> under months of high pressure. This issue was found during my code
> review. But by hacking the kernel a bit: adding a mdelay(100) in the
> async discard path, this issue will be observable with WARNING triggered
> by the wrong GFP and cond_resched in the bio layer.
>
> So let's fix this issue in a safe way: remove the synchronous discard in
> the swap allocation path. And when order 0 is failing with all cluster
> list drained on all swap devices, try to do a discard following the swap
> device priority list. If any discards released some cluster, try the
> allocation again. This way, we can still avoid OOM due to swap failure
> if the hardware is very slow and memory pressure is extremely high.
>
> Cc: <stable@vger.kernel.org>
> Fixes: 1b7e90020eb77 ("mm, swap: use percpu cluster as allocation fast path")
> Signed-off-by: Kairui Song <kasong@tencent.com>
> ---
Seems reasonable to me.
Acked-by: Nhat Pham <nphamcs@gmail.com>
next prev parent reply other threads:[~2025-10-07 23:53 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 20:02 [PATCH 0/4] mm, swap: misc cleanup and bugfix Kairui Song
2025-10-06 20:02 ` [PATCH 1/4] mm, swap: do not perform synchronous discard during allocation Kairui Song
2025-10-07 23:52 ` Nhat Pham [this message]
2025-10-08 20:54 ` Chris Li
2025-10-09 15:32 ` Kairui Song
2025-10-09 16:58 ` Chris Li
2025-10-12 16:49 ` Kairui Song
2025-10-14 21:27 ` Chris Li
2025-10-15 2:55 ` Chris Li
2025-10-15 6:24 ` Kairui Song
2025-10-15 16:45 ` Kairui Song
2025-10-21 6:48 ` Chris Li
2025-10-21 8:44 ` Kairui Song
2025-10-21 7:34 ` YoungJun Park
2025-10-24 4:00 ` Kairui Song
2025-10-06 20:02 ` [PATCH 2/4] mm, swap: rename helper for setup bad slots Kairui Song
2025-10-07 23:47 ` Nhat Pham
2025-10-08 10:25 ` David Hildenbrand
2025-10-08 20:58 ` Chris Li
2025-10-06 20:02 ` [PATCH 3/4] mm, swap: cleanup swap entry allocation parameter Kairui Song
2025-10-06 20:07 ` Kairui Song
2025-10-07 23:49 ` Nhat Pham
2025-10-08 10:26 ` David Hildenbrand
2025-10-08 20:59 ` Chris Li
2025-10-14 3:12 ` Baolin Wang
2025-10-06 20:02 ` [PATCH 4/4] mm/migrate, swap: drop usage of folio_index Kairui Song
2025-10-07 23:48 ` Nhat Pham
2025-10-08 1:20 ` Andrew Morton
2025-10-09 15:33 ` Kairui Song
2025-10-08 21:03 ` Chris Li
2025-10-14 3:15 ` Baolin Wang
2025-10-07 22:20 ` [PATCH 0/4] mm, swap: misc cleanup and bugfix Andrew Morton
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='CAKEwX=PisWyb-Gt=n7ZBPNTNjbRNM5F5j4LE4NoRgTUB+2ZV-w@mail.gmail.com' \
--to=nphamcs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bhe@redhat.com \
--cc=chrisl@kernel.org \
--cc=david@redhat.com \
--cc=kasong@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryncsn@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.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