From patchwork Wed Jan 13 20:51:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 12017827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61246C433DB for ; Wed, 13 Jan 2021 20:51:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7059A23107 for ; Wed, 13 Jan 2021 20:51:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7059A23107 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sipsolutions.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 897C48D0094; Wed, 13 Jan 2021 15:51:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81FEC8D008E; Wed, 13 Jan 2021 15:51:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E598D0094; Wed, 13 Jan 2021 15:51:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 5881D8D008E for ; Wed, 13 Jan 2021 15:51:28 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 197B41EE6 for ; Wed, 13 Jan 2021 20:51:28 +0000 (UTC) X-FDA: 77701947456.29.coast94_3b09a2727521 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id C83841809056C for ; Wed, 13 Jan 2021 20:51:27 +0000 (UTC) X-HE-Tag: coast94_3b09a2727521 X-Filterd-Recvd-Size: 2930 Received: from sipsolutions.net (s3.sipsolutions.net [144.76.43.62]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Wed, 13 Jan 2021 20:51:27 +0000 (UTC) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94) (envelope-from ) id 1kzn6y-005uvP-KI; Wed, 13 Jan 2021 21:51:24 +0100 From: Johannes Berg To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Catalin Marinas , Vlastimil Babka , Johannes Berg Subject: [PATCH v2] mm/slub: disable user tracing for kmemleak caches by default Date: Wed, 13 Jan 2021 21:51:14 +0100 Message-Id: <20210113215114.d94efa13ba30.I117b6764e725b3192318bbcf4269b13b709539ae@changeid> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 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: From: Johannes Berg If kmemleak is enabled, it uses a kmem cache for its own objects. These objects are used to hold information kmemleak uses, including a stack trace. If slub_debug is also turned on, each of them has *another* stack trace, so the overhead adds up, and on my tests (on ARCH=um, admittedly) 2/3rds of the allocations end up being doing the stack tracing. Turn off SLAB_STORE_USER if SLAB_NOLEAKTRACE was given, to avoid storing the essentially same data twice. Signed-off-by: Johannes Berg Acked-by: Vlastimil Babka Acked-by: Catalin Marinas Acked-by: David Rientjes --- Perhaps instead it should go the other way around, and kmemleak could even use/access the stack trace that's already in there ... But I don't really care too much, I can just turn off slub debug for the kmemleak caches via the command line anyway :-) v2: - strip SLAB_STORE_USER only coming from slub_debug so that the command line args always take effect --- mm/slub.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 34dcc09e2ec9..a66c9948c529 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1412,6 +1412,15 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, size_t len; char *next_block; slab_flags_t block_flags; + slab_flags_t slub_debug_local = slub_debug; + + /* + * If the slab cache is for debugging (e.g. kmemleak) then + * don't store user (stack trace) information by default, + * but let the user enable it via the command line below. + */ + if (flags & SLAB_NOLEAKTRACE) + slub_debug_local &= ~SLAB_STORE_USER; len = strlen(name); next_block = slub_debug_string; @@ -1446,7 +1455,7 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, } } - return flags | slub_debug; + return flags | slub_debug_local; } #else /* !CONFIG_SLUB_DEBUG */ static inline void setup_object_debug(struct kmem_cache *s,