Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5557291rwd; Wed, 24 May 2023 03:42:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66eU5ssy5sJDwEVRjgRkdfJomc/2vH8lWhimv6fvrkqwHZ890XucqatFJD+/6L9/r8uCbX X-Received: by 2002:a05:6a20:8e07:b0:101:47d8:ff86 with SMTP id y7-20020a056a208e0700b0010147d8ff86mr20391255pzj.34.1684924954112; Wed, 24 May 2023 03:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684924954; cv=none; d=google.com; s=arc-20160816; b=jRgHTB+ZI6CVTwtc2JVY2wASm59oqVaqCU/8AcQMtX56vJdUf18KrcmCs1Sip2P/01 Jf0OwCyIyjYBUn1EY8ScltaxeocSJ91tmUjJgLfb0Ev60XzTA5jUxGS010PNo5ZNqYSo cIrLowtSOma4v3esoWWSSK+1TKdrbQ0ZCVNTWsyxAjMgjd9YaqcmHM6dwW5Fjwe/Krkc 34LcAERv3t54orZ93x2/PpNaS2Pwf4QVU8nZqJl/VUfaVRIkSrtbVOu9m9A3+1DtfWia Po6Dc5ii9GuVJ9LrQaGRMdwbjnOa8E/a0Oldg9GXl9/WJid9tpOggfuyt07mrnqTY1JV LupA== 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:dkim-signature; bh=hliaaV35ugS9mBcv4FyggOLg0wQ/iiY9Q3rhXXLm7AY=; b=TmLSgPB7IOOID+wXA2WSndzEj3gN9W7SNss/+mREnw+iErAfLunKgYSrZcfLvMb4UE NX4V2NMRVgs26S/igL5O2gNnC3t16EBuipI5THGuJUXNFm3ggvKs9g9LSWkTRWsoc0TD M8MD7bQr/ozvIB0kLibLvpInFb2mysmwwVdwtA/Xypq2eTJ4xUJnJ6NMGDReyPc1r0+x wCEXVxqb9QbbCekK5exPutz7+HbBlM1B6BWI45+tplQr9Gbi66e1Pjfo39NHr9/RC7G3 gCCc+1qIMPathB6wj1qDWJKqa6hIah+7hIRvNNy3uxQFz1qDK3vgLNasAU+nhn56BNor w6iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=OnzsDya3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gc7-20020a17090b310700b002532c8283afsi886024pjb.47.2023.05.24.03.42.19; Wed, 24 May 2023 03:42:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=OnzsDya3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232377AbjEXKYC (ORCPT + 99 others); Wed, 24 May 2023 06:24:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231506AbjEXKYA (ORCPT ); Wed, 24 May 2023 06:24:00 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3065011D for ; Wed, 24 May 2023 03:23:59 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id C39E2223D9; Wed, 24 May 2023 10:23:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1684923837; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hliaaV35ugS9mBcv4FyggOLg0wQ/iiY9Q3rhXXLm7AY=; b=OnzsDya3ECMF2LW6Tu/DQER+kYAv7897Jlj7xXn2quQ6zFhHc52EY2t73zWroFdhxnRlS8 T0FQQgynmCyjp6WmPTUgows5xs+X177KlarU2SuH+TM+byVtXWtgxvH8lpKr9tMnUs4Efg /phot2QbYeGI56UFHOBRcLzZLJxv7Zs= Received: from ds.suse.cz (ds.suse.cz [10.100.12.205]) by relay2.suse.de (Postfix) with ESMTP id 1B9BA2C141; Wed, 24 May 2023 10:23:57 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id DE97ADA7D7; Wed, 24 May 2023 12:17:50 +0200 (CEST) From: David Sterba To: Christoph Lameter , David Rientjes , Pekka Enberg , Vlastimil Babka Cc: Andrew Morton , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Joonsoo Kim , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Roman Gushchin , David Sterba Subject: [PATCH] mm/slab: add new flag SLAB_NO_MERGE to avoid merging per slab Date: Wed, 24 May 2023 12:17:48 +0200 Message-Id: <20230524101748.30714-1-dsterba@suse.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a flag that allows to disable merging per slab. This can be used for more fine grained control over the caches or for debugging builds where separate slabs can verify that no objects leak. The slab_nomerge boot option is too coarse and would need to be enabled on all testing hosts. There are some other ways how to disable merging, e.g. a slab constructor but this disables poisoning besides that it adds additional overhead. Other flags are internal and may have other semantics. A concrete example what motivates the flag. During 'btrfs balance' slab top reported huge increase in caches like 1330095 1330095 100% 0.10K 34105 39 136420K Acpi-ParseExt 1734684 1734684 100% 0.14K 61953 28 247812K pid_namespace 8244036 6873075 83% 0.11K 229001 36 916004K khugepaged_mm_slot which was confusing and that it's because of slab merging was not the first idea. After rebooting with slab_nomerge all the caches were from btrfs_ namespace as expected. Signed-off-by: David Sterba --- include/linux/slab.h | 3 +++ mm/slab_common.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 6b3e155b70bf..06b94dfbce65 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -106,6 +106,9 @@ /* Avoid kmemleak tracing */ #define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000U) +/* Don't merge slab */ +#define SLAB_NO_MERGE ((slab_flags_t __force)0x01000000U) + /* Fault injection mark */ #ifdef CONFIG_FAILSLAB # define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000U) diff --git a/mm/slab_common.c b/mm/slab_common.c index 607249785c07..0e0a617eae7d 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -47,7 +47,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, */ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | kasan_never_merge()) + SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge()) #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT) -- 2.40.0