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=1796176339; b=zshzAkAoUuflVMZyYcXpJro1uMtkikf6Fl1ZgmPG25olRRV3WqbyLSZDCtena4mXeutt y8BG1a9yyylaQW4c2wXdVAtgEtCATNJWqB8wejdVDOwFeKaBynUZt0YPI8ytw1n9d/jLh E4PZJzZR0MlzWfhz2IIiEuIKVVMmdU/Es7reyAIe1NPqReV5v5hiqm8274hQraCc4toko /BqbbVTXXBCmY4Qk3QZoobtxuEbLdhHyd10RsGL2T9b88LxZcNT6McQr8DuURX6F5pJEk b2eBWsmpiDRO4xuznpkKPLURyGogfju8CbXzOIQ1CxXWQ51E23sE0j0MEzbg3mDdfnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796176339; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=vuS96CUU/bkiIwOSc64yln26cglpuW50J39V+HTpbpc=; b=5YEWEZxRlOukoDHodnymA1gHA9AdTw0aZdCJ/eN3nU17RbEOsiyJfS8mkdBcnS0kkzrX 8O/OrZYHupgfR/E5EdGv8Varch90AcvlJjv57o8fak99Y4gHSSNLC5tUWD5YN6UFRoW+b KeQrJw5F2W22o5PfOddGNjAXtO/ktUkGhnSudX5wmYpoUcgSkSoaFUIeRkLUvmHH9qglq rZg1JJBzDSPh8TyFUK3E2YQ3k9Ecb0akn/JhRAFxI630nc0iFuBTZ6N5TEZUxusheaJLT kA8e9LWZryJfbNcz6FeYnhJqrGDK8fHggmfq7N876QNQa4gOlHQ6mn8Fo3FcEB47fNA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=2ecIOCSE; 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 4D25D606A31A for ; Wed, 2 Dec 2026 01:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=2ecIOCSE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A1161F00893; Wed, 2 Dec 2026 01:52:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796176339; bh=vuS96CUU/bkiIwOSc64yln26cglpuW50J39V+HTpbpc=; h=Date:To:From:In-Reply-To:References:Subject; b=2ecIOCSEZ8Ih9o95G0erLPcxt2+UJeC1E7s6YOprx+klxS7+s/1ibFOoTNXm3lZyY HXY2LwN+OTxp+qva9xjs8IIfKYPhZ2U8s5RI83Pm825Jxq+CEzlckiBYBqxuXnsAI6 519xDWAM87fiKvDBEOLU6enXBfzeVQGGY0GWuZIY= Date: Tue, 01 Dec 2026 17:52:18 -0800 To: mm-commits@vger.kernel.org,yuanchu@google.com,weixugc@google.com, vbabka@kernel.org,surenb@google.com,shakeel.butt@linux.dev,rppt@kernel.org, ridong.chen@linux.dev,qi.zheng@linux.dev,paulmck@kernel.org,mhocko@suse.com, ljs@kernel.org,liam@infradead.org,kasong@tencent.com,hannes@cmpxchg.org, david@kernel.org,baoquan.he@linux.dev,baolin.wang@linux.alibaba.com, baohua@kernel.org,axelrasmussen@google.com,max.kellermann@ionos.com, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261123135200.4086519-2-max.kellermann@ionos.com> References: <20261123135200.4086519-2-max.kellermann@ionos.com> Subject: + include-linux-rculist_nulls-add-hlist_nulls_add_behind_last_rcu.patch added to mm-new branch Message-Id: <20261202015219.1A1161F00893@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: include/linux/rculist_nulls: add hlist_nulls_add_behind_last_rcu() has been added to the -mm mm-new branch. Its filename is include-linux-rculist_nulls-add-hlist_nulls_add_behind_last_rcu.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/include-linux-rculist_nulls-add-hlist_nulls_add_behind_last_rcu.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Max Kellermann Subject: include/linux/rculist_nulls: add hlist_nulls_add_behind_last_rcu() Date: Mon, 23 Nov 2026 14:51:56 +0100 Patch series "mm: multi-gen LRU: reduce memcg rotation overhead", v4. This series addresses excessive time spent rotating memcgs during MGLRU reclaim on systems with a large number of memcgs. On some servers with tens of thousands of cgroups, we had repeated soft lockups and RCU stalls: rcu: INFO: rcu_sched self-detected stall on CPU rcu: 60-...!: (1118 ticks this GP) idle=ca74/1/0x4000000000000000 softirq=140067260/140067260 fqs=10 rcu: (t=2101 jiffies g=180256409 q=94266 ncpus=96) rcu: rcu_sched kthread starved for 2073 jiffies! g180256409 f0x2 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=53 rcu: Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior. rcu: RCU grace-period kthread stack dump: task:rcu_sched state:R running task stack:0 pid:15 tgid:15 ppid:2 task_flags:0x208040 flags:0x00000010 Call trace: __switch_to+0xc4/0x108 (T) __schedule+0x2b4/0x978 schedule+0x2c/0xc0 schedule_timeout+0x7c/0x110 rcu_gp_fqs_loop+0xec/0x4e8 rcu_gp_kthread+0x12c/0x160 kthread+0x118/0x1e0 ret_from_fork+0x10/0x20 rcu: Stack dump where RCU GP kthread last ran: Sending NMI from CPU 60 to CPUs 53: NMI backtrace for cpu 53 CPU: 53 UID: 3758108211 PID: 4052395 Comm: php-cgi8.3 Tainted: G W L 6.18.52-i1-ampere #1203 NONE Tainted: [W]=WARN, [L]=SOFTLOCKUP Hardware name: Supermicro ARS-110M-NR/R12SPD-A, BIOS 1.1b 10/17/2023 pstate: 40400009 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : handle_softirqs+0xa4/0x2e8 lr : __do_softirq+0x18/0x20 [...] Call trace: handle_softirqs+0xa4/0x2e8 (P) __do_softirq+0x18/0x20 ____do_softirq+0x14/0x28 call_on_irq_stack+0x30/0x48 do_softirq_own_stack+0x20/0x38 __irq_exit_rcu+0xc0/0x100 irq_exit_rcu+0x14/0x28 el1_interrupt+0x3c/0x58 el1h_64_irq_handler+0x14/0x20 el1h_64_irq+0x6c/0x70 lru_gen_rotate_memcg+0x210/0x280 (P) shrink_node+0xb14/0xcc8 do_try_to_free_pages+0xd0/0x508 try_to_free_pages+0x11c/0x230 __alloc_frozen_pages_noprof+0x4f8/0xe00 get_free_pages_noprof+0x20/0x60 ceph_alloc_readdir_reply_buffer+0xa4/0x160 ceph_readdir+0x248/0xeb0 wrap_directory_iterator+0x54/0x88 shared_ceph_readdir+0x1c/0x28 The problem was lru_gen_rotate_memcg(). Its memcg tail insertion walked the destination bin while holding the per-node `memcg_lru.lock` with interrupts disabled. With so many cgroups, the lock duration grew too long and thousands of concurrent reclaimers were contending for the spinlock all the time. Reclaim can also repeatedly promote memcgs that are already in the young generation, and scans of empty or protected memcgs can bypass the rescheduling points in page reclaim. This patch set contains three parts: The first 3 patches add a cache for each bin's tail to make tail insertion constant time. The fourth patch skips redundant YOUNG rotations when the memcg is already in the default segment of the current young generation. The last patch adds rescheduling points between memcg reclaim attempts and at bin/retry boundaries to avoid potential remaining soft lockups under extreme pressure. I ran a micro benchmark on branch 6.18 on a 12-core Xeon 5118: 8 concurrent workers repeatedly write `1024M swappiness=0` to the root cgroup's `memory.reclaim` for 60 seconds, against a previously prepared set of 1500 memory cgroups. Each worker issues its next request when the previous one returns. The test measures request throughput and latency under concurrent MGLRU reclaim. All requests returned EAGAIN, indicating that the requested reclaim target was not met; the reported throughput counts completed reclaim attempts, not reclaimed bytes. Results: Requests/sec Mean latency Maximum latency Unpatched 4.56 1739.85 ms 4083.55 ms Patches 1-3 43.42 183.53 ms 393.15 ms Patches 1-4 59.22 134.03 ms 393.44 ms Patches 1-5 57.80 137.63 ms 412.72 ms Constant-time insertion increases request throughput by 9.5x. Avoiding redundant YOUNG rotations adds another 36.4%. The full patch series improves the unpatched throughput by a factor of 12.7. All requests returned EAGAIN. These results measure reclaim attempts that did not meet their requested target. I did not measure scheduling-latency improvements of the last patch. This series is very similar to an earlier patch by Chen Ridong which I was not aware of at the time of writing: https://lore.kernel.org/all/20251119083722.1365680-1-chenridong@huaweicloud.com/ This patch (of 5): Move some code from hlist_nulls_add_tail_rcu() to the new function hlist_nulls_add_behind_last_rcu() for callers that already know the last node of an `hlist_nulls` list, to allow constant-time appends. Link: https://lore.kernel.org/20261123135200.4086519-1-max.kellermann@ionos.com Link: https://patch.msgid.link/20261123135200.4086519-2-max.kellermann@ionos.com Signed-off-by: Max Kellermann Signed-off-by: Andrew Morton Reviewed-by: Paul E. McKenney Reviewed-by: Barry Song Cc: Kairui Song Cc: Qi Zheng Cc: Shakeel Butt Cc: Axel Rasmussen Cc: Yuanchu Xie Cc: Wei Xu Cc: Baoquan He Cc: Baolin Wang Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: Johannes Weiner Cc: Ridong Chen include/linux/rculist_nulls.h | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) --- a/include/linux/rculist_nulls.h~include-linux-rculist_nulls-add-hlist_nulls_add_behind_last_rcu +++ a/include/linux/rculist_nulls.h @@ -116,6 +116,33 @@ static inline void hlist_nulls_add_head_ } /** + * hlist_nulls_add_behind_last_rcu - append after the last list entry + * @n: the new element to add to the hash list. + * @last: the last element in the list. + * + * Adds the specified element after @last while permitting racing RCU + * traversals. @last must be the last list entry, with its next + * pointer holding the terminating nulls marker. + * + * The caller must take whatever precautions are necessary + * (such as holding appropriate locks) to avoid racing + * with another list-mutation primitive, such as hlist_nulls_add_head_rcu() + * or hlist_nulls_del_rcu(), running on this same list. + * However, it is perfectly legal to run concurrently with + * the _rcu list-traversal primitives, such as + * hlist_nulls_for_each_entry_rcu(), used to prevent memory-consistency + * problems on Alpha CPUs. Regardless of the type of CPU, the + * list-traversal primitive must be guarded by rcu_read_lock(). + */ +static inline void hlist_nulls_add_behind_last_rcu(struct hlist_nulls_node *n, + struct hlist_nulls_node *last) +{ + WRITE_ONCE(n->next, last->next); + WRITE_ONCE(n->pprev, &last->next); + rcu_assign_pointer(hlist_nulls_next_rcu(last), n); +} + +/** * hlist_nulls_add_tail_rcu * @n: the element to add to the hash list. * @h: the list to add to. @@ -143,13 +170,10 @@ static inline void hlist_nulls_add_tail_ for (i = h->first; !is_a_nulls(i); i = i->next) last = i; - if (last) { - WRITE_ONCE(n->next, last->next); - WRITE_ONCE(n->pprev, &last->next); - rcu_assign_pointer(hlist_nulls_next_rcu(last), n); - } else { + if (last) + hlist_nulls_add_behind_last_rcu(n, last); + else hlist_nulls_add_head_rcu(n, h); - } } /* after that hlist_nulls_del will work */ _ Patches currently in -mm which might be from max.kellermann@ionos.com are include-linux-rculist_nulls-add-hlist_nulls_add_behind_last_rcu.patch mm-vmscan-move-code-to-lru_gen_adddel_memcg.patch mm-mglru-cache-the-last-memcg-node-make-tail-insertion-constant-time.patch mm-mglru-avoid-redundant-rotations-of-young-memcgs.patch mm-mglru-reschedule-between-memcg-reclaim-attempts.patch