From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DADA606A337 for ; Fri, 4 Dec 2026 10:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=CRDCqlDS Received: by kanga.kvack.org (Postfix) id 403336B05B3; Fri, 4 Dec 2026 05:36:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B4216B05B4; Fri, 4 Dec 2026 05:36:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A4266B05B7; Fri, 4 Dec 2026 05:36:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 001C46B05B3 for ; Fri, 4 Dec 2026 05:36:27 -0500 (EST) Received: from smtpin12.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 75DC4120310 for ; Fri, 4 Dec 2026 10:36:27 +0000 (UTC) X-FDA: 85505946414.12.2F554C6 Received: from mta0.migadu.com (out-213.mta0.migadu.com [91.218.175.213]) by imf28.hostedemail.com (Postfix) with ESMTP id 51FBCC0005 for ; Fri, 4 Dec 2026 10:36:25 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CRDCqlDS; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf28.hostedemail.com: domain of ridong.chen@linux.dev designates 91.218.175.213 as permitted sender) smtp.mailfrom=ridong.chen@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796380585; b=tJqdhOcWy8FSab5nmXrYbm6iLMmnirIg7/FrE1HUsaYvuB1lJ/l1eZqjWRmG9509dbkr2G v1g7gWGUy/XtfNaxSN7V6LTTxsJhYpDD8XidD/jgMb9usYuBG7zR01EvyooZh9rN+hKGk5 RW42CGkeM7ZpQC9VcVNs/nn5Z5wYgvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796380585; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lU7C0Xe4SWD0cp36nfe1ksD6HrDWvxncspyiI1vTSao=; b=psAAOwBqY+mr6ZDIizTZD4GL89CMAVAKyxsD+6XTIRooT2ojy5J46nZd9ngiYq0lpLEWXn 9O3u6ICOzG6WN2+76YUvzPul182RgRyo60NkoQOGQiMGm2oVw2RxW4ry2Mkikhhkf7tplt tNuO0C8gtYKkvsZ9CYVweIhcx7boe0k= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=CRDCqlDS; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf28.hostedemail.com: domain of ridong.chen@linux.dev designates 91.218.175.213 as permitted sender) smtp.mailfrom=ridong.chen@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=i/fj1cKl9/A+rmgJDMHsPXtyNeEacCQP/xzDluK4zcM=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796380583; v=1; x=1796985383; b=CRDCqlDSaKwbxZM6gum3WCPqWnOvnZVGFzNFXacBTJehU7WUEmhuLuAWHl0KOPJSvrIMVHzK LliwuRcvR7uC+smVtqN8rbDxbtg1LJyI5F+4wjoSf3Hoy7nYL91Tv1wBzpYqmUhCP7YRvLfgK/n nCXdW3Qjw2YZRq401QheB8pQ= X-Envelope-To: linux-mm@kvack.org Received: by smtp.migadu.com with ESMTPS id c7ac2a6c8536e648; Fri, 04 Dec 2026 10:36:23 +0000 X-Mizu-Trace-ID: c7ac2a6c8536e648 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Fri, 4 Dec 2026 18:36:14 +0800 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 0/2] mm/mglru: shorten the lru_lock hold time in scan_folios() To: Kairui Song Cc: Andrew Morton , David Hildenbrand , Johannes Weiner , Barry Song , Qi Zheng , Shakeel Butt , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , "open list:MEMORY MANAGEMENT - MGLRU (MULTI-GEN LRU)" , Ridong Chen References: <20261127060315.1119672-1-ridong.chen@linux.dev> <42195463-c50b-4f80-ad2c-ecc106e4c2ae@linux.dev> From: Ridong Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Stat-Signature: jft8a3ezninxgo999ore1fkchxa18qpf X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 51FBCC0005 X-HE-Tag: 1796380585-55056 X-HE-Meta: U2FsdGVkX18ow5xUuQp9ZqoYe4wuyA0rYN4zMisfdNKqfv4UsalKiJsPeCiqmOY6SChenS0K3GExxutXjCp1ROtOETUpIlfFMdPHueTPzZEdG87s9nRw8WkVQcAXscZIhoRPtlpy4qB3k6VG8QeelzDKj7XkECQ81wrrJAEh0QbTGQ3bHxQlwOChUrYl0zJGNn8cvqrGz8Jd8a18iQU/eG10QpLkyMFwCK0Y75+uxnp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tQO9S745vSBtxZyG921IDwgQpEOtmPA5j5qrYlS8/oTHEJqXBgvN6hyPSDVvjdDnXg1WBrUON4Q1vbUeyK/bH2lXNOX9s2+QH+rqTbI0pRI4YClNpu0bWd522QFn+xb4YuSJgxN5hEk4dXu9AVmHXao2W3DGB4T5Rk0YovWjiVjmte09BR8VlPOWBhDdtmpwniHicE6f93mfxQSAASRFPJhpOkXLxX5hkUkAZrq0lqolr2NFQDLUP1KVP20AgmQ6/kKmkRCqqz2iMtlk64/RwDpq7BWOcEgJKwsI8HqgoQlo1lG4TNxDnFkEW7zU+8cleuDvpiGaBYoSFyfKFBILHRb2PABDNQPdRV2l9W9C8QNCW4MjRysPaevrvLbfXDzo6HNgqeg= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 11/28/2026 4:30 PM, Kairui Song wrote: > On Sat, Nov 28, 2026 at 9:00 AM Ridong Chen wrote: >> >> >> >> On 11/28/2026 3:34 AM, Kairui Song wrote: >>> On Fri, Nov 27, 2026 at 02:03:13PM +0800, Ridong Chen wrote: >>>> From: Ridong Chen >>>> >>>> When many CPUs reclaim from the same lruvec, they spend most of their >>>> time spinning on lru_lock, and the time scan_folios() holds the lock >>>> limits reclaim throughput. With 24 threads refaulting file pages in one >>>> memcg, about 40% of all cycles went to waiting for lru_lock here. >>>> >>>> This series takes per-folio work out of that critical section, along >>>> the lines of what isolate_lru_folios() already does for the classical >>>> LRU: >>>> >>>> 1. Update the node, memcg and zone LRU sizes once per zone instead of >>>> once per isolated folio. >>>> >>>> 2. Prefetch the previous folio, so the cache miss on its flags and list >>>> pointers is not taken while holding the lock. >>>> >>>> Tested on an i7-13700HX (8P+8E, 24 threads), turbo off and the >>>> performance governor. 24 files of 128MiB on ext4 on brd, all threads >>>> in one memcg with memory.max=1G, random 4K pread(), so nearly every >>>> read refaults and every thread ends up in direct reclaim. Reads per >>>> second per CPU, mean of 2 runs, with and without each patch in one >>>> kernel and the runs interleaved: >>>> >>>> CPUs base patch 1 patch 2 both >>>> 1 426681 -0.4% -0.2% +0.3% >>>> 2 387442 +0.7% +1.2% +1.4% >>>> 4 360312 +1.0% +1.5% +2.1% >>>> 8 314549 +2.5% +2.5% +3.3% >>>> 12 235058 +3.2% +4.3% +5.6% >>>> 16 184086 +9.4% +9.2% +11.2% >>>> 24 124478 +15.5% +16.5% +21.6% >>>> >>>> The gain grows with the number of CPUs reclaiming from one lruvec; >>>> with a few CPUs there is little contention and no measurable change. >>>> >>>> Ridong Chen (2): >>>> mm/mglru: update LRU sizes once per zone when isolating folios >>>> mm/mglru: prefetch the previous folio in scan_folios() >>>> >>>> include/linux/mm_inline.h | 26 ++++++++++++++++++++++++-- >>>> mm/vmscan.c | 18 +++++++++++++++--- >>>> 2 files changed, 39 insertions(+), 5 deletions(-) >>> >>> Hi Ridong >>> >>> I have a different approach proposed about two years ago: >>> >>> https://lore.kernel.org/all/20240123184552.59758-1-ryncsn@gmail.com/ >>> >>> I hesitated to push that as the end to end gain was not >>> that large (5-10%) fio and it makes the code too complex. >>> But I think that one may work very well for microbench. >>> >>> I tried to resurrect that 2 weeks ago, but realized it's not >>> the best time at the moment, there are too many things in flight >>> for MGLRU: >>> >>> https://github.com/ryncsn/linux/commits/b4/mglru-isolation/ >>> >>> Perhaps we can discuss and see if using a "batch struct" could >>> fit better later? It should also unify the aging batch too. >> >> Hi Kairui, >> >> Thanks for the pointers. >> >> I'm fine with handling the batching together with your batch struct >> work later, and happy to fold the nr_taken[] part of patch 1 into it >> when the time comes. >> >> Patch 2 (prefetch) is independent of that, though. It is the >> one-liner Chris suggested for your v3 1/3, which he said he would ack >> if resent on its own [1]; the inc_min_seq() half of it has since been >> done by commit 5d3664f070f0 ("mm/mglru: move folios from oldest gen to >> second-oldest gen from head to tail"). It is a no-op on archs without >> prefetch, the same thing isolate_lru_folios() already does for the >> classical LRU, and it gave +16.5% alone with 24 CPUs in my test. > > I'm actually a bit skeptical about the real effect of this, and the > previous work for inc_min_seq... for example if you read: > https://lwn.net/Articles/444336/ > > In my previous attempt 2 years ago, I did more than just synthetic > microbenchmarks, on three different CPUs, 5900HX, i7-9700, 8255C and > 7K62. The results changed dramatically; it's not a x86 vs ARM thing, > but is strongly affected by the actual microarchitecture design (which > is not surprising). So my conclusion was that it isn't worth the > complexity, especially considering that modern hardware branch > prediction is much smarter and memory pressure is mostly random. In > the longterm we should work on getting rid of the LRU "as a double > linked list". The branch check may even bring negative effects, IMO. > >> >> Would you be OK with taking the prefetch patch now, with batching left >> for later? I can resend it as a standalone patch. > > But that sounds ok to me, it wasn't too ugly now considering we > already have all the wheels. If that solves the problem for you, let's > have it. > Hi Kairui, Sorry for the late reply. I've been looking at MGLRU direct reclaim tail latency on Android. When many tasks enter direct reclaim at the same time they pile up on the same memcgs and slow each other down [1], so the time spent under lru_lock matters there. To check the prefetch on arm64, I ran the same kind of microbenchmark on an 8-CPU tablet: random 4K pread() on files 3x the memcg limit, one thread per CPU, all threads in one memcg, base and patched interleaved in one boot, 5 rounds each. Reads per second per thread: threads base prefetch 1 180688 +1.5% 2 189663 +2.0% 4 181787 +3.2% 6 168018 +3.8% 8 146523 +6.1% From 4 threads on, every round was faster, and there was no regression with 1 thread. So the gain is there on arm64 too, and the change is a single line, the same as isolate_lru_folios() already does. I'll resend the prefetch patch on its own and leave the batching for your batch struct work. [1] https://lore.kernel.org/linux-mm/20261119065043.398-1-ridong.chen@linux.dev/ > For the batching part my concern is that how should we balance the > stack usage and batching size, vmscan have a bad history of causing > too many stack using, with a batch on stack it will get worse, perhaps > we should put it somewhere else, but I think this can be done later > too, after FG maybe. -- Best regards Ridong