From patchwork Mon Dec 4 19:34:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13479022 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 61072C10DC1 for ; Mon, 4 Dec 2023 19:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAAAF6B02EB; Mon, 4 Dec 2023 14:34:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C5286B02FA; Mon, 4 Dec 2023 14:34:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 701AC6B02F1; Mon, 4 Dec 2023 14:34:57 -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 420806B02E7 for ; Mon, 4 Dec 2023 14:34:57 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DE8751C0608 for ; Mon, 4 Dec 2023 19:34:56 +0000 (UTC) X-FDA: 81530138592.15.8ACD716 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf02.hostedemail.com (Postfix) with ESMTP id 92A1F8000C for ; Mon, 4 Dec 2023 19:34:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3aoiT3pa; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LJvwh73C; dmarc=none; spf=pass (imf02.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=1701718495; 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=EqcJTAjZFB8lQHDKYDjIZchVKot1dBAP9whijzHZRBs=; b=aeXyAkIn8HuVATBNRJ71XpjYPNAuq0XXtyCssu5q9v5hH+QC33XpiP2ChrkhpU6I1kQLfv hMl1nGR6/3udnrBCrs3ndww5674vszEM+/wvmOTZBM8Bx+t1Qm2LDNRdSSr9g4WeTyaVPR t3+EpfHRw0QWYo56GU1SCCR2aG9jR8c= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=3aoiT3pa; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LJvwh73C; dmarc=none; spf=pass (imf02.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=1701718495; a=rsa-sha256; cv=none; b=cJ2f7baYUJlHwdKwE2PCEWUvKZoeRd/9z/vFaTUKDTAzsmZUd6zTTc1A71NgiDYXeGAUbt GQ9IEMo2fItGEIn6s/T2XisDQZu1oZoq3n9dd1MV0il0oE324BBD4VAj39CQgwsQ0IfI8C BX9JgsJKNalCik69ZfFBZM+kp4ALbss= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [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 8DF80220FD; Mon, 4 Dec 2023 19:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1701718492; h=from:from:reply-to: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=EqcJTAjZFB8lQHDKYDjIZchVKot1dBAP9whijzHZRBs=; b=3aoiT3paks0mcXiEeezN/xPw9jv7Di3tra3+7n/QDct0IcBebFNeztkLnzZNR1eA+r+5P7 5HTYlXZjd6w/d/4hPiYwAl8U4a6RDNwPAenVha70NBnhh7hjIhw5Mnrb5mEfP6x/vm7DcI RvtCEN+PAXA5BPRclQuH0Zu5ugFOvzQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1701718492; h=from:from:reply-to: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=EqcJTAjZFB8lQHDKYDjIZchVKot1dBAP9whijzHZRBs=; b=LJvwh73CRk0ogt5DyHZYk9KKPNPbooLArhcWhOV7Z8vEi3KnNjT7llf/nkqXmRF2A2S/E1 I9N7BuX+zof3jCDw== 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 70C1D13AC1; Mon, 4 Dec 2023 19:34:52 +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 KHI2G9wpbmUPMwAAD6G6ig (envelope-from ); Mon, 04 Dec 2023 19:34:52 +0000 From: Vlastimil Babka Date: Mon, 04 Dec 2023 20:34:40 +0100 Subject: [PATCH 1/4] mm/slub: fix bulk alloc and free stats MIME-Version: 1.0 Message-Id: <20231204-slub-cleanup-hooks-v1-1-88b65f7cd9d5@suse.cz> References: <20231204-slub-cleanup-hooks-v1-0-88b65f7cd9d5@suse.cz> In-Reply-To: <20231204-slub-cleanup-hooks-v1-0-88b65f7cd9d5@suse.cz> To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim 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, kasan-dev@googlegroups.com, Vlastimil Babka X-Mailer: b4 0.12.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 92A1F8000C X-Stat-Signature: cikwf3th78pidcmfqmr4s6e4yg7g1scp X-Rspam-User: X-HE-Tag: 1701718494-246981 X-HE-Meta: U2FsdGVkX1+VbpQYNt7h7yOMnBAKKOHhWP7XOgczj9ab3fDos7jYLmkKfpRaNkP1ZsBPWlj/MZstwmNwPWr9e7k3teKlrv4rxrOPlgPjTycY4Rlo7UPqpa6iz1x/IPlU0PJkNiu8N8CEEDjSpHvR9OEWoiLYnZoEL16UFzApYCaAhbR9hZekud5AqJdUrJcOuSeKZQ475Fl7E9YDb/mEzovRe/lcRmWZxEyX0Ei2NCOU3MANfZFCGD6zNJwCkFzfaQ8PgvspHV3ZtluhptfyTT0uX99rRh9185j3Y9gZRAxhtG3TivM7yOJARHIFsMXGK30aay1DgCY4Z9IRo2y57Hlo7It/y69qqQcsPzP3ApDNSD3E1EA0orJhwVuI9vV5m3oUZwcEkVhBhWFk58JEWkn9Hvc74xdu6v5xHT16uYsfMohjQ1oQgFCGQzZwTPBSb9LsSZHg8WBzQw3+VuemCziOD8Y+jlLBdolW28nO9yKhuUsg8ZT6bZZDwaDHgT0DP3HKXiF7wZKmiUB0auC4AZT7jCdnIeHxTSZmiWY1wn0J8Eh55+YElytc3G+aZZgQ3uxWl0miFmN8QWUiD013aQFv5zra29kXsDfUN6kLLItGb3X2yF3OiYUlTkEkEzdwxCJ0y3Zqsk+ITknzn4757WYLYorWkzo0xSToylN1lyj8wgmPapa7WZZKz/W8twaaE0quBnPCq0JBtqFmZ30RUIwPG/FB5GyPLPbArSG5gQXIwRbOJut5IzaiTn1bY069kxlCNz1vffbvg5iY6UPCHCcYdjgZT2iWx26oyBDMetF0hJ1HsrZfo7dGZks3pvtwluMbK39PobvAKjC1TYIycM/IVlEPRgv6nrEHM26nuv+D0MGq1+t6RZ6lrXn6qUr+OoDkgpauRUhvws9qKWMffStdlItDo+uJ9LCtyKJkh5qv3/d35d7xT0330/gBOl8T4GnUXBhsw01r9tpCX8A WNMFuynH dJrcmNxGG7+x3JCcwHOCv+NIC0YEV2VycYnKAgjXFMFu3aOHO6t1dLOv26QDi2KqrTEFVH4K3ZlPprRXr3IdNaEKmT6u2nH49xlhVw1UnObqGtmri75mgt4rv43GLpNYpuPjKMME7JA6ec4KHag7aDFIkyVtrhxxoIYyQR29Zt9OKbpNzFpWMQFkcG0vy+p++UuTgmA8k5Cjz5Fbkv46rBQqMatpOg36lS8CQenk0knFBSsS+jj3SzHfEFBK3CDNVhq/DwkPDov3YNa/BrYtMpNDv1/eZas8lOXJM3k9iT6+24Zs= 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 Reviewed-by: Chengming Zhou --- mm/slub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 3f8b95757106..d7b0ca6012e0 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -396,6 +396,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 +} + /* * The slab lists for all objects. */ @@ -4268,7 +4276,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, @@ -4545,6 +4553,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);