From patchwork Wed Nov 29 09:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13472573 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 EF0ACC07CB1 for ; Wed, 29 Nov 2023 09:53:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 058936B03BA; Wed, 29 Nov 2023 04:53:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 721296B03BE; Wed, 29 Nov 2023 04:53:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1547D6B03BE; Wed, 29 Nov 2023 04:53:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 552896B03C2 for ; Wed, 29 Nov 2023 04:53:42 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 243CE1404F1 for ; Wed, 29 Nov 2023 09:53:42 +0000 (UTC) X-FDA: 81510529884.22.57C1699 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf27.hostedemail.com (Postfix) with ESMTP id DEC0640004 for ; Wed, 29 Nov 2023 09:53:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701251620; 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; bh=DUPnHPdnAWU/UCFeEX1tNeDnCcnIMYmNivE3br+UPhg=; b=ZKISDxQenbfYJyb/putVH9rizQdRT7Xq+W/O2eNAVQedTHasWWjO5tt1N1s+PqAyJrSfrv cTp40XrhHsPCOBY2hqGZeqIYmclCv4vwhJSDgFUk3Ez6km8owFpVg3Oq1hgj6S/aYVazMt 8/oi9aA+cQFL8tclfsQLiK6d0uNjaII= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701251620; a=rsa-sha256; cv=none; b=gnK5efGObMXp3ytftH5a8N5t7+Cqvvf+Cv3BLvYi4tBlhS/bKIfLFYixZsA5OVSl30AqyO Y3DdLJo2RuOZwbFPxy1XuJCLXr5WES5PYvYis4LYORaFoF6spN3eVURs92RUrBhtM6xgw9 2djmj7c8N1an2Ewair4vs6mwmfOTQrE= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E3FEA21990; Wed, 29 Nov 2023 09:53:36 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C819013A96; Wed, 29 Nov 2023 09:53:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wISPMCAKZ2UrfQAAD6G6ig (envelope-from ); Wed, 29 Nov 2023 09:53:36 +0000 From: Vlastimil Babka Date: Wed, 29 Nov 2023 10:53:26 +0100 Subject: [PATCH RFC v3 1/9] mm/slub: fix bulk alloc and free stats MIME-Version: 1.0 Message-Id: <20231129-slub-percpu-caches-v3-1-6bcf536772bc@suse.cz> References: <20231129-slub-percpu-caches-v3-0-6bcf536772bc@suse.cz> In-Reply-To: <20231129-slub-percpu-caches-v3-0-6bcf536772bc@suse.cz> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Matthew Wilcox , "Liam R. Howlett" Cc: Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Alexander Potapenko , Marco Elver , Dmitry Vyukov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, kasan-dev@googlegroups.com, Vlastimil Babka X-Mailer: b4 0.12.4 X-Spamd-Bar: ++++++++++++ X-Rspamd-Queue-Id: DEC0640004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: x8dfhkuzdrw67ka6qk1p34mzd65mdbwg X-HE-Tag: 1701251619-174418 X-HE-Meta: U2FsdGVkX18cs/3FdrVIQTYadERWsMzSeXbgT5Bs1ASaX7u87Uf2zs5L5CBK/60xuCKsahqmRpSKoRh8Qvh1njKwA9fmX2G5g1lUMXfHlvWEDoHdmfk5QMprSxMYOiw8XBokOitWqZS01RdojhcdTbi+amIbL8IJtcyUIAc96Ay8Qhe6D35Ml+PdrJH9rNAvx/vxkC5FN+Q22kdbDRYp1J41dRs/0a1/WRwZaEbOVBuR5UIn0YGm7gENOFSTa+yv33pxZivyTI8Wwy3qluuhpFEn6w4oHoKho/8YAtCydjudXO3FTTWDW7C57RYdtnhVDexuGMHZATLciorLMDWR7KvJORJ02Elrdl8MVlaNw2TTSbGESTlzv9G2snCwvTs5c6JLHNFMWioDYUCfQMycpvlwTBgTxtPjxFPjusrlwxkjLKE62LiMYupyRXeGfqh0LU6kG6lbRu/catY+A82EPiJtlI/mCGV6yQxFimpC81hTcR/v4kOuRYg7f7Pb5j94nn+CHNAveeTie3fyiQom5Wnmo6mjx8mdOr7L5y4MhP98tCAYmC7YSs70eMHGkEH6qPnziBQ+Y2GJKNxLebmyDdCyGUPTrb9lsZtYl2U3ArzWqgvGKEUejXoVFmwIE4kgb9Sys8cxzH6oLJhIU4kXyZyAQ76IQbR6eNG7YOGSnCzkjNGjBgXvpRzVXGOM0pX3FpA4rKCGIYz9tIkZVxiOlf27Qvxn+Ml2GaVfBGWG2aHoCHk61KfQEu5NnRTayo96IACOSZr9dC4M2w+uC725q8ySqG4e/P0BAF2ZvKnc5r3h2cbkW7zKpWMtOpN4lb6gfDt/ukFXl9WLeSjddd+unSkTbaLZhEa9iTEbA3SqI10GxG96ojsZ74/1eNCK0D0vVbspT+whe22XbLutOPgsad4aOr+z/HO5sGbVRDPiKENpFjTaohquepWDurRNL8BgWS+l1L99LrbeWGmYX3f IL2Czh37 csWODmEAC/SQsCIdSRY2fssbbDfR/LUCZzZ1scYmDkMLY5aigddHLFsuGeDIMexMRuPIKM2OWmxjA2Cv6h1Pg4DfvmtYpPVEhlIvG5w1zUL9XmQAPtoVthWew8Xo5RgJOWzR7YHluWTkiu/fgsuj7hOYCFNtHN5Bki4aPz1d6iBUonlL62lWs+6FR8YfvAZAgMs77 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: The SLUB sysfs stats enabled CONFIG_SLUB_STATS have two deficiencies identified wrt bulk alloc/free operations: - Bulk allocations from cpu freelist are not counted. Add the ALLOC_FASTPATH counter there. - Bulk fastpath freeing will count a list of multiple objects with a single FREE_FASTPATH inc. Add a stat_add() variant to count them all. Signed-off-by: Vlastimil Babka --- mm/slub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 63d281dfacdb..f0cd55bb4e11 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -341,6 +341,14 @@ static inline void stat(const struct kmem_cache *s, enum stat_item si) #endif } +static inline void stat_add(const struct kmem_cache *s, enum stat_item si, int v) +{ +#ifdef CONFIG_SLUB_STATS + raw_cpu_add(s->cpu_slab->stat[si], v); +#endif +} + + /* * Tracks for which NUMA nodes we have kmem_cache_nodes allocated. * Corresponds to node_state[N_NORMAL_MEMORY], but can temporarily @@ -3784,7 +3792,7 @@ static __always_inline void do_slab_free(struct kmem_cache *s, local_unlock(&s->cpu_slab->lock); } - stat(s, FREE_FASTPATH); + stat_add(s, FREE_FASTPATH, cnt); } #else /* CONFIG_SLUB_TINY */ static void do_slab_free(struct kmem_cache *s, @@ -3986,6 +3994,7 @@ static inline int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, c->freelist = get_freepointer(s, object); p[i] = object; maybe_wipe_obj_freeptr(s, p[i]); + stat(s, ALLOC_FASTPATH); } c->tid = next_tid(c->tid); local_unlock_irqrestore(&s->cpu_slab->lock, irqflags);