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=1796047384; b=AZOE/XOWPpKrAnu6cOpvwevPjZSvWRYHoOaZbBU4ihS91r8nNXB+JhP2KZYnGPcT6m0s EfX8MADEozs2NXwX1tNo7lngBo5eb2eq0NCaABSomN3GoT+st7zAdQHrkcM336aaM/9zi 9I0lBCtubRRD24hs8bHJQzU0Vx03IRPPMM16a4G9sz9L21Cf87grXjdNnA9Z3t1ibwjnh ZrgpCOLKpvk/AG+cqx+YOPx6xJh+UcbAjkkjAOpsqxIZO4vGJR4757/UQumquvlTWcIjd YhoLG028lCPXE5QQnMUpVUkj9BK8v7nlt7QKBwjVpVuivXeV9vpSkucxpJ59adZSXRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047384; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=eD/z512KJFkMdwLb1AtuS/dZaxt/Oxg7ARIUduFvD9M=; b=4nMPVuIq6Lw8jdnnj0ws4oYaLjQLOaBpYEDDyyuzHW+w4A1AQa52imlfCrFazuNJglkA 9xayAL4tb3eqeq9Ytj7E+Wpvs3PWeJsg2cgh33Y8XzygmvAOPit0ljWDZqFKzL762MPUq vrLZvTuoCsyRy+37bPaaYYC0K8Qwqfe2KZoVc7FxVUZDVb7NA3QxbDegCZR8wXwR/k9Yx Pj7B/i1Sl9HruzYIw1PFGv9uc0WZDM4qjbbmMmU0v1wheDESzIdxkMIgKC57IAMjwGynL 5XIuk47oF/nHAaIqw6HtJNS0e9j2tB6AWnNxCSg7/GhHwl7xHwuh8oa3mSiraw9PDFw== 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=ZnM6XU7n; 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 A1009606A320; Mon, 30 Nov 2026 14:03:04 +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=ZnM6XU7n Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19A731F00932; Mon, 30 Nov 2026 14:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796047384; bh=eD/z512KJFkMdwLb1AtuS/dZaxt/Oxg7ARIUduFvD9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ZnM6XU7nIcPSbkjzEdHIVHmOqndZ+ePCRS8sT8POK1brKgPFnmZ/y+chaC10JTkEI fhqMMbWxqjOra4HTP7K1OWQr2ZQnv8gTbiSHQNGNOCppxQw7sz6tbsbshBwtyiKkI2 GX7x6gLIRn25bG27GBhFg0eHHNkimonmiGGBrgyQ68FuMK75iK9L1oqxAwfesTp2L5 orrAyaql1Nuz8T44LafkKUzQTvh1QPUkDGcLuEtRbryQB7Knz+tfbq9WrMTHx6Yyr5 Ap1TUsYBw8UN/YmZTBA+dYkVS0dBysagvM2+fs7+BxS8h84JIWLNQnhV9YF4vsiWRa Wa2WlU/0zpsKw== Date: Mon, 30 Nov 2026 14:02:53 +0000 From: "Lorenzo Stoakes (ARM)" To: Pedro Falcato Cc: Jan Harkes , coda@cs.cmu.edu, Andrew Morton , David Rheinsberg , Hugh Dickins , Vlastimil Babka , "Liam R. Howlett" , David Hildenbrand , Jann Horn , Alex Shi , Johannes Weiner , 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> X-Mailing-List: linux-kernel@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: On Fri, Nov 27, 2026 at 10:14:39PM +0000, Pedro Falcato wrote: > On Fri, Nov 27, 2026 at 07:45:41PM +0000, 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. > > > > 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. > > How about we don't do that? Something something separation of concerns. > If we want this functionality (and we very well might), I would suggest > we do this in reclaim code itself. Something like > > blk_finish_plug_or_flush(). > > Because I really don't want to set the precedent of making every direct reclaim > caller aware of block plugs. > > Either that, or we let it fail. > I think that's follow-up stuff in general! The block plug stuff is pretty grim overall... > > > > 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) > > Aside from the above: > Reviewed-by: Pedro Falcato Thanks! > > -- > Pedro -- Cheers, Lorenzo