From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047534; b=B0ZgxgMBlY9wzDX/9h7PoaDRRR1HYzJu9Xxbt5BKZd5bVKEGor9NaeIBJR3O1V2cFw/J +3AxDysG/2OAOV/Tn3qt/cA81SXCPnRIJ0415wngn6PVOH/6Ph/p7nlL4RZuO+a45DiwH DyWOvafVsztR37B8yAEWBCxysJ2HEF9wPhovHTWkpeZaozNUrGeeGUTOw2XCuwBPfSjBN YgHjtNZ4HDOLgAMZNDnqCE9lnLJj2+MLA9Y5nuZIlOJ/DLSFc6WyhTbGxeYkBoEKDBgz1 YrroKjSo/wYAG6YaHHxK1FpaKxsywRbAASxLqPhOpXvq/kILuFxcn1wkzPUVQuaPsbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047534; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=+7MBTubwNdAlzQJiqcyR8ed+0YyVUiRm0Ki5JkiSzkk=; b=eglNv+cJri0pnBHyze2Cn2DXe7AojwlBQguRNfQMMibFetHjFvIUHwLfkutvN0sXW31k STXyx4a6bdnTBS6lHVwNJGNrGdcZmKkkXBU1GRd2Kkkx7rI8V2fR73vGwP2kcXwJ8D5us Wq6rZDslQkXCJQB13SBrvmqewXCrGv34rsc94uQ2zu++fjWth6cnAPYYKTgregNh/8a3e PnbUpjL4tPnNlnHw6m0Fg3edlF/Ze97dRvYki4LDaVylCFI2rL1vwVeWZhgnk1Ey0rNL5 T3ySuwAUK01ZDV++JtSPh00KTUKyTbWxFzwCxe6vaBTSQkZOCHJlBuO3ffq5bSIam2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DEbkJbhX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1ACE4606A320; Mon, 30 Nov 2026 14:05:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DEbkJbhX Received: by smtp.kernel.org (Postfix) with ESMTPSA id C06531F008A0; Mon, 30 Nov 2026 14:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796047534; bh=+7MBTubwNdAlzQJiqcyR8ed+0YyVUiRm0Ki5JkiSzkk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=DEbkJbhX8EKN7b7SoyjUrQ/0gBvb+tbRasK+0t0O5I7K2ksTQcBF4BBmFIVej8vrq MQmKAfsIyQsQ7DSgw0HFROb/JLxNP5wdJJP19ogHCweW2s042F24gTAUDFfu4+ufsW yFfOpYpJmAZtHR8WV/uL38WeqErHzy48ds3ID+u1w8wa8xwvb/jY2CGXW9oWl5UNrj iUU0OREwEKnH48Tk5Ock6uetMBBqugMdpLAUe0x4+ebgtbrzyKdbPSG66BX7NhN8If GKPKk/rXQOvr+T6wF/JEHw90q3HVMMxz5wW3o9BC4K952x7a7moN6nUzi0dUUx8Qo0 TuScJDmFyImog== Date: Mon, 30 Nov 2026 14:05:24 +0000 From: "Lorenzo Stoakes (ARM)" To: "David Hildenbrand (Arm)" Cc: Jan Harkes , coda@cs.cmu.edu, Andrew Morton , David Rheinsberg , Hugh Dickins , Vlastimil Babka , "Liam R. Howlett" , Jann Horn , Alex Shi , Johannes Weiner , Pedro Falcato , David Rientjes , Rik van Riel , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Arnd Bergmann , Stephen Rothwell , Muhammad Usama Anjum , codalist@coda.cs.cmu.edu, linux-mm@kvack.org, Andrei Vagin , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Chris Mason Subject: Re: [PATCH 2/4] mm/madvise: don't declare OOM for MADV_WILLNEED swapin Message-ID: References: <20261127-mlock-madvise-mprotect-ai-fixes-v1-0-e46b2b1eb435@kernel.org> <20261127-mlock-madvise-mprotect-ai-fixes-v1-2-e46b2b1eb435@kernel.org> <245d204c-dd94-4ca9-8676-d277c212806c@kernel.org> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <245d204c-dd94-4ca9-8676-d277c212806c@kernel.org> On Mon, Nov 30, 2026 at 01:30:28PM +0100, David Hildenbrand (Arm) wrote: > On 11/27/26 20:45, Lorenzo Stoakes (ARM) wrote: > > From: Chris Mason > > > > MADV_WILLNEED on memory in swap can OOM kill a task when the memcg that > > the swap entries are charged to is at its limit. > > > > The hint is only a prefetch, so it has to give up on a page when memory > > is short. But swapin_walk_pmd_entry() and shmem_swapin_range() call > > read_swap_cache_async() with GFP_HIGHUSER_MOVABLE and with the gfp mask > > of the mapping, so the allocation and the memcg charge can both go as > > far as the OOM killer. > > A lot of the "can trigger OOM killer" AI reports are utter garbage. But this > here seems like something reasonable to do. Yeah this seemed like a valid one, or at least not too horrible fix for this one :) > > > > > The charge goes to the memcg of the swap entry, which need not be the > > caller's. > > > > The fix used here is to allocate with the gfp mask of readahead, and to > > flush the block plug when a page fails. madvise_do_behavior() plugs the > > whole walk, so the swap writes of reclaim can sit in that plug. Their > > folios stay under writeback, and with no retries the rest of the range > > can fail as well. > > > > The hint can now skip pages when memory is short, whether in a memcg at > > its limit or on the system as a whole, since neither the allocation nor > > the memcg charge is retried any longer. > > > > This applies in particular where reclaim has to write to swap to make > > room. Skipped pages stay in swap until a fault reads them. > > > > Fixes: 4c6355b25e8b ("mm: memcontrol: charge swapin pages on instantiation") > > Signed-off-by: Chris Mason > > [ ljs: commit message tweak ] > > Signed-off-by: Lorenzo Stoakes (ARM) > > --- > > mm/madvise.c | 19 ++++++++++++++----- > > 1 file changed, 14 insertions(+), 5 deletions(-) > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > index ebb4ce7daf6c..8b56f7aea935 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -196,6 +196,8 @@ static int madvise_update_vma(vm_flags_t new_flags, > > static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, > > unsigned long end, struct mm_walk *walk) > > { > > + /* Only a prefetch, as in readahead_gfp_mask() */ > > + const gfp_t gfp = GFP_HIGHUSER_MOVABLE | __GFP_NORETRY | __GFP_NOWARN; > > struct vm_area_struct *vma = walk->private; > > struct swap_io_ctx ctx = {}; > > pte_t *ptep = NULL; > > @@ -221,10 +223,13 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, > > pte_unmap_unlock(ptep, ptl); > > ptep = NULL; > > > > - folio = read_swap_cache_async(&ctx, entry, GFP_HIGHUSER_MOVABLE, > > - vma, addr); > > - if (folio) > > + folio = read_swap_cache_async(&ctx, entry, gfp, vma, addr); > > + if (folio) { > > folio_put(folio); > > + } else { > > + /* Reclaim queues its swap writes in our plug */ > > + blk_flush_plug(current->plug, false); > > No idea about that magic. Let's hope it doesn't cause harm :) Like sausages, if you don't think too much about what goes into them it's all gravy ;) > > Acked-by: David Hildenbrand (Arm) Thanks :) > > -- > Cheers, > > David -- Cheers, Lorenzo