From patchwork Mon Feb 12 21:39:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554059 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 9A4FDC4829F for ; Mon, 12 Feb 2024 21:40:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 888F76B00A6; Mon, 12 Feb 2024 16:40:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 837C66B00A7; Mon, 12 Feb 2024 16:40:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63DC56B00A8; Mon, 12 Feb 2024 16:40:21 -0500 (EST) 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 4F1A06B00A6 for ; Mon, 12 Feb 2024 16:40:21 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 26B02801A5 for ; Mon, 12 Feb 2024 21:40:21 +0000 (UTC) X-FDA: 81784470642.26.FC990E8 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 7E67C100015 for ; Mon, 12 Feb 2024 21:40:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3CAOj0gW; spf=pass (imf05.hostedemail.com: domain of 3QpDKZQYKCMEz1yluinvvnsl.jvtspu14-ttr2hjr.vyn@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3QpDKZQYKCMEz1yluinvvnsl.jvtspu14-ttr2hjr.vyn@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707774019; a=rsa-sha256; cv=none; b=3S7/9ypd6NNvZI6OzYpA3O/kwWCoz4Uin4wlSsYSL8hYPVOwUmDU0jK4vILAdUlXXksjig enuki9++Bbsw6j7lTsS+AvQH7b+fAMgnj7CEoSy2FvL4Zh3CSeVn7ujhT1jLfGbLfHj8t5 Xz5/wLzboZYbKEFS49aJqbboHUYfYr4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3CAOj0gW; spf=pass (imf05.hostedemail.com: domain of 3QpDKZQYKCMEz1yluinvvnsl.jvtspu14-ttr2hjr.vyn@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3QpDKZQYKCMEz1yluinvvnsl.jvtspu14-ttr2hjr.vyn@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=1707774019; 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=TxFmyXLHYuBt1ZmWD3OCbH5m3f76lMQsgX1qwMm0SnA=; b=G0dVDr9dWJeTSN7x9LyZLW/+hvr5Uy1QgTcu6Tk2nCcJqQB4RWgaPrd3D6aH0gHvPswtbY 3WjGTi5JDotdbMBlcnltiL4GMofYROADOM0uLQxaGxtQf+krkttAGgDwdvYCmNwC3d5tPB /oCoXICbT62Grb19yaWNBbmFWMwuZFE= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso5926812276.3 for ; Mon, 12 Feb 2024 13:40:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707774018; x=1708378818; 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=TxFmyXLHYuBt1ZmWD3OCbH5m3f76lMQsgX1qwMm0SnA=; b=3CAOj0gWQGwlngYqSHt9wEjWheIzhWc7wbxoL5dKO411iHdvPOEK4Q6Xh02fK9nwV+ xF4c6fmbVHOSlQjTUWQ5/umFN9RtTZdTNkA0jarKalEyTLZrSGFS90Q1hOiI9Z2BxJN4 ave1MUz96YyR+iRo3N/1rKWe83QNuixNKo1P2fHEocUCGpO6z9OTEEFFenvg5KDrI500 BJ82wzOIYqdMRf0GAyYAl/jc/DkM5ODvw9lBPICAGNqK5anwfM53jvsO9uEZbVbkINPp Hn5LEctSMn4jiPPDFZ38H/eDUmEtzJJr0cQ/1Vw9PrcZvk+KW7fR/Kh6ZMp5IlygZXQn k/1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774018; x=1708378818; 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=TxFmyXLHYuBt1ZmWD3OCbH5m3f76lMQsgX1qwMm0SnA=; b=BcnXG0YFmwZoWNWMmOvu2uU/pt4I7hlTwHFXsHxxwzU+xdOq91J/k7bGGJfT36XC7i VmnJ3HKM0a2KwuBmht6f7+RiM0jO4oNczIv/2BR4AOMxh57GhKXArQH3X0PtcP24yRjQ 1Xgu6OqmDFBtUblSVnm5/u5C5lCx4ms5qdTgt42aSb6GP7A8ticrf6joLitJ3HBEVB0a FCgk3G2BBv1jiuDMwIfYt57P0SZpBfV8HALYmy2csElxKu/vPdWyZUYGltoC7OOaEiBU UMlhFPcIpfjtEv4K+1am6vVA+eImDuuy8ldj197udcHUqYo5aQZWh8ndUVV8cNHTCfnm rk6Q== X-Forwarded-Encrypted: i=1; AJvYcCXU+5Y3Z9Q8LD/v44BQj84d//ojujKMUC6YzfpJKw7b5cVhRqkJf31cdNqWLO/N/0XBYr4uwpIz53TVJNdBctRmkI0= X-Gm-Message-State: AOJu0YzZ/3WN6JOnWGUVRpOkJtPlHb1mBHD0HX97iju6So3UlkxAEnk5 DNuC4SQPD7ccY72mbLPihHgaJ3aHW//JIlSBqjL10+zEotnLdZeXnoOxJUNdN4+Mu/hLvxSFljA 7Pg== X-Google-Smtp-Source: AGHT+IGBONdcVlXEEGFa18cuaG6bv+Dg1NI+YmaYVRfFeBb82PPmmVaHOveRp5zx3fRCNj/22b8sYtrJmjo= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a05:6902:2291:b0:dcc:5a91:aee9 with SMTP id dn17-20020a056902229100b00dcc5a91aee9mr85473ybb.7.1707774018612; Mon, 12 Feb 2024 13:40:18 -0800 (PST) Date: Mon, 12 Feb 2024 13:39:07 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-22-surenb@google.com> Subject: [PATCH v3 21/35] mm/slab: add allocation accounting into slab allocation and free paths 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, 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: 7E67C100015 X-Stat-Signature: e7dfttgbppbzzaqacq1gmseix8499dqa X-Rspam-User: X-HE-Tag: 1707774019-128417 X-HE-Meta: U2FsdGVkX1+ewQ226bwJwsn6EgQBiCv29hKE/gTVnXNLJ7qa1qgiZ3PUEqMEVugqb34UQfpl8oqaE7s7+kJjzOCjpPCxvx3wyuJKCSVjo7jFAjf2ZziONdrkaGenedvH/eMbeQS3M7fqxG1PwL1cYVPPp5lxHQCt2cJjsWsfnmV7in8hfRIL4ANjae3BepCrUjQe+pUytpHJxVnvqOppBgNMC0RghQSBrSKu8VCNo/7XlPC9Yp6S9eGMDHPYfTFVxGUrbdv0sHOXFqCpmLIXmbSLpsNILTqLpG3MPI3BKfX+pxGGmMDXTMTd6tgozHnzq2FKZpx1f5copNO7dct3iqP05a2FPEzFBkf1qmc+jvkFRxLTHYDaIiznBfsCrO88+LcaIVfzxhUwpokIJbMmcazIJ5EuNquOIj1NlE62uEdlOd2mjgrHqCHrDeZKV1Ap6ED4VgynHGeh5csJyWv8tABSC5U4wLjjYdaniMpjkvfJn15FQdw3Evq6kMfwb69nUItZJYfa+GNWFpEtv02qQ6tCvCFT2j3YF8x6In3F6c+e4tAnASVnnUv/cU1/zhsMg82qFZrQqPzsMEJAKrswr42cH4L4h0mfoOApoH7VsD/K85/zx/xz9k+hzRT7MQyvA4CQ5n7Y4A61FVHrQ1CAglmx8EUtMPLiaOs+Mi3rdrneTjk6I2+yB4Y8L8tNdjT65LsRDMjCpGaP0jxzwyw7nfLclKEMM8v/GzRQRjSZx3xz0tkhge8iUBFYMNpAqcdyIGs+S8IkMTFnd2zivPAftYP77LfQAbMNjC8WutOl/yzSPbQpKmHQXf41o9G5zFYrTdodcYkEa4bcWo5drxzqB/kv92ymgF8rq8IXXmVQjDc4yXiU4FRi6uN/UVXerSLTEt/YZXWSKbIXxb1B3qCvkgJ/FME9xobuU2WDfy2VcjvDEadl5QiXXO+aWvuruOJzg690I7S6YoCmW7HBRR+ eiVmd2aR bFrAP0aUAAt8HMUPtRK9wmYrZ90Sj58+c12oLId54a0vLoqcn01LEuW+iMBCSKGK0b9rEEhTYfCxsgeJnZ40XQ/i6B5fFKOieCgiafIhnTXAfccJ5Ylqwkd6K+VuU//Jk4Ss1oHYNilUpwNFtDUjrkCyo9J66788MwHsX3HeP6GTgbsXoyLEgHPlYRW6CUlUIgMsHgu7eaIg9/GuBCFr55qA0aQvNgWGSgUMbpTVWSNcjW5TCzn3Iz9rdcm7wTaKKGeQwl5YWNIIBeV0qrZywrTfXqGiwzyHf/HPnBZLtAXPC+AaP/Kx96cu4Wks0BMqc3mm6qTtuV0B8/QSR6z1kbd03w+81IkldoOBPn5zRNn1w//5H2L4bc9OftqZ13Ot1pzxDFQeuww6SceZYEEvyZ3ruEPIEm7xrqhyW 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: Account slab allocations using codetag reference embedded into slabobj_ext. Signed-off-by: Suren Baghdasaryan Co-developed-by: Kent Overstreet Signed-off-by: Kent Overstreet Reviewed-by: Kees Cook --- mm/slab.h | 26 ++++++++++++++++++++++++++ mm/slub.c | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/mm/slab.h b/mm/slab.h index 224a4b2305fb..c4bd0d5348cb 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -629,6 +629,32 @@ prepare_slab_obj_exts_hook(struct kmem_cache *s, gfp_t flags, void *p) #endif /* CONFIG_SLAB_OBJ_EXT */ +#ifdef CONFIG_MEM_ALLOC_PROFILING + +static inline void alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, + void **p, int objects) +{ + struct slabobj_ext *obj_exts; + int i; + + obj_exts = slab_obj_exts(slab); + if (!obj_exts) + return; + + for (i = 0; i < objects; i++) { + unsigned int off = obj_to_index(s, slab, p[i]); + + alloc_tag_sub(&obj_exts[off].ref, s->size); + } +} + +#else + +static inline void alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, + void **p, int objects) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING */ + #ifdef CONFIG_MEMCG_KMEM void mod_objcg_state(struct obj_cgroup *objcg, struct pglist_data *pgdat, enum node_stat_item idx, int nr); diff --git a/mm/slub.c b/mm/slub.c index 9fd96238ed39..f4d5794c1e86 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3821,6 +3821,11 @@ void slab_post_alloc_hook(struct kmem_cache *s, struct obj_cgroup *objcg, s->flags, init_flags); kmsan_slab_alloc(s, p[i], init_flags); obj_exts = prepare_slab_obj_exts_hook(s, flags, p[i]); +#ifdef CONFIG_MEM_ALLOC_PROFILING + /* obj_exts can be allocated for other reasons */ + if (likely(obj_exts) && mem_alloc_profiling_enabled()) + alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size); +#endif } memcg_slab_post_alloc_hook(s, objcg, flags, size, p);