From patchwork Thu Jul 4 13:59:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13723784 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 06BC9C3271E for ; Thu, 4 Jul 2024 13:59:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A32C6B008A; Thu, 4 Jul 2024 09:59:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 82AE86B008C; Thu, 4 Jul 2024 09:59:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F2A16B0092; Thu, 4 Jul 2024 09:59:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4EBCC6B008A for ; Thu, 4 Jul 2024 09:59:47 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BEC6F1212AE for ; Thu, 4 Jul 2024 13:59:46 +0000 (UTC) X-FDA: 82302228372.15.992AA74 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 0A06B80024 for ; Thu, 4 Jul 2024 13:59:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EeI01k+R; spf=pass (imf02.hostedemail.com: domain of 3z6qGZgYKCHoqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3z6qGZgYKCHoqspclZemmejc.amkjglsv-kkitYai.mpe@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=1720101573; 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: references:dkim-signature; bh=LAtQdKc3DWjogtnJ0IRwxqFJsxK6c7FwoZ+WvIyW3Xo=; b=rqQPo4FK2WasJRua7eqOs/3zA8tChFxYtcVo1GWHnckIbL9gdUe2EpDlDoFZXblY8bqPjp LnPS8oPsBd9cKb/yOaBr3Hc+jSWUdAw2lm5jsfKJsU6Wz7v1J/Zqp23IjjJxflG8TIEOGY GTuzJXvJROU4CdBnBmdp4I9YyDqRnx0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EeI01k+R; spf=pass (imf02.hostedemail.com: domain of 3z6qGZgYKCHoqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3z6qGZgYKCHoqspclZemmejc.amkjglsv-kkitYai.mpe@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720101573; a=rsa-sha256; cv=none; b=0/aQHRq/CP+pIQpFmqgLkID3p3jmRhCBPFZqdz77CS/qom45gdZ183ey4b+xuTPl1NaKZ0 pjLDS77KDZkgII+wuOqgxWz6aumgZ28zOxovUvXqopqRcBbAHBddGhNVJz4NY+GXKL4ZMO jbYBbEQa+nIU2WBdXgiaLH5hvkCjXKY= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64f4b849b7cso11599277b3.2 for ; Thu, 04 Jul 2024 06:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720101584; x=1720706384; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=LAtQdKc3DWjogtnJ0IRwxqFJsxK6c7FwoZ+WvIyW3Xo=; b=EeI01k+RFy+LjqQhHAphgHXtsc30U8gPbomzEzmKtpxhgItKqGtvD9fcYo/YHtBatB wmBK20p98RYj2rA9ClQ3Ll1I7zFx5DARaqf0Bjem0rgYxsg2VyGf58sEKF5+kSM7C9Kn eA/dCZnRGgvjA+eCftNrxX2qxRCdT3VeY/2laeeCuKFcPN3C7+SJuiU/7eqAZox9GXgA Djn8CiHCBzecZdjFCDsB/gsTNkDiSh3MBPhlM0Ee/CTVdN0Ccy1askNDZif7leV25pOR Xfx93IcDmbpDbt0kZpVyfhkvEyycPAE6dNEu+PQutyyVj62D4I2anTUiQa2QWy0oUrJi 8Nkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720101584; x=1720706384; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LAtQdKc3DWjogtnJ0IRwxqFJsxK6c7FwoZ+WvIyW3Xo=; b=KL8cFIBcZyLXFBCftttTvubWsf5d2N15gjZXFa32g8XSFB7Vm9wWZWxbN51kujeMh7 y5Xs0OzPvaurT9ceiGa6rHhQg7C6cxvpRd0cxoRV0542Zf6UiiV842XHahi+6d+Jtuv0 vQi78KwGxjdXtq4A2YV8gLRXIB032jy/2+mvPZ03N2hdBLGfJaJAbdiv4itlfUpq8dwS G2JkckuYp6LVvd4fuQVpcp/2uZhA/T04U+BXcNjedA88+e74iBWoVR6uRBsjj/rCLebI tnoL8BOqElRsk2AnyGSfbM5BPm73gxuyycQry97s/iUItapCrWSD/d7m/cKy7cfdB+gA crZA== X-Forwarded-Encrypted: i=1; AJvYcCXecuShsPJv8k4E7IEu+uFYIvRrxNAAWi8wfzAHJO71rkfFk5pqsOX4tL3DbxUoJ6MQdCaGNbrG99qBROjZAvFemL8= X-Gm-Message-State: AOJu0YztX8Ok7A2Re6+L9iMjyUtJG7S+OHozyfGkpn1k8HV/ZTX/0i4O OhjG0fs18M2a/6nNPYfYCRAK1/h2SGwik6npANvCes1GJP0YDwMf+0t9CC6KHykmq0wWiWKWLLs wGg== X-Google-Smtp-Source: AGHT+IHKp+9v7/1jkX7RG5nnKgjFqzydqFYM1oxQOc7v96Ao5/MWhucQyLSdycDsJ6Fj0xxeXCWOwAFBRvc= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:f773:f667:425:1c44]) (user=surenb job=sendgmr) by 2002:a81:84ca:0:b0:64a:bd29:c5cf with SMTP id 00721157ae682-652d572cf58mr79517b3.1.1720101583822; Thu, 04 Jul 2024 06:59:43 -0700 (PDT) Date: Thu, 4 Jul 2024 06:59:41 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240704135941.1145038-1-surenb@google.com> Subject: [PATCH v2 1/1] mm, slab: move allocation tagging code in the alloc path into a hook From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: vbabka@suse.cz, kent.overstreet@linux.dev, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0A06B80024 X-Stat-Signature: a75pe5gp1s9arak16s58z6rcoqhmkzxi X-HE-Tag: 1720101584-320485 X-HE-Meta: U2FsdGVkX1+DFkJEamMTIPeihyb6/rpxU9splIma8Isx/iLQbv4dssFttL0TdMm3/xwaxlP7NUsgocCJRE2US53fVBB0LilsVTaFs05tArGDgQ0eR2b1Hb48PgBd9dgwJv6BCxccsO/afEDaLmU9OX3qguCHbKW5IfagwfYe5kfxKT2UTw2YC7ubJlpnj94PEK6OARiWVmxAOTFaMuABA5986OBO5gWGrZbp2Eo07LSzrVT01u8hsBibZDNO9tP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+iuz8SJe+bOVbbGKkR7ypoooK7No9tLhDQ6PyjnpYyGqyllA/CMgfJrrx+rIRsRJXrX29+/4ozboEIxBIx+TmKewf0O3zyoXAjpvOr3zgyLeMjYx4mjbKxBEOXfVlAJgJ3DAlEqmH1K4y6gm5tQDOqozjqoVcAYlVaiPbrCbK374vqMDVnQQTC/xJeluXgSbq6zxYBUqPqkL5m77TeSPFcOfYkZjOXL/XKZh+51GtxAbizZOlO4NY7c= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000706, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move allocation tagging specific code in the allocation path into alloc_tagging_slab_alloc_hook, similar to how freeing path uses alloc_tagging_slab_free_hook. No functional changes, just code cleanup. Suggested-by: Vlastimil Babka Signed-off-by: Suren Baghdasaryan --- Changes since v1 [1] - Moved entire profiling code portion from the slab_post_alloc_hook into alloc_tagging_slab_alloc_hook, per Vlastimil Babka - Moved alloc_tagging_slab_free_hook out of CONFIG_SLAB_OBJ_EXT section and into CONFIG_MEM_ALLOC_PROFILING one, per Vlastimil Babka [1] https://lore.kernel.org/all/20240703015354.3370503-1-surenb@google.com/ mm/slub.c | 86 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 36 deletions(-) base-commit: 795c58e4c7fc6163d8fb9f2baa86cfe898fa4b19 diff --git a/mm/slub.c b/mm/slub.c index 4927edec6a8c..98c47ad7ceba 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2033,11 +2033,54 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) return slab_obj_exts(slab) + obj_to_index(s, slab, p); } +#else /* CONFIG_SLAB_OBJ_EXT */ + +static int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, + gfp_t gfp, bool new_slab) +{ + return 0; +} + +static inline void free_slab_obj_exts(struct slab *slab) +{ +} + +static inline bool need_slab_obj_ext(void) +{ + return false; +} + +static inline struct slabobj_ext * +prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) +{ + return NULL; +} + +#endif /* CONFIG_SLAB_OBJ_EXT */ + +#ifdef CONFIG_MEM_ALLOC_PROFILING + +static inline void +alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags) +{ + if (need_slab_obj_ext()) { + struct slabobj_ext *obj_exts; + + obj_exts = prepare_slab_obj_exts_hook(s, flags, object); + /* + * Currently obj_exts is used only for allocation profiling. + * If other users appear then mem_alloc_profiling_enabled() + * check should be added before alloc_tag_add(). + */ + if (likely(obj_exts)) + alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size); + } +} + static inline void alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p, int objects) { -#ifdef CONFIG_MEM_ALLOC_PROFILING struct slabobj_ext *obj_exts; int i; @@ -2053,30 +2096,13 @@ alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p, alloc_tag_sub(&obj_exts[off].ref, s->size); } -#endif -} - -#else /* CONFIG_SLAB_OBJ_EXT */ - -static int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, - gfp_t gfp, bool new_slab) -{ - return 0; -} - -static inline void free_slab_obj_exts(struct slab *slab) -{ } -static inline bool need_slab_obj_ext(void) -{ - return false; -} +#else /* CONFIG_MEM_ALLOC_PROFILING */ -static inline struct slabobj_ext * -prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) +static inline void +alloc_tagging_slab_alloc_hook(struct kmem_cache *s, void *object, gfp_t flags) { - return NULL; } static inline void @@ -2085,7 +2111,8 @@ alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p, { } -#endif /* CONFIG_SLAB_OBJ_EXT */ +#endif /* CONFIG_MEM_ALLOC_PROFILING */ + #ifdef CONFIG_MEMCG_KMEM @@ -3944,20 +3971,7 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru, kmemleak_alloc_recursive(p[i], s->object_size, 1, s->flags, init_flags); kmsan_slab_alloc(s, p[i], init_flags); -#ifdef CONFIG_MEM_ALLOC_PROFILING - if (need_slab_obj_ext()) { - struct slabobj_ext *obj_exts; - - obj_exts = prepare_slab_obj_exts_hook(s, flags, p[i]); - /* - * Currently obj_exts is used only for allocation profiling. - * If other users appear then mem_alloc_profiling_enabled() - * check should be added before alloc_tag_add(). - */ - if (likely(obj_exts)) - alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size); - } -#endif + alloc_tagging_slab_alloc_hook(s, p[i], flags); } return memcg_slab_post_alloc_hook(s, lru, flags, size, p);