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=1796139301; b=N+WZwJM93GDuLVFr+RO+UHalrR71o604yt4zpwTwYsvbLF401V2/S8xIoZvL/Cm0QZAb yWis7CrbjZQ49MwU+ixzuh2pqkJdcL2T+KeCJnMdF4Hun3Dgs50c8kogAvwBWYsI+XbIw SNNHprnDt7nBWSVBDn3ORzitU4byq2HRclHP4jMXTXdPzI3EfEcz0PecaVYZNjP228/UQ VGE4GNKTysNUfv8zX4JVREpOF4o3Ko7Jd0lfHtIavNjURDoEVSV55klzo5vL76gy0Ny8/ iisUye/vXq6TvlG6y70vvrZLibO0G+2N4Tufeja0gCCMHeXdm7UVHbT1jfN4K4Is2FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796139301; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=US1aS9cwGKv4JodbxlKwObIxtmMsDRz5WHFdZLeY9QQ=; b=4OcwC13qksU65l/8zLFUf5TUwddQJp2O4NQlxis6s7bm/KCq5DwpIcSlflipCwY8y6rm xTOGeLJU3nLJFB58s63VxzfgaRwFjr47uGM951NexsTts6tqNBlJ963PXfDFuKJPwau0j c/taCwccu0yYn+0AGwcv/UBr13hmotoso93SmUKVAOds2UPAeKsbAcCul4eM22wssgwI+ ZF6+uSwg6FbmSxEULqg5XWj/WAJ6tUARfiumjm480J/Mr3rzFWt3u5g59W7snXIXmqKft ifz6lvk7KybwoVkMepWymK7RskJ9RsjIdbhKK+/OLWW8os0wzqFZjl34pLI9YZPZ3ZQ== 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=oPVYaDZL; 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 C0EDE606A320; Tue, 1 Dec 2026 15:35:01 +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=oPVYaDZL Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B71A1F00923; Tue, 1 Dec 2026 15:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796139301; bh=US1aS9cwGKv4JodbxlKwObIxtmMsDRz5WHFdZLeY9QQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=oPVYaDZL1QwDJKajERqgzD1DBgvVLtTlF9HUNaCvwn2EzhnsRfnGOURXAugqKnIdJ HGpVv36vOR1oI4qkM82YYJm0COR6WHkJF2Qe8zykQRNnSrU+McHHgwUJXCYDCkKAgs uUTq3Gpulh5SWc3K7fyt9J6sjAj1l0GZjJWITZZ5FO886dJMHO6goIoMhlkuxy4TfC BOMbEdsvzYjtJSe+U9Q4obBtfV5LyA+X4fkYRbMNpA5C0YNGEiF3WVX0vZnpymjhku fj/QbIBxLBsW4y1hV4ITbHAkY7AEK3aowQAs2Tl1QvgzaZGeYqZtQoqMunz1+kb1gU ENQ3oeCNppysQ== Message-ID: Date: Tue, 1 Dec 2026 16:34:46 +0100 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 4/4] RFC: mm/vmscan: unlock unmapped folios only after the deferred TLB flush To: Kairui Song Cc: Zhang Peng , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , "Borislav Petkov (AMD)" , =?UTF-8?Q?Cenk_Y=C4=B1lmaz?= , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Andrew Morton , Zi Yan , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Chris Li , Kemeng Shi , Nhat Pham , Baoquan He , Barry Song , Youngjun Park , Mel Gorman , Sasha Levin , Rik van Riel , Ingo Molnar , Peter Xu , Hugh Dickins , Axel Rasmussen , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Yuanchu Xie , Wei Xu , Baolin Wang , Andrea Arcangeli , Thomas Gleixner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261118-file_folio_flush-v1-0-e9e739ed14e0@kernel.org> <20261118-file_folio_flush-v1-4-e9e739ed14e0@kernel.org> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27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KnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/29/26 12:41, Kairui Song wrote: > On Sun, Nov 29, 2026 at 7:30 PM David Hildenbrand (Arm) > wrote: >> On 11/29/26 12:20, Kairui Song wrote: >>> On Wed, Nov 18, 2026 at 5:22 PM David Hildenbrand (Arm) >>> wrote: >>> >>> Thanks for taking care of this! >> >> Thanks for the review, I'm planning on sending #3 and #4 out soon. >> >>> >>> >>> I'm not sure locking that many folios at once is safe under pressure. >>> Our first TLB batch flush series internally kept every folio locked, >>> but we found that unlock them improved performance further for >>> some workloads so we switched to the posted version from Peng. >> >> Yeah, I don't see a way around not destorying performance: >> >> I have further below. >> >> "Note that khugepaged and batched (async) folio migration already keep up >> to HPAGE_PMD_NR (e.g., 512 with 4 KiB pages) small folios locked after >> unmapping them with a deferred TLB flush; migration even allocates new >> folios, possibly entering direct reclaim, before flushing the TLB and >> unlocking them. Both also call MMU notifiers while keeping other folios >> locked, just like we do now." >> >>> But to fix the flush issue we do have to keep them locked though. >> >> Yes, unfortunately. >> >>> >>> There is no deadlock, but seems fragile. e.g. shmem_get_folio_gfp() >>> takes a plain folio_lock(), so a thread faulting a parked folio waits for >>> the whole batch while holding mmap_lock, and the batch can be >>> blocked by any non-trylock part of rmap/splitting. The per-folio hold >>> time is much longer too. Maybe we can optimize other parts later >>> instead if there is any actual regression. >> >> Yes! >> >>> >>> >>> I'm trying to make the swap table allocation sleepless, so we no longer >>> need to worry about that :-D Lian and Chris are pushing on the swap >>> queue series and it should come after that. >> >> That would be nice" :) >> >>> >>> >>> Hopefully the swap side can get rid of this too. The discard attempt is a >>> historical thing to avoid OOM on super slow discarding devices, reclaim >>> throttling (which is being unified for MGLRU) can handle that instead. >> >> Ack! >> >>> >>> >>> Using a list is usually bad for performance IMO, Peng used a folio_batch, >>> which I'm also a bit concerned about stack usage-wise.. The overhead >>> could be trivial though, I tested this series and it's working >> >> Yeah, if a batch is a better fit (and we can tolerate stack usage) we should >> ideally optimize it on top of this here. >> >>> >>> Ultimately I think we want just one or two unified batches for the whole >>> reclaim loop: from the very begiing of the call stack, >>> SWAP_CLUSTER_MAX is 32 which is the typical starting budget >>> under pressure, close to the folio_batch limit 31 already, and >>> we have a few of them already too. >> >> Ack. >> >>> >>> >>> folio_list can get repopulated from shmem (pageout() passes it to >>> shmem_writeout()), so the loop can leave N already-flushed folios behind and >>> get NULL from it. Should be fine, but it blurs the two stages. >> >> Yes, I didn't find a simple way to improve that without reshuffling the code >> massively. >> >>> >>> ... >>> >>> This looks... really weird; it will be much cleaner with Peng's cleanup I >>> guess. >> >> Yes, please do cleanups on top once we have it fixed. This all needs to be >> separately cleanly into stages. >> >>> >>> >>> The writeback part may better at least have a folio_set_reclaim() so they >>> don't miss a rotation? Better if we can reuse the pre-stage checks by >>> splitting that part out properly. >> >> Is that something you want me to change in this patch? >> >>> >>> I tested this on x86 under pressure (40 GiB in one process with >>> swap, 4 processes concurrently, and 4 memcg-limited cgroups reclaiming >>> concurrently): TLB shootdown IPIs dropped by 90%, wall time by 30%. >>> Clean page cache seems unchanged, and on arm64 nothing changes >>> either. Really nice result! >> >> Thanks for the test! That's what I was expecting in the common case. It took a >> while for me to figure out how to have the patch minimal and yet not harm >> performance ... and while it even improve performance for the dirty case. >> >>> >>> So it looks good to me, just a few nits and a lot of cleanup to be done. >> >> Thanks! Yes, I hope you guys can figure out cleanups on top of this. >> >> Is there anything specific you want me to tackle in this patch before I resend? > > I just noticed the folio_list issue was also pointed out by Zi, with > that fixed I think it's good enough. > > The folio_set_reclaim part is kind of trivial Yes, let me just include that. -- Cheers, David