From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0155C369D7 for ; Thu, 24 Apr 2025 09:29:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2106B6B00A9; Thu, 24 Apr 2025 05:29:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A2EB6B00AA; Thu, 24 Apr 2025 05:29:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00FAC6B00AD; Thu, 24 Apr 2025 05:29:30 -0400 (EDT) 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 D45D46B00A9 for ; Thu, 24 Apr 2025 05:29:30 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A1A1A1CF352 for ; Thu, 24 Apr 2025 09:29:30 +0000 (UTC) X-FDA: 83368414500.14.8EAF63D Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf11.hostedemail.com (Postfix) with ESMTP id A292940007 for ; Thu, 24 Apr 2025 09:29:28 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=earVKD1V; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745486968; a=rsa-sha256; cv=none; b=KkARquUSM3T+QdYnuzBXoeOFfHIjDF860SODcbyL0T95nGVQMqR8XSDvWgI9iQGlTptw8d vFtfkyh5fVZlqMsMOhgzHfDsv0gIun0lpvlwms14TC2TO2Cpt7WVJJxXTozKcQFQQScdWw SNH/sy+DrA+H9Oeguaefl+QNMo6Mjxc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=earVKD1V; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745486968; 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=emqJp3Dr3uZ/0FPx2fo09TOUZ7mzAJd83ebP+rzKJaY=; b=HzLwBl3219mfsulPnro+mZ36pkZJcEDJPmzk5FFF2IuOpNmty/bDKxS2df06ADK6+ohThh 2liXWb73TUGiGpzi+ttgU2xe56+oovuU97ORlGKkpIZQNp8mRn4ut4uBjAeO/rxHBW1vc2 RE/LC2odyMMIn36vJkOJcdAQgLav+/Q= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5f4ca707e31so1255859a12.2 for ; Thu, 24 Apr 2025 02:29:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745486967; x=1746091767; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=emqJp3Dr3uZ/0FPx2fo09TOUZ7mzAJd83ebP+rzKJaY=; b=earVKD1VLBJikQT8JuPpfn5KjGzI5d35+L67122TQeSYHDDhKcSrVR+rLc2KYI/NoF WFg9WcipwdPqkANv5B8RozTLNwmCNgabdAPdj+6FWAjJoIDgvqsJywTwrRMiA5aroUoF sjr4Poj3VRGMlIqg9ZtYAoT/lxGlXlMokIHLX1boxAwIC2unzhf9ba1OlqkcTBIIySxR jr/ZzEG3fgwn++3dw6iiuUj4Av0+K6K182c4/dRYerdtmrGhQrXHq2RElD4JggJU2AzR aRHZtYww3fQhNTy32frpg/Gbd0ZRStpT6TO4FC4AzbHlmVEeklyuv+ohndzi52QkiUAH dHTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745486967; x=1746091767; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=emqJp3Dr3uZ/0FPx2fo09TOUZ7mzAJd83ebP+rzKJaY=; b=XRCKsYlUqATwRnFwhhainc2+6MlDjOhyaJav3InvmhTMJyh+HEXcbtbtdG5biTwe7i eYkM+5VefXPtpDDAA78GS3i66ga0f6IYKsAafW7Hlgrp6Dd83Y562Z2cseslw/uUiCrr ucnbBd2qdHktYuR3L6Lnbuy/7GnJi+f9FxBwQwWrWlmymxXyNdWJgQKmytaMxOlsM93Z hXJkzzlN5BE8Zo2U0E7ctUn2AYoZM5XSdLCjKbq7sHBZaPXjf03/tJ4Ep3zem96TfD4P LOhoWOosJXIexEwrOCVfpojeq+VyHGVlbe0zyVbsone44Qekq+cZQNFCoJ7Ch0cDRH7a g5zA== X-Forwarded-Encrypted: i=1; AJvYcCXaGOlgijkCJ483QrmFi88SLXtFXriauq/KaWci9uRZsw1yRCwKr33UalBVRmbFAJSEjJNKzfzMNg==@kvack.org X-Gm-Message-State: AOJu0Yy76L0eo3Va6Vp4SeciDVuQzCG6JcBmsPC2qZmzhaGF3uqQ4OSw spTP5LUqdvCtMCiS0cV0+7WmmKi5fE7LDQ+mw6aB2dCGO7aL7cQartod3XlYOmlIHkz4Jj2s7uj NB+7NnqBHWVCIEoRErHUPMA/z6Z0= X-Gm-Gg: ASbGncs5ixXj4JKQI9DpSbn6p57+76DCllCqs0ED/zUWzAFRHDES3r4pPJ40mDDKCqh qO7bYhAdu9fqaRDHYyGDtgBIcr/q+H5GlAwHwGcTTl4h8lydccUM2awFk1EBpYic4AydercfE6R UqjFPxIQ5HVY5HAS6ZWejhaA== X-Google-Smtp-Source: AGHT+IGTmo4D66ZzGkHf+lx5EU/fmhf5RaiBs35BZ1O8MoD5zN9qYJBzHB6QN2m1D4wXScfTxlhD5XXd1ubwsXWmDac= X-Received: by 2002:a17:907:8691:b0:acb:b900:2bc5 with SMTP id a640c23a62f3a-ace572b4619mr208700866b.32.1745486966648; Thu, 24 Apr 2025 02:29:26 -0700 (PDT) MIME-Version: 1.0 References: <20250424080755.272925-1-harry.yoo@oracle.com> In-Reply-To: <20250424080755.272925-1-harry.yoo@oracle.com> From: Mateusz Guzik Date: Thu, 24 Apr 2025 11:29:13 +0200 X-Gm-Features: ATxdqUFpT2K9i5NWIy4iBrdWe1JtpjyVecpNXJAMCqjsnXGDj1PZMLKaE2iQQq8 Message-ID: Subject: Re: [RFC PATCH 0/7] Reviving the slab destructor to tackle the percpu allocator scalability problem To: Harry Yoo Cc: Vlastimil Babka , Christoph Lameter , David Rientjes , Andrew Morton , Dennis Zhou , Tejun Heo , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vlad Buslov , Yevgeny Kliteynik , Jan Kara , Byungchul Park , linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: A292940007 X-Stat-Signature: 6n7n5p1b4967q474ic85fhoz85tqo488 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1745486968-281861 X-HE-Meta: U2FsdGVkX19U8391+NKlTfcX85PlaAwOvsinjtmID1WOtprDV+vf6DGZyxOCRnTzKcAu/wii6oCypqUquPJ+1V4Sbyb7dojUOVF01MJ2Xj1pTX+eExERaqv758A4Kwffyrbg3v9nBefwB/0ZBEDwvLZizq+WN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JeWZgEDh5LNg4Fv5ucB1gcr+uNEDDrE5vL+KnyjbuFo9fy1zh+QiCcoQv+DqKkIBsG6IB+utx0kOb79ajRemk/aFWQAAydKRdVFREtn0R9xxXFjqBDv6jqyTnKBxNmlorfmOHyywv/3Xcgxxt/X2tgsSYoZ4V/cIrvJ4e9/jc8SBgawQYWojXzwgIdaXEF0eQTnQ3wQLHfhtPq7gubwCKU24VCUu91dl9NXtrbWXsBYov8OwYEC5Qm57mAfo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Apr 24, 2025 at 10:08=E2=80=AFAM Harry Yoo w= rote: > > Overview > =3D=3D=3D=3D=3D=3D=3D=3D > > The slab destructor feature existed in early days of slab allocator(s). > It was removed by the commit c59def9f222d ("Slab allocators: Drop support > for destructors") in 2007 due to lack of serious use cases at that time. > > Eighteen years later, Mateusz Guzik proposed [1] re-introducing a slab > constructor/destructor pair to mitigate the global serialization point > (pcpu_alloc_mutex) that occurs when each slab object allocates and frees > percpu memory during its lifetime. > > Consider mm_struct: it allocates two percpu regions (mm_cid and rss_stat)= , > so each allocate=E2=80=93free cycle requires two expensive acquire/releas= e on > that mutex. > > We can mitigate this contention by retaining the percpu regions after > the object is freed and releasing them only when the backing slab pages > are freed. > > How to do this with slab constructors and destructors: the constructor > allocates percpu memory, and the destructor frees it when the slab pages > are reclaimed; this slightly alters the constructor=E2=80=99s semantics, > as it can now fail. > > This series is functional (although not compatible with MM debug > features yet), but still far from perfect. I=E2=80=99m actively refining = it and > would appreciate early feedback before I improve it further. :) > Thanks for looking into this. The dtor thing poses a potential problem where a dtor acquiring arbitrary locks can result in a deadlock during memory reclaim. So for this to be viable one needs to ensure that in the worst case this only ever takes leaf-locks (i.e., locks which are last in any dependency chain -- no locks are being taken if you hold one). This needs to demonstrate the percpu thing qualifies or needs to refactor it to that extent. > This series is based on slab/for-next [2]. > > Performance Improvement > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > I measured the benefit of this series for two different users: > exec() and tc filter insertion/removal. > > exec() throughput > ----------------- > > The performance of exec() is important when short-lived processes are > frequently created. For example: shell-heavy workloads and running many > test cases [3]. > > I measured exec() throughput with a microbenchmark: > - 33% of exec() throughput gain on 2-socket machine with 192 CPUs, > - 4.56% gain on a desktop with 24 hardware threads, and > - Even 4% gain on a single-threaded exec() throughput. > > Further investigation showed that this was due to the overhead of > acquiring/releasing pcpu_alloc_mutex and its contention. > > See patch 7 for more detail on the experiment. > > Traffic Filter Insertion and Removal > ------------------------------------ > > Each tc filter allocates three percpu memory regions per tc_action object= , > so frequently inserting and removing filters contend heavily on the same > mutex. > > In the Linux-kernel tools/testing tc-filter benchmark (see patch 4 for > more detail), I observed a 26% reduction in system time and observed > much less contention on pcpu_alloc_mutex with this series. > > I saw in old mailing list threads Mellanox (now NVIDIA) engineers cared > about tc filter insertion rate; these changes may still benefit > workloads they run today. > > Feedback Needed from Percpu Allocator Folks > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > As percpu allocator is directly affected by this series, this work > will need support from the percpu allocator maintainers, and we need to > address their concerns. > > They will probably say "This is a percpu memory allocator scalability > issue and we need to make it scalable"? I don't know. > > What do you say? > > Some hanging thoughts: > - Tackling the problem on the slab side is much simpler, because the slab > allocator already caches objects per CPU. Re-creating similar logic > inside the percpu allocator would be redundant. > > Also, since this is opt-in per slab cache, other percpu allocator > users remain unaffected. > > - If fragmentation is a concern, we could probably allocate larger percpu > chunks and partition them for slab objects. > > - If memory overhead becomes an issue, we could introduce a shrinker > to free empty slabs (and thus releasing underlying percpu memory chunks= ). > > Patch Sequence > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > Patch #1 refactors freelist_shuffle() to allow the slab constructor to > fail in the next patch. > > Patch #2 allows the slab constructor fail. > > Patch #3 implements the slab destructor feature. > > Patch #4 converts net/sched/act_api to use the slab ctor/dtor pair. > > Patch #5, #6 implements APIs to charge and uncharge percpu memory and > percpu counter. > > Patch #7 converts mm_struct to use the slab ctor/dtor pair. > > Known issues with MM debug features > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > The slab destructor feature is not yet compatible with KASAN, KMEMLEAK, > and DEBUG_OBJECTS. > > KASAN reports an error when a percpu counter is inserted into the > percpu_counters linked list because the counter has not been allocated > yet. > > DEBUG_OBJECTS and KMEMLEAK complain when the slab object is freed, while > the associated percpu memory is still resident in memory. > > I don't expect fixing these issues to be too difficult, but I need to > think a little bit to fix it. > > [1] https://lore.kernel.org/linux-mm/CAGudoHFc+Km-3usiy4Wdm1JkM+YjCgD9A8d= DKQ06pZP070f1ig@mail.gmail.com > > [2] https://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git/log/?= h=3Dslab/for-next > > [3] https://lore.kernel.org/linux-mm/20230608111408.s2minsenlcjow7q3@quac= k3 > > [4] https://lore.kernel.org/netdev/vbfmunui7dm.fsf@mellanox.com > > Harry Yoo (7): > mm/slab: refactor freelist shuffle > treewide, slab: allow slab constructor to return an error > mm/slab: revive the destructor feature in slab allocator > net/sched/act_api: use slab ctor/dtor to reduce contention on pcpu > alloc > mm/percpu: allow (un)charging objects without alloc/free > lib/percpu_counter: allow (un)charging percpu counters without > alloc/free > kernel/fork: improve exec() throughput with slab ctor/dtor pair > > arch/powerpc/include/asm/svm.h | 2 +- > arch/powerpc/kvm/book3s_64_mmu_radix.c | 3 +- > arch/powerpc/mm/init-common.c | 3 +- > arch/powerpc/platforms/cell/spufs/inode.c | 3 +- > arch/powerpc/platforms/pseries/setup.c | 2 +- > arch/powerpc/platforms/pseries/svm.c | 4 +- > arch/sh/mm/pgtable.c | 3 +- > arch/sparc/mm/tsb.c | 8 +- > block/bdev.c | 3 +- > drivers/dax/super.c | 3 +- > drivers/gpu/drm/i915/i915_request.c | 3 +- > drivers/misc/lkdtm/heap.c | 12 +-- > drivers/usb/mon/mon_text.c | 5 +- > fs/9p/v9fs.c | 3 +- > fs/adfs/super.c | 3 +- > fs/affs/super.c | 3 +- > fs/afs/super.c | 5 +- > fs/befs/linuxvfs.c | 3 +- > fs/bfs/inode.c | 3 +- > fs/btrfs/inode.c | 3 +- > fs/ceph/super.c | 3 +- > fs/coda/inode.c | 3 +- > fs/debugfs/inode.c | 3 +- > fs/dlm/lowcomms.c | 3 +- > fs/ecryptfs/main.c | 5 +- > fs/efs/super.c | 3 +- > fs/erofs/super.c | 3 +- > fs/exfat/cache.c | 3 +- > fs/exfat/super.c | 3 +- > fs/ext2/super.c | 3 +- > fs/ext4/super.c | 3 +- > fs/fat/cache.c | 3 +- > fs/fat/inode.c | 3 +- > fs/fuse/inode.c | 3 +- > fs/gfs2/main.c | 9 +- > fs/hfs/super.c | 3 +- > fs/hfsplus/super.c | 3 +- > fs/hpfs/super.c | 3 +- > fs/hugetlbfs/inode.c | 3 +- > fs/inode.c | 3 +- > fs/isofs/inode.c | 3 +- > fs/jffs2/super.c | 3 +- > fs/jfs/super.c | 3 +- > fs/minix/inode.c | 3 +- > fs/nfs/inode.c | 3 +- > fs/nfs/nfs42xattr.c | 3 +- > fs/nilfs2/super.c | 6 +- > fs/ntfs3/super.c | 3 +- > fs/ocfs2/dlmfs/dlmfs.c | 3 +- > fs/ocfs2/super.c | 3 +- > fs/openpromfs/inode.c | 3 +- > fs/orangefs/super.c | 3 +- > fs/overlayfs/super.c | 3 +- > fs/pidfs.c | 3 +- > fs/proc/inode.c | 3 +- > fs/qnx4/inode.c | 3 +- > fs/qnx6/inode.c | 3 +- > fs/romfs/super.c | 3 +- > fs/smb/client/cifsfs.c | 3 +- > fs/squashfs/super.c | 3 +- > fs/tracefs/inode.c | 3 +- > fs/ubifs/super.c | 3 +- > fs/udf/super.c | 3 +- > fs/ufs/super.c | 3 +- > fs/userfaultfd.c | 3 +- > fs/vboxsf/super.c | 3 +- > fs/xfs/xfs_super.c | 3 +- > include/linux/mm_types.h | 40 ++++++--- > include/linux/percpu.h | 10 +++ > include/linux/percpu_counter.h | 2 + > include/linux/slab.h | 21 +++-- > ipc/mqueue.c | 3 +- > kernel/fork.c | 65 +++++++++----- > kernel/rcu/refscale.c | 3 +- > lib/percpu_counter.c | 25 ++++++ > lib/radix-tree.c | 3 +- > lib/test_meminit.c | 3 +- > mm/kfence/kfence_test.c | 5 +- > mm/percpu.c | 79 ++++++++++------ > mm/rmap.c | 3 +- > mm/shmem.c | 3 +- > mm/slab.h | 11 +-- > mm/slab_common.c | 43 +++++---- > mm/slub.c | 105 ++++++++++++++++------ > net/sched/act_api.c | 82 +++++++++++------ > net/socket.c | 3 +- > net/sunrpc/rpc_pipe.c | 3 +- > security/integrity/ima/ima_iint.c | 3 +- > 88 files changed, 518 insertions(+), 226 deletions(-) > > -- > 2.43.0 > --=20 Mateusz Guzik