Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp598349lqp; Thu, 21 Mar 2024 09:51:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNQ4FAf1MlpPnQlTylc9IvNQw7u6GxtlunKffsSU8nqsieRitCE1iL2nkT5u2TZ089Qu8ygK94/F6Z60ChPrpdba41dBHDTzN8ezClMQ== X-Google-Smtp-Source: AGHT+IG/UOqHmH2e+pHj0TsZUFPt6Qvh5Ssqpr3y8zmcaYawr8Qd9aQXnDHOdNj1py89hRgJxILp X-Received: by 2002:a9d:69cd:0:b0:6e6:7bed:262b with SMTP id v13-20020a9d69cd000000b006e67bed262bmr6471997oto.2.1711039880270; Thu, 21 Mar 2024 09:51:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711039880; cv=pass; d=google.com; s=arc-20160816; b=OiS4V1kr0ahTbAxXfM6B1IHDLaSdXHAUj/m7A6kZmapTj3uu00h4zCm/CCcmpUXzsG 3Qiw07v2iWMf/+FPepX1Td2NIZcJS0Vu5LXQaYC3kQp/VkuzYAZEmnYPntGcFM/i7olU oSLV3L9Aku9s5Xe+syGfgeWCZUgmEOs8gkzhLHGmiaxr32QKRZB7yXyuDE4Rgszhz1JH 79dGvFcHwus02bylyw7xjVivhIzX076BZuIG0lwX9/2dtV7EaxzQAQVChbEGzdFUnxK6 RlN166DnoADxCNw4ovFUd9mgwLzQzqrSuZx5FwajUnQ6m7NLo+2O/O8Cbc7uiQ3Gu27T ogJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=XaC6gpRUGM+qkcKqV2c0VBwhZNh1AuaCpOBKo907lO0=; fh=RFX80Qe52J/qlEsKvMbCh68vU/SHkJxtUuTCakIEMkw=; b=lyUVgmOGMROqyd7Qnuj1cXYJYFUr/GCFbmoaVnCrFlys5ma8JPvZU7GAUvTydqmzuk cBDM4a7gvDrZ13L+X4yVrjXYWHxb1+iPyIDaLDtPX6dSudNvL4rXZ7uF4OmiagbHXaOz FGgIzqkDJBXD4GlQE1eutTAfBM2B1uQX54R8YrDS6xzcnRDveVOzapq14aL8+xm2iQ7a piDI5zKOc1LOCfcOoLLPLYd/nMS1YmafhrE3sErBv93or+UjnjHifdWkitHWOw7EvN4Y rDQkqSPXkBOXKGgziB9srgIeNC8NsucJF1rNDeK5P4OVeah/07zlMbI2CGeD7TQfdVv2 I+Tg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=drOoDhgj; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110391-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110391-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f18-20020a05620a409200b007882bc74632si120437qko.81.2024.03.21.09.51.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:51:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110391-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=drOoDhgj; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110391-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110391-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A46FC1C21E5F for ; Thu, 21 Mar 2024 16:51:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 34EE51448DA; Thu, 21 Mar 2024 16:38:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="drOoDhgj" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A8E914291A for ; Thu, 21 Mar 2024 16:38:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039101; cv=none; b=nij27/GJG5Vv2lsOQ2Q94zjc0EOwcc/HVAWkXV/oEataLAQIPQMZckM8cFNxtaIc08VzQkyyegb0welH9Eop043xYjqfiunaXmiXZqukDZhui1PyDbvW5D8GiJxrb3bUZy5l1SYDGRHSuUl3cAUgpuO7hjN0fV1CznqxW2s1A7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039101; c=relaxed/simple; bh=dLP/xEKvAlFy0CEGgcN9QUf+tNZYc143hgSrqnBpNn8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XG92xhZ2lPFrUSi8ccVhCeOAX2yPRcYdih9o+VqbElVjaKT7Hu2LOnzyLMmLhY678jj3abD/YJiHlAsg/2XZl78xDTKtzzwKuHwEJRS/suSx/80iGSW4k+yjJqiaFSx+/UyH2YVbJyCgyU2dlf92yM/g+H9mp83mV/9nz7ftJgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=drOoDhgj; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbee93a3e1so1862211276.3 for ; Thu, 21 Mar 2024 09:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039097; x=1711643897; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XaC6gpRUGM+qkcKqV2c0VBwhZNh1AuaCpOBKo907lO0=; b=drOoDhgjvFnVXBEZpJ/03O6mvbFcUBd1qWIMYHrNYMiMNLtpsb3SgquUQ5BAt88tek v0R+UPjT7SJ071wL7FgdPBFRHu+QgIA7zC3CmZN8BZl/TO23d8h7Wb+sICJnJQIJ0y7I m/1+bZJ+hHTfHonk+GDZo4j5J1pX3Q9kmZQtd1el31dIG3ICMtgyxYLv91gwJQIUarD0 aPAORrE5K21K5QO6BOSnAjrFv2EJL0i6sg/nOi6uptNsz8S3+wCOIrAisJn4DCRRs+2d Mzu6FUR3x6eZAnpwBEH402H5smA2SIpOaLpLGP82Lq2Hnti7ocu1ZnXq4zoISST13jOA siAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039097; x=1711643897; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XaC6gpRUGM+qkcKqV2c0VBwhZNh1AuaCpOBKo907lO0=; b=ue79KjFQ4LzAdUswQQj/WA/LB7sgOJ2b2p8gch07mD1zEeLMtMan9md3FGjyYSqIFg jOr+OdE7HOnafQmVdK9mUG1RaSZqMthDk4AbEr5o7BmJQTFBKG8WaNBPTgIX/CF+n/6t /3331kqezDwRe29rI/5Xn4AYDfH3VvT0la5KCaIidc+w/UDoh0lbAt8jOu7VFn/C92Xq RXrgewH7bZf6vM4icroM9JVamXZ0ktEwqmhfVo+LmlezvNe578ampty3nlFYM++rVRX5 tfzR60cN5AAOMxmYGDViFDDcrPc7H56EtK944vbLgugeYp3KaV1jlPwamUynLdkXjMPT dpsQ== X-Forwarded-Encrypted: i=1; AJvYcCVC9jwnFygT3JaeNg4tjta8rKUyBxeC5NBESTRar+l/fkusXw7z/7mIIJUGXUFRqOaOo7QUVb/80g6Hn/q+KF+DYeb15z4RiILT3H6h X-Gm-Message-State: AOJu0Yx5vmspfWCw2nFLBBUV5N41aktpc0zeOVyrk62hdJuOHr6RqCBF ZhaNx1bSAn3gnuAYbDkMHbEez8HD8UmloA1z6PK+nCA+CtdAcp8WrHufbyQAOmokoAhVQIN2oDt OQg== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a05:6902:1502:b0:dc6:e823:9edb with SMTP id q2-20020a056902150200b00dc6e8239edbmr1143317ybu.12.1711039097346; Thu, 21 Mar 2024 09:38:17 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:53 -0700 In-Reply-To: <20240321163705.3067592-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321163705.3067592-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240321163705.3067592-32-surenb@google.com> Subject: [PATCH v6 31/37] rhashtable: Plumb through alloc tag From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" From: Kent Overstreet This gives better memory allocation profiling results; rhashtable allocations will be accounted to the code that initialized the rhashtable. Signed-off-by: Kent Overstreet Signed-off-by: Suren Baghdasaryan --- include/linux/alloc_tag.h | 3 +++ include/linux/rhashtable-types.h | 11 +++++++++-- lib/rhashtable.c | 28 +++++++++++++++++----------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index bc9b1b99a55b..cf69e037f645 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -141,6 +141,8 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) ref->ct = NULL; } +#define alloc_tag_record(p) ((p) = current->alloc_tag) + #else /* CONFIG_MEM_ALLOC_PROFILING */ #define DEFINE_ALLOC_TAG(_alloc_tag) @@ -148,6 +150,7 @@ static inline bool mem_alloc_profiling_enabled(void) { return false; } static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes) {} static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} +#define alloc_tag_record(p) do {} while (0) #endif /* CONFIG_MEM_ALLOC_PROFILING */ diff --git a/include/linux/rhashtable-types.h b/include/linux/rhashtable-types.h index b6f3797277ff..015c8298bebc 100644 --- a/include/linux/rhashtable-types.h +++ b/include/linux/rhashtable-types.h @@ -9,6 +9,7 @@ #ifndef _LINUX_RHASHTABLE_TYPES_H #define _LINUX_RHASHTABLE_TYPES_H +#include #include #include #include @@ -88,6 +89,9 @@ struct rhashtable { struct mutex mutex; spinlock_t lock; atomic_t nelems; +#ifdef CONFIG_MEM_ALLOC_PROFILING + struct alloc_tag *alloc_tag; +#endif }; /** @@ -127,9 +131,12 @@ struct rhashtable_iter { bool end_of_table; }; -int rhashtable_init(struct rhashtable *ht, +int rhashtable_init_noprof(struct rhashtable *ht, const struct rhashtable_params *params); -int rhltable_init(struct rhltable *hlt, +#define rhashtable_init(...) alloc_hooks(rhashtable_init_noprof(__VA_ARGS__)) + +int rhltable_init_noprof(struct rhltable *hlt, const struct rhashtable_params *params); +#define rhltable_init(...) alloc_hooks(rhltable_init_noprof(__VA_ARGS__)) #endif /* _LINUX_RHASHTABLE_TYPES_H */ diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 6ae2ba8e06a2..35d841cf2b43 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -130,7 +130,8 @@ static union nested_table *nested_table_alloc(struct rhashtable *ht, if (ntbl) return ntbl; - ntbl = kzalloc(PAGE_SIZE, GFP_ATOMIC); + ntbl = alloc_hooks_tag(ht->alloc_tag, + kmalloc_noprof(PAGE_SIZE, GFP_ATOMIC|__GFP_ZERO)); if (ntbl && leaf) { for (i = 0; i < PAGE_SIZE / sizeof(ntbl[0]); i++) @@ -157,7 +158,8 @@ static struct bucket_table *nested_bucket_table_alloc(struct rhashtable *ht, size = sizeof(*tbl) + sizeof(tbl->buckets[0]); - tbl = kzalloc(size, gfp); + tbl = alloc_hooks_tag(ht->alloc_tag, + kmalloc_noprof(size, gfp|__GFP_ZERO)); if (!tbl) return NULL; @@ -181,7 +183,9 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, int i; static struct lock_class_key __key; - tbl = kvzalloc(struct_size(tbl, buckets, nbuckets), gfp); + tbl = alloc_hooks_tag(ht->alloc_tag, + kvmalloc_node_noprof(struct_size(tbl, buckets, nbuckets), + gfp|__GFP_ZERO, NUMA_NO_NODE)); size = nbuckets; @@ -975,7 +979,7 @@ static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed) } /** - * rhashtable_init - initialize a new hash table + * rhashtable_init_noprof - initialize a new hash table * @ht: hash table to be initialized * @params: configuration parameters * @@ -1016,7 +1020,7 @@ static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed) * .obj_hashfn = my_hash_fn, * }; */ -int rhashtable_init(struct rhashtable *ht, +int rhashtable_init_noprof(struct rhashtable *ht, const struct rhashtable_params *params) { struct bucket_table *tbl; @@ -1031,6 +1035,8 @@ int rhashtable_init(struct rhashtable *ht, spin_lock_init(&ht->lock); memcpy(&ht->p, params, sizeof(*params)); + alloc_tag_record(ht->alloc_tag); + if (params->min_size) ht->p.min_size = roundup_pow_of_two(params->min_size); @@ -1076,26 +1082,26 @@ int rhashtable_init(struct rhashtable *ht, return 0; } -EXPORT_SYMBOL_GPL(rhashtable_init); +EXPORT_SYMBOL_GPL(rhashtable_init_noprof); /** - * rhltable_init - initialize a new hash list table + * rhltable_init_noprof - initialize a new hash list table * @hlt: hash list table to be initialized * @params: configuration parameters * * Initializes a new hash list table. * - * See documentation for rhashtable_init. + * See documentation for rhashtable_init_noprof. */ -int rhltable_init(struct rhltable *hlt, const struct rhashtable_params *params) +int rhltable_init_noprof(struct rhltable *hlt, const struct rhashtable_params *params) { int err; - err = rhashtable_init(&hlt->ht, params); + err = rhashtable_init_noprof(&hlt->ht, params); hlt->ht.rhlist = true; return err; } -EXPORT_SYMBOL_GPL(rhltable_init); +EXPORT_SYMBOL_GPL(rhltable_init_noprof); static void rhashtable_free_one(struct rhashtable *ht, struct rhash_head *obj, void (*free_fn)(void *ptr, void *arg), -- 2.44.0.291.gc1ea87d7ee-goog