Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp668297pxb; Wed, 13 Jan 2021 12:59:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1YWMbYQ01+/UWPrzL3oaw56I/YOgoZA1+dFbGMo+aCxVJmeAWYgIzuDEh6OdboQ+M9x35 X-Received: by 2002:a17:906:cb86:: with SMTP id mf6mr2850210ejb.57.1610571598588; Wed, 13 Jan 2021 12:59:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610571598; cv=none; d=google.com; s=arc-20160816; b=wFmPAHORdPX0nFy05ZcLxZtmaj/dTb2ChipgGjFHCckWxb9lMaE3vJS07hBlg37VXS B7KFDlrfbqcSELJjjh3byQpem1gWreS//GP3agDRsRWwQAQJCvqkfJzg1Xh/OqpMZbEY 3p0WP/EB8pdUj/x9tWV1fS93tacDhePBT7aDY7Ei2o6z8C1tqc04IUyhkHa6akSI5F/a 085ZsY7p58ZI7CoYpXavyfZ6p5qBXlMvuVzoW4oWMG0Fc+ek3bgnij63ZcO7cvive1d8 J81BvLzvIw6py5wZTPfV7RVSMCaE77yN4qTAzRnzNk/dFU9zHRlXhUXbrfy5BvesPnfP W2LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=FGhiq96cd45nMjZLm6AsZcPhzp/dAzHnYixuzPkgo5s=; b=fwfzPngQQP8ux6xy2f1q/k/lUmCs0Xo5GKoS3OWf3AgfM57OHPBxyO2kXY+FIyx1DC EW8KO1I4qM1+r5Mi3xbv73qVquvAQGHMvIRcKXPVoEpTWV4jmDT4NUq4j+xwGL81HSl+ HJSJJvM1z1xFVLwGn0t+HKN+lVhWnhWuYHG5JrUNFXRqOoBzsOS+bCNMz01KnbcDq7lq SiteAkvRCuLdywc9QfU4qBr/uIvq3XUg5uWnEzvfVUAOdE/LJvfM0X1tAebPRVTnFSDS EaXqWB8UV+pWNOft4s9xZpCCUMJm3qu1w90oaFWW7p84j6DaGvy2MiqRBtR8O4A+FZpI Yj8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si1585769edb.389.2021.01.13.12.59.34; Wed, 13 Jan 2021 12:59:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728980AbhAMUwJ (ORCPT + 99 others); Wed, 13 Jan 2021 15:52:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbhAMUwJ (ORCPT ); Wed, 13 Jan 2021 15:52:09 -0500 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A0FC061575 for ; Wed, 13 Jan 2021 12:51:29 -0800 (PST) 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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, -- 2.26.2