From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 828788017D for ; Tue, 20 Oct 2026 15:13:39 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69KFCF92002899; Tue, 20 Oct 2026 18:12:16 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69KFCF92002899 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="QWyHPiPf" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69KFCEXO002895 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 20 Oct 2026 18:12:15 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69KFCEXO002895 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48df02b91f9so572964f8f.1 for ; Tue, 20 Oct 2026 08:12:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBwJvjjOdFGMTXXbU2NEAQe+fx9FasInp28VOj3nsOx47bOpYuWjggPzgAF6hlg/dGzWvFkzww==@openvz.org X-Gm-Message-State: AFq9FYIUHcbM9Dp24UvQudqW7joCdYvl4NeufzJqPKsUa83+iQF3VsOc nHtcU3pOkjbsB+mV/noFeT305b1ZF/G80zNy9RKnidIpq4Gq9yq9j82ORg6itBSW4/y0P1SddtE nDIU9waldl6dSTD7XqROGrtZ1yz75Rocjc8F/vozqyUFBgYOhm/xKnA== X-Gm-Gg: AYBFou0L9yRKXwWr3L+OxPMHnJBI3X+Sbt7pOMqGYgT9X4/idGU5xgitvCx4/jOVJEP fcB/vAbqiLELthQZI8FtAsPg5l6IGVraK+vpRFcAuneo0sBXPl52OXRTWpHUCj0qk+4jhV4q/4D q5qVdSUGdltQAnYXIA8XwWmadwGxawnUFLWWB1914mIeCpxFyrSfUopWhL2pdY/o5wlvovXcg5j YwVzxr15a8AL3mzpL03NM3JDxSNpIgTWCMJfc8HJdBLyvVCeZZayQamWYw3ntfEhIeiVr7X/NrX cp+RzBcHZr+xkSay2PyCVFNGliY8ytXxEIYFmDNnAuqto29rALtHGzCe5X2PobHWTreww1rlrCO lklQkfqh0yEzHwHJ2 X-Received: by 2002:adf:e010:0:20b0:48a:fff3:f9c1 with SMTP id ffacd0b85a97d-48e1e7d24afmr4214547f8f.20.1792509132942; Tue, 20 Oct 2026 08:12:12 -0700 (PDT) X-Received: by 2002:adf:e010:0:20b0:48a:fff3:f9c1 with SMTP id ffacd0b85a97d-48e1e7d24afmr4214453f8f.20.1792509132174; Tue, 20 Oct 2026 08:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1792509132; cv=none; d=google.com; s=arc-20260327; b=kJfz+xO4fNrBewY8h6PWIDgnS9YcBzaMa5+0UGzEtKhPE8RfevVsM7GbcsuI2a/DWO xb1I11C6hT73Jyog7sk352lHkpYxK9X1bJadOPV1MCsHILTGm2gk0HflnGgXxTDOf2El L2lA2sK18CwTj9JPnDz9YAIhE97nQhDL5weDLg69awUlNRebx2sBGgiyL+p86yAnhd66 YtTGLv8gqcPL/Lh9xr7Stbaw3hKCWdRIIimPRmbiPvnxQH8O2Rs9EWOqfiQuREg6jJLA 19cUvZzG2iBdGUBIcxuGRxdopfM/qIN/aJa4TXsqNcio2tkk+ZcP3tBF+dtFdOzLeqj+ 0MkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=to:message-id:content-transfer-encoding:mime-version:subject:date :from:dkim-signature; bh=Zwk+ms7n1U04uljqxuxmE/ZWR/ojhdl53pSuvaWiFrY=; fh=M81R4pbPlUuKtko6pX3kWZGRGY4osEzB3DJaqaPopcw=; b=ZNXPJq0NpS82XzfM0Oed1pfw+Wc1P8xnLvHbygUm5g9FhpaH6G88vs01IxiHB2g1lr x9zAA8LUN/cXUbDeMFDLXb0xXsngLzyxSBYgnpgXc66T0OrORhKbCuWzu10ZuiG05tzk CcO/4i9MXfOCG871GPOeDc84gsHqUl6E5JAuFtMSkS28lV3ZNLf9sonKHy2BUgchEqsG MHAxoBqpVwoSSsYKrRlYylznU4ZPkETfPr1+rYGccspZcss74Is6SaI5lf6RsRV+vy+L YOjWua3EcAtynAhvKBBQ1M9Q6+vmUK/flK5wCzFw0bxwDTrYdt5mk10BCxYrDk0zlSmD gXqQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QWyHPiPf; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48e1d845b1asi5480424f8f.386.2026.10.20.08.12.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Oct 2026 08:12:12 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QWyHPiPf; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=Zwk+ms7n1U04uljqxuxmE/ZWR/ojhdl53pSuvaWiFrY=; b=QWyHPiPfDmqdZ2oiroq xymmOqvdInLP8js96ZAqgX8VhFPQO1iLx2bdwaFZmNWffgNwjyoDOQ+HNzwXOOUvWXafE0CtJBJQ2 r2cbWEWybTzUNv2Qp6F2ox/7EGjXO/0I91p7e6t3M4sgeJ0bZ+4J9s0jLHY3TdD05DelQ6sNqS505 Pdod4NnKatLxf9zs6vyTCJHFvs3GklYLCjm5XXVWiX3g/oXvbGiHQmgGppVhBe0vvOL9uHDIG+RiT wkX0Y5j7bB/bDbStJQoeyPx3TxKvVUgWWnqMOmdUpXamdUqHOEoMh2gHPJ+pnvXn1r3Sa4ZjMtajA 7OecdAbE2iSueww==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xJBS1-00ESkG-15; Tue, 20 Oct 2026 17:12:01 +0200 From: Konstantin Khorenko Date: Tue, 20 Oct 2026 17:12:07 +0200 MIME-Version: 1.0 Message-Id: <20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-v1-1-4bdb03031132@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAMaE12oC/yWNUQrCMBAFr1L225VsDW31KiLSpquJwaTs1iKU3 t2on8PjzaygLIEVTtUKwkvQkFMB2lXgfJ/ujGEsDLWpGzK1wcHiJDxh9Fk4xYyLzlmQrG3Jono JKbIoxic/r653nnE8Nh1TR4ehNVDE5X8L71/0DN4F7PYEl/+gr+HBbv4mYds+9UeKg58AAAA= X-Change-ID: 20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-d968e1813b70 To: Pavel Tikhomirov , devel@openvz.org, Konstantin Khorenko , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4591; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=9Ce2cFw1AJRb5XJR224pwDB/lERJZBO29MfjsEo7T94=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBq14TKYDg01cDR0qJQDMDSh3EIUGPVvXJ50bPju r81XYCUgi2JAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCateEygAKCRBRlgpH+WFc KjLCD/9BFJ7IQll0ZVmRAY1AqfKeNjb4BfxICnRYJMF5JIOa8cg+i1LGLWndYANgaGZYwQZQ3/W fFX56ssH0iKUVGBJ/7di0f2qM5EXKJzq7TuautLUQVE5vM4F+AMKX8GYTZ21IuSLPlVik2pSx2e 3aIAZJW0AA4iHRUQBgcEV/elN1/R+F+XTW51TYlO+pzqSw3/f7OTZ7oUyL7UYN1/xNlSMEnZ8T/ ZtqaiGr/VEmNePYnCYWI0g6XpIpMPNGSv+43V96x9r4Q9XjY8mqTzfTjKR5HMvQATZlTpxhSWUY uiUETXSbpTeu45bFNhlhpq2kw9pP32VuEmFy2Z9xrgAStBx185tGkY0uiJPEkMDmuy06TlPedQR hdEqkW68PZg0m8cMVQYxg52gnn7l406ga9J8Tf+vTpuKdNsVIu9+TSouWflqgUenvgk1oNy0SGv ObdCxRwEEsGewv8AJKGYLZQcU7HVV8YKNuMJhsj2b6627AZgFRtt36zo6W1pehTTld/TqZ73fVP 1kpGUC23ftlwvcI6tkBVls8ZqvNCrlb+hGPxS2iEHO5EpHVXPMjR0T3jtNy7mGKtP8enZ9/RNNH 9MD9nn31YXmw/UtWDkAvaryQUd6f+WkCiric8hWodz1sowbPrG8/cR6ZXK1Ljgv4lfzieaGWOME RieOYLnhO8eOrXA== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Subject: [Devel] [PATCH hci-8.1] ms/mm/shrinker: allocate shrinker_info_unit from a dedicated kmem_cache X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org shrinker_info_unit holds BITS_PER_LONG atomic_long_t of deferred work plus a one-word bitmap, 520 bytes on 64-bit. kzalloc_node() takes it from kmalloc-1k, so almost half of every unit is padding. Allocate the units from a cache of their own, sized to the unit. The cache is not cache-line aligned: the counters of a unit already share cache lines between shrinkers, and aligning the unit would only keep neighbouring units off each other's boundary line, at the cost of part of the saving. Link: https://lore.kernel.org/20261019-vstor-144715-shrinker_info_unit-kmem_cache-v3-1-0fb061e09bf4@virtuozzo.com Signed-off-by: Konstantin Khorenko Signed-off-by: Andrew Morton Suggested-by: Andrew Morton Reviewed-by: Harry Yoo (Meta) Reviewed-by: Qi Zheng Acked-by: Muchun Song Assisted-by: LLM Cc: Dave Chinner Cc: Roman Gushchin Cc: Johannes Weiner Cc: Michal Hocko Cc: Shakeel Butt (cherry picked from commit b36b71cb22027228fcc0f3a64c0f36900142c637) Adapted: in 6.12 mem_cgroup_init() is a subsys_initcall and runs after cgroup_init() has brought the root memcg online, which already needs the cache. Create it where the root memcg is allocated, in mem_cgroup_css_alloc(), instead: the function is __ref, and its root branch runs once, from __init cgroup_init_subsys(). https://virtuozzo.atlassian.net/browse/VSTOR-144714 Feature: mm/shrinker: sparse per-memcg shrinker units Assisted-by: LLM Signed-off-by: Konstantin Khorenko --- Port of the mainline patch that moves the per-memcg shrinker_info_unit from kmalloc-1k, where almost half of every unit is padding, to a cache sized to the unit. Merged into mm-unstable as b36b71cb22027. One adaptation: in 6.12 mem_cgroup_init() is a subsys_initcall and runs after cgroup_init() has brought the root memcg online, so the cache is created in mem_cgroup_css_alloc() where the root memcg is allocated. https://virtuozzo.atlassian.net/browse/VSTOR-144714 --- include/linux/memcontrol.h | 1 + mm/memcontrol.c | 1 + mm/shrinker.c | 11 +++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 2772a7750fa4e..e5b8ac79f6c7c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1740,6 +1740,7 @@ static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) return false; } +void shrinker_unit_cache_init(void); int alloc_shrinker_info(struct mem_cgroup *memcg); void free_shrinker_info(struct mem_cgroup *memcg); void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4e0c0c46689aa..0734c0fa21d05 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4393,6 +4393,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) #endif page_counter_init(&memcg->cache, NULL, false); + shrinker_unit_cache_init(); root_mem_cgroup = memcg; return &memcg->css; } diff --git a/mm/shrinker.c b/mm/shrinker.c index a70074f7135a9..5e45b230a5ccf 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -12,6 +12,12 @@ DEFINE_MUTEX(shrinker_mutex); #ifdef CONFIG_MEMCG static int shrinker_nr_max; +static struct kmem_cache *shrinker_unit_cachep; + +void __init shrinker_unit_cache_init(void) +{ + shrinker_unit_cachep = KMEM_CACHE(shrinker_info_unit, SLAB_PANIC); +} static inline int shrinker_unit_size(int nr_items) { @@ -33,7 +39,7 @@ static inline void shrinker_unit_free(struct shrinker_info *info, int start) if (!unit[i]) break; - kfree(unit[i]); + kmem_cache_free(shrinker_unit_cachep, unit[i]); unit[i] = NULL; } } @@ -47,7 +53,8 @@ static inline int shrinker_unit_alloc(struct shrinker_info *new, int i; for (i = start; i < nr; i++) { - unit = kzalloc_node(sizeof(*unit), GFP_KERNEL, nid); + unit = kmem_cache_alloc_node(shrinker_unit_cachep, + GFP_KERNEL | __GFP_ZERO, nid); if (!unit) { shrinker_unit_free(new, start); return -ENOMEM; --- base-commit: ed6900fdc06c26a6b1dd37b4b4420157c9af0c95 change-id: 20261020-b4-prep-khorenko-vstor-144714-shrinkers-kmem_cache-d968e1813b70 Best regards, -- Konstantin Khorenko _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel