From patchwork Wed Mar 6 18:24:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13584441 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 E7CBCC5475B for ; Wed, 6 Mar 2024 18:26:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1665A6B00BF; Wed, 6 Mar 2024 13:25:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EB6B6B00C0; Wed, 6 Mar 2024 13:25:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0B9A6B00C1; Wed, 6 Mar 2024 13:25:54 -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 CB8646B00BF for ; Wed, 6 Mar 2024 13:25:54 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A41198034A for ; Wed, 6 Mar 2024 18:25:54 +0000 (UTC) X-FDA: 81867443028.29.412433F Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf08.hostedemail.com (Postfix) with ESMTP id A8B4E160019 for ; Wed, 6 Mar 2024 18:25:52 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="hr/ZeLQa"; spf=pass (imf08.hostedemail.com: domain of 3L7XoZQYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3L7XoZQYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@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=1709749552; 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=Fu+QokTCwH9vHgRIOuSmN9iHLTBbRC7AqqeSJz2bhTE=; b=I6Df4JcQ/bui/Ner+A5HuYysH5OkGkW6e6UJg1dSQMD3bf8Sy8UhirMwHf3w5E9Ve9ZRKi mEo/6KwkTxRnuAXI0EEpT4BRAbCipF9apEPDT/tRVCVJkQ5CLc4eknGq5n9lU4HVVNF9Mt 06gvC0avSSHbz00xQHqzR7ZcEs5Rk40= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709749552; a=rsa-sha256; cv=none; b=lkkIZ3sXvmqwUymiIdZdCHX90ZjuuOgkJZbkIcWTVs5Lg2JVJfYxNnxnppc6ysxmOAgSD2 tW3A3ZH2VGgvr/jYG8HtubtKW/5esQDfbluHoHHZazN3wHUwrCSJxPpbucYTCFJpf40rts 9bFt7xrfi1CXdNQa8J3+vR4/5zLO8yg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="hr/ZeLQa"; spf=pass (imf08.hostedemail.com: domain of 3L7XoZQYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3L7XoZQYKCHIikhUdRWeeWbU.SecbYdkn-ccalQSa.ehW@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-609dc04bff0so209447b3.2 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=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=Fu+QokTCwH9vHgRIOuSmN9iHLTBbRC7AqqeSJz2bhTE=; b=hr/ZeLQa/vSnFJKBBYMXXuDGBYJf47IIwLTkqHfrEprGm19UgmNv/JxP11kc+y/BUs VQFnV2JxgaN5upWc15abzaC+u411GaRQ9DKYOBG/nWox98PKPHTR5c7CvlKkTD3GNVjB A9QzfyD604/6mSvRk/3HKvfysCF00WARl7EC2ntzawMjeKurszrNkE4ldASlaVxhn6us 9CfEOuKiEcoa5o+Fs62vOzdi26UPU8aWXiLlgKbDEiWnlq5XUobXX2xP8HGKUa+r186r 31oWjnz0aboVDVhpC10mxsNnQcLET1BPZ9/jeIIoVFjJJSaR87/jO+eX2mOJalb1PKSg n9AQ== 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=IrDT1OvhTQz51PUz6bIHPKfWboQsU/vH+AxfqDHHIdJ1x33JMPYSy0VPukWfvbtKda 53gSwD4QK8qZTdfwsyAzLqyt+UrDtsjv011Wtda10pKE5qUvTLV6e2dghTwz13zBcGw1 0/3EXKUoGSP6Y16brf/2oMS8hc1pEnLOtXHAePWhHY7hGIcrK39DISt7SKj7agfevKr3 9UrtCqVaYQiIkBMeDIycWYQubn5g/qz8Jno2m+i8c99ukog9AwkqvTpLUaKsLjI8Sa76 nyhsRK/jLq5u2w/PvnyMl/iPv3InaGxZRzxD46t5zf33ad3zZCTQ95Pb3on8871MrrCa 0PMw== X-Forwarded-Encrypted: i=1; AJvYcCX3lCnhnG5JX/BZnmN7vh1yC0gargeOBlrjGKuX/eH9514q6v3q6Ms1J5ILERMPMrKPK8TrtwhmrBgUdVkREcrV+0w= X-Gm-Message-State: AOJu0YxJNJZ+y0ePzJFJF+FU/BhUwGFy3X3qeClgr3je9rmViTZmKTwf 17NNxVahuv8bAAhbihhOECEtBPs6pLB7pDljVdLsWC6h9x4fxePriDpTZ+LYg0vfXiWXV3E3mcV Amw== X-Google-Smtp-Source: AGHT+IH8uTiw8GF5vZKvpNdwUjiYw3f4d0sxZhsV7lTjdNn/jH/CQVsQaOx2OIyhhvAH+kWCwcf8uXZ95X4= 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> 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 X-Rspamd-Queue-Id: A8B4E160019 X-Rspam-User: X-Stat-Signature: m59gh4yufder97ssxzdzjyb96eaxtp5m X-Rspamd-Server: rspam03 X-HE-Tag: 1709749552-312831 X-HE-Meta: U2FsdGVkX1/iYCHBEif3KjEAYOTf8tqvchV1ZtLPwCRlJmUR3umScYel2kt9LNowM4ggk2mzvIvdyUhsFEPsndBwVnJ2ZYuhnuLfy4cBLL6N7G8cdCkVuOdn1Ah3KzJLndVqCoRpoQ09BpARC8UFPyt3bg2XNDVRb74C6+hRVQivIvt3EtqGFMkUD3yst1tEjLdxEld/e2jQBIOThNlZOsrccYRrJJ8QsQIEov7tiFb+03Hl5bcHtTKRnx3x9qLYpq4mn8QaMb8kxQBVtbp66uN5kT9P3bbt0GJxnNOhImIGnheXlkVYsSHsDCgqaM9cCYNEPpiyMZ6wVzN6S8YFoP+NrxhEHR3qtHgwA1iZRmGeMqqWqB9lReNnq3a5ZUyhuedz5XjTXsixdBWnaQtfZ0duSdToKuW8DxOC7xlufn0ydIUvClnMdc+WwrUbJ/tNFVv5lKAlAd1Cnivk3p5VE/JwTNRdG2jpMju09jZXSgLzZgTd9JUcCCvcLLrjkw1fTdPN6d7/rs9lBC5j2JtCJXw7kgSBScelQCIHWQpSk9rCdHLi9lE/VJBXD8B3q+MnLz7uIe6w6o4ZDGSKTz6DuyG1D7WCoTY/cYJfwmMUWfmitnOoY77y8metLKE8bQgUJNHRZARvweynfBlAEkDk0KkhvBb1GBiChOCE05grRxW3Rwg/wZVtb0Io3lHqmPcVNr63H9W5NMbkjBXo1IBLLUuTQJ4VRUtKZda1hbjpOgCmojAytRH12j30klYwqkLL7EhmmUxZVfQPJslFMyBP53swb3xsExEPJgwSC9uGXWrcGzOBNwWEHK2pwC/M0y70YreYV3dOKCiSfjQ3F0hAC2/uQWH0duUBVgZKPQ2YCIJCdgmZl0QqNj1lUEOTjOvM71u83NYXQtnFbqnPTEKBnCUwqgFLjlOY24TH5D96CAOs5C/qQiciWtc0k/cxvlPcYCetwzcqIfADr25QmZm RLZPgjwI eYda9sprX97x0T+e7FZeONxZDClbERW1oSLbkEV4ZZXOd7I4tw1+anBtZcOiSh5vLdaMq6FRDmE6rZGlPBTo2j84Yw8gL1jcvLgVVg1KEjfblV36/FdNezVDRLsg+C2ArZEbsjIZWwesr2ZPib9EZa22Vkf5slYzhmuHqool+UgRwDzl2of6HCBsMlbNBU8K4SpCkdlTEhswd5fOSAuZOmUsCuIBVZyXzL0RpgTz+W0Yrm4ZOY0uEcotGQHyTPpy9w4luVhq3a+/TUIWabamhK3caGXFznL5IzJb4YeEObuN7CSAFS9eWIM0U/ZOPIbPdE0ak6ul4tDh463O93YcqTAGxZR7RxI3aRG+7rkWbSEijwl37BDB3e0kTwa3Xbl7mBFGYj4ToypJ3Fo4MGmp6lE7L4OUzWtKzwPZw 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 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),