Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp81674lqi; Wed, 6 Mar 2024 10:35:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+r5YtWWQ8Zr+47A70O+4dxfuyYxE7eWnaK4/QSnDgJGRHVvwspa06TtRxB8e1ws1d2WxXgUA16jc5pZ4bGO7x4sLncW4Bm3uZnLul2Q== X-Google-Smtp-Source: AGHT+IFV9ivsvnk3/Zy4yVI0TM1sPsXaFzx3ucnI4o6dwxkFw5eE0vTBS/uZ6ogrx0chnNUkL/3G X-Received: by 2002:a05:6358:885:b0:17b:583c:c4b7 with SMTP id m5-20020a056358088500b0017b583cc4b7mr6345503rwj.3.1709750106853; Wed, 06 Mar 2024 10:35:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709750106; cv=pass; d=google.com; s=arc-20160816; b=XenL4TMIXHA5nVjvL9yV1/tZrWnXcvvv4Mj71E5IwhHh8QF6gVdN8vVn6vGIpiDNGl x6LLA/hn9v05562ZRjqong3fU8CxhfFA8lljNQ66bH82zPT9nhFpp92KqI1Xy9EjvvyP yX07rVzFjqw67HsjNGA5fe7jd7TjUrg7ruZPri51SVvdmjjccmhZi1kq2Tnniik9HiHJ YtZdrjDRwIwr19lOOU2FZZwjTK1DXVaZQcaLZCDvsayTlGMoklI7tu9znObWniO7IOyu KLvGVNiNFZ3xfckEWYGkgNQAQHcRX1bqi7OobztFhMY2BZA8H6L1I4SZekQn5WGNe05I pHzA== 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=Fu+QokTCwH9vHgRIOuSmN9iHLTBbRC7AqqeSJz2bhTE=; fh=bbB8BizNE+dJlZVPCstmPMGYiGrm9rvdUZPtfR9jwvM=; b=LPoLpownvOJ/lWBUxs8MBeFZY3f/gC2NjVOZKpGUmL5oGD85WL2bJ93OrmzzwLxCdc clOoA+2oU6WZYjTT2lWlhmGw+5KeiHXDjGPnptNZpaUlZTk/xdJGZL1OZ86T/jx15r0E 3EsGyJB4IGRniO4KJPQqw3TiKfXdEjF/jCf+nfO0i7KgTw/UfqVBOrLeo6wq5me+gShs DnPJDTbfuKdhwpNWJYMZewaVN7SS5zigrY30/w6QQWKXKCDPJ8V9aTd7iSJxewrXx1Fv M6nV0fD9oRIOl1KYpoCk3rKI+yr0l2n/naY4MQru99KtttiSAqg3IjK3EierM+UQPg03 /5WQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Krg355b8; 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-94423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94423-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kl13-20020a056214518d00b006903065874csi14900879qvb.199.2024.03.06.10.35.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 10:35:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Krg355b8; 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-94423-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94423-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 7EB461C216CA for ; Wed, 6 Mar 2024 18:35:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D67931504C5; Wed, 6 Mar 2024 18:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Krg355b8" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 8BF9C1504C6 for ; Wed, 6 Mar 2024 18:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749555; cv=none; b=d8riQ3lPdrBKgRtaVfqQijZl2wJAnkk+7jBtX0/ZHdvq/8eRy/yTAlBpY3u0AaXbJSOYWWd9tY/6w+QWvlNGt29xgY0t46wkYz9y1gJanFIPfXJ1IBwOFkz0Q0tRhP+0H3YV1uDhv6QzttPaR/UoFxZT1Y6vMeqKKIusGD03Lrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749555; c=relaxed/simple; bh=5Ps9bn/WL7D2YUoIFkvXSXhqbgCAzIZXzki4BvwSQyw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Fgrbf9t/H8N/eskm53ar6fNiOmXOnjqgeS7ToiU7lykW+ivcwkA4PI2GuZb2Dc9GLNc6a52kUlDajkfmXnuodBb64kPumEjqA/6ANsowz+SWLr28CMDE42uzjX9NeKx/cRFY64M8hy5yPGv5RIiHkkOeco1Tu+3bq7Iy8MkDSn8= 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=Krg355b8; arc=none smtp.client-ip=209.85.128.202 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-yw1-f202.google.com with SMTP id 00721157ae682-609d8275c70so95687b3.3 for ; Wed, 06 Mar 2024 10:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709749552; x=1710354352; 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=Fu+QokTCwH9vHgRIOuSmN9iHLTBbRC7AqqeSJz2bhTE=; b=Krg355b8KgD6id5JcTsV3wqDAUXGr4DVd5frbbmhV7PnOi+t23+aFd2asfUMcZMKzs mFXFwGf/0GkQ3nx5hGu0NuN7QYOqiavZz27TajMbsGjEDJ0aNHFxsurwWahCQ2MdzJky wfBjId8xi9ynzU+9jkSwr9u/U+EMRUKak8Mb0dzA2tphc9KThLquy3jMjFx5VzyX0zW1 Ud8Eg5QOROZxAsEDCt1xmUu/RQHK//TYbw9SmusP0IcKiGpzwojPBdOyWEzEvduTvGcB ejOKPrq4q7WKaCO81CIGyBcIQTxGjusWU+AVQWlEKIWs6u1P1RMykU5FlCjX3jvIFFHy cHXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709749552; x=1710354352; 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=Fu+QokTCwH9vHgRIOuSmN9iHLTBbRC7AqqeSJz2bhTE=; b=DmFIXe3S6f5hb3O4t6b6ef5iENmBdbkSyzuzvVGOBqB80LYtpsxkhcnGH1LyW+BaXg OLkOesEsY0qOjoVtUzwn25YFboyHrhuIuJhUyCq5a+eJnOTe7I3pg68OnXzN4uFTMl2M 9t9U65gEeI3sYZz05yHWKSPx4aRs9kSFrdPjDqJuuP88fauk2VDJbDbg1F9Gr4DeySHc DkvBldxT80L8OYPkAKjjYJzZ/IjsNNXe7z6vRvTlMRiAhfMTSwhl1QXqT2BChXtSmuSX rLLsizGLgLleXAhgajONq5Uy9B1UHp6BH4VzofuYxso4lqcCM7oUfTRVEcQnrSDg4tjY 0cwg== X-Forwarded-Encrypted: i=1; AJvYcCV+1fxsI28ud6HtTIkcMDWpdvP636PNoPEzLeE7tnf5/3ptyWvt3VQvCdAIl17LrSNzvIkyLDXa41IgmxCaJs2rGwlTAoe1JSLOUjba X-Gm-Message-State: AOJu0YzP/TEOp8AdEHjSv1eXwYcbR7Be4X830ZIaQj1SbQXMalKPmdfx 4aCgV7qcNZQqiOf+Nxyb5fHwCCeXKLtZE6b9dAWlwvt/IAeopk9LA4ePelcX7qOzpQB8dQy5J36 IxA== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:85f0:e3db:db05:85e2]) (user=surenb job=sendgmr) by 2002:a05:690c:c02:b0:608:66be:2f71 with SMTP id cl2-20020a05690c0c0200b0060866be2f71mr3512997ywb.9.1709749551693; Wed, 06 Mar 2024 10:25:51 -0800 (PST) Date: Wed, 6 Mar 2024 10:24:29 -0800 In-Reply-To: <20240306182440.2003814-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: <20240306182440.2003814-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306182440.2003814-32-surenb@google.com> Subject: [PATCH v5 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, shakeelb@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.278.ge034bb2e1d-goog