From patchwork Wed Feb 21 19:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13566210 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 BEF84C5478B for ; Wed, 21 Feb 2024 19:42:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2FD76B00BF; Wed, 21 Feb 2024 14:42:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE0EA6B00C1; Wed, 21 Feb 2024 14:42:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABEAE6B00C2; Wed, 21 Feb 2024 14:42:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 911B46B00BF for ; Wed, 21 Feb 2024 14:42:05 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 74A78A0BA7 for ; Wed, 21 Feb 2024 19:42:05 +0000 (UTC) X-FDA: 81816831810.23.D388B0C Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf02.hostedemail.com (Postfix) with ESMTP id BCC0580020 for ; Wed, 21 Feb 2024 19:42:03 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=o6bfTOA+; spf=pass (imf02.hostedemail.com: domain of 3ClLWZQYKCD0rtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ClLWZQYKCD0rtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708544523; a=rsa-sha256; cv=none; b=TmNV6AGsfzfS05LIKwFmFw+0UL2tlAG3HDmaOroC+xGGSphXzDKv2Yxm1zEDLrd9WFz5lG JWV277CyNNG0dWdvvUzSKv1jqhamxhf2JVPq952t8sWL+YbCnmOotCTJg6ThlCZIYN1R2Z WqFk6c7gP2cDc/uC51DIasZULANcPbI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=o6bfTOA+; spf=pass (imf02.hostedemail.com: domain of 3ClLWZQYKCD0rtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ClLWZQYKCD0rtqdmafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708544523; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4ca2CRMzgUqo30S53DRYHeCmPf8DAT9MnFsYZ/BDy7I=; b=z/5kTLtFG0Awb1kNLZIaXWx2xk2ywuJEEqgwkCHAea+CjLY+IUkJlr5siZ2pBio6IBTz7Y JKC74jOK9+Drqfw7ura7buWj4L2knbPPfuCMEMiATRux71kTjwl9avQp6BgJxDxG5YwOZr HyowkzLUtHF3sWHou3qXT/3zFLBC7SI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60770007e52so82279587b3.1 for ; Wed, 21 Feb 2024 11:42:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708544523; x=1709149323; darn=kvack.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=4ca2CRMzgUqo30S53DRYHeCmPf8DAT9MnFsYZ/BDy7I=; b=o6bfTOA+AwRb+B3M97lcMw18noBRECxdvL/PK0jAlkpKrG2LYW1iluc/sHd/UYIO6O qWWdYcxiXOrQap3chEXJIO+/0svAaIBsfBuLQfjr2dzS0otGCY3zz/N01wUBTFCiiXqr OyyHQUba38AtSjqPNBUz8kiVV5d3NLce2b+HbN+wnmjZJsGUL9Msrrva25nkQ24coXLY 7wbsqTy9EjsqwDtB6cx6KoZi5TKExx6BlD757oTAe2IAdPLkNQ84MkA+AI48/2wueVd/ 16TC2T951nfAezeMPLL3tb859pbE5HquKOVGDUd/Q0nfsIDUDRFumpTD8NLEPRmGHqVS HArg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708544523; x=1709149323; 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=4ca2CRMzgUqo30S53DRYHeCmPf8DAT9MnFsYZ/BDy7I=; b=OhGYoEXGztENTD/18jMlc9eqTy0Uzt5vzg6myhV0VSEvNCmw4bMOhkqqGzCDsLFitJ rdYfKy43yw/cs8RSPziuOidP5oMm2Jphw4SA5S8ZM5J8bTGUwxj3UxSmk3W6PXFhjICw FOr6Tnkk2TzKaA+L7/BdziLmNgAEnOprIkIBrpbcgPH66bIqqinC+k6thsaDuu20SrTz KM1rmrmivB9JSDBOYfyxrtOE6vm8UhHeSG6fcDKT/hK/d6ujtIKQLhdTFz3lhS+7yUTL +d7fJdOYWRM7szETDahZX6FbvOO/4C8dGiDt6UjIb4pvatkQELOVScO1N1NMyeQNNSSi hIog== X-Forwarded-Encrypted: i=1; AJvYcCVLeCY7TKhFHtbxUYzr0chD0CiXFk00or0WkBhgtnfdHQEF4VsjgDVP2PHCrKwo5UbbF59eNipbGZN7S5NPqFLM7VA= X-Gm-Message-State: AOJu0YxfGzv7ZRuyXI3b/cUR81iGOLy6q2RoeXI7iInDT8+C7KAfCccl OQGBwGl7Mmb7iDMIL0Y+No5y6PKiO48L1B3EsH75np+HXpbB3uuro+jplmDkk6iy+iK9OxweV4V huw== X-Google-Smtp-Source: AGHT+IFffFYSdKTwRIoTuKanuxnAO1YVHDWWhEPlchVKFceg9jZBcLvA/YiXfOHsmmNJVcGKnn75V3mm8JM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:953b:9a4e:1e10:3f07]) (user=surenb job=sendgmr) by 2002:a81:fe07:0:b0:608:22c7:1269 with SMTP id j7-20020a81fe07000000b0060822c71269mr2041757ywn.0.1708544522852; Wed, 21 Feb 2024 11:42:02 -0800 (PST) Date: Wed, 21 Feb 2024 11:40:43 -0800 In-Reply-To: <20240221194052.927623-1-surenb@google.com> Mime-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221194052.927623-31-surenb@google.com> Subject: [PATCH v4 30/36] 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, 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, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.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 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BCC0580020 X-Stat-Signature: u7yp953y8j59nf8q1n5x39ho59nqmfbe X-Rspam-User: X-HE-Tag: 1708544523-579411 X-HE-Meta: U2FsdGVkX1+EVrP3LzIKnl0Y6T6Jmxq3lMsYfG2zPLHocVRo8qGzs4uEz34coepZHs7XoQsiQoaoyWs0PkEyYAAphKnKj8UgK22FU1sUh9R9o/ZdW34/qlQz0MthAWCPQdRLaXn9riyD5geaq4DvgdjxNGg3CeMLHcdbPeFYacdaVji+zKmK0+w1gMAa3gCTeh1lKBlX+i/WcXXG7nVBNgUttNbnsW9+vClbdl12bdOmlhtaGZQHDZNe4Kvr/pT+RhivF5l5GbFZi5askIsKUUHM6LoScPDkN89QMeaJZ6NJowB/DI0AL6zxyPsZaUicP04Pi4/AIXKKCbb6pm5w1FcfZWdyuQe+3r4dAFY/29V2Ev5639nEzc52zn4xn+vjKrwipYq64wSLSbzw1VmYpr9iG223qA1WxOgqDM7HJdx8eXNs4IH3B3A78Cv8z2Bv7GKp8M/S72up7j1Bak1zEILOvxNsuOiMT9Gei8dwnLyyIwq4ex/DK5MPp2WsF7yOdm8QfDaojRJSpOpT9TWBY9PO4KTLJkd6qqGR4Rad0WmQEcrs7DIVc26i7jH4AGIWMew1htWJSIhR60jCRVwfvtTERmmr0PXzAlJYwKBFjTT6sG5eVwbQxdknBK6iGDF246OlncN3cBl2AM4UG7na8gCOpGRIMunMb7wlazoqCXpVWNx1n1MOpBma4udbZSrT8V/fyC4ENQJ7X3yyQvzJTx5Iuuzi2gIBSBw2WucqJZ4I4tu+0e0OTzSILkcfaZB2tgXCzM2BBmnYOCyEfBCZAaPd5vuSUMczEkS4wzAHXmBIy3kwdFAdTCx/jAvzO1UvnFsmL2es1koYmGVnNgjekctyO9NqiX15F+rxwtVfgrzwQbXSAb28BV3B1qpErIWyT0G/MuteGGRp6xPr9B8CVKohZryugqOix6vibS9Cykj4vJdVA0Cg2GL7xRC+GLO0SUHCofdO83v7/ooA/Jd Msge1fn1 OXo6FqL84PEYuN5Wc0yNUgIGTM4glEGFV3FfBDz9NgY3J1uhcUrkfqPdgaacc7OB8z2vOTyrvBsgJfm3XuMITs+KYogjKVGkxjN5Zb+eCSt5dzo1BTyYNxJ5PoU+Xy5BEwXG499OjZjw8BztYrxRii84jKLrLeuOt6cZqwyeG+mO8YMexcLUA0FnHnBXo58Ai3WP7N/Eefxhy6BBaNLsnqdvOAx9de7+YTcsYaKdqxdUC53HkwhhlGt9eycG/wOEUQ+42y1zrjzjtk/VPfElCW8PEejLPeg3hztGtZhn9AETvNSN3T1+tiQHiVkVZZO6jiNgRphainlXw/kY85AOdn4hoPTNpVANGSyMFEgLUA6qMj+zYirDLojz7CrVYq72hqaApvyyU02lDEKJYyDZyGZF5KXqQ7bQkGOqS 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: 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 86ed5d24a030..29636719b276 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -130,6 +130,8 @@ static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, this_cpu_add(tag->counters->bytes, bytes); } +#define alloc_tag_record(p) ((p) = current->alloc_tag) + #else /* CONFIG_MEM_ALLOC_PROFILING */ #define DEFINE_ALLOC_TAG(_alloc_tag) @@ -138,6 +140,7 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, 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),