From patchwork Mon Sep 2 04:41:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13786704 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 A10FBC54FC6 for ; Mon, 2 Sep 2024 04:41:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 091326B00B8; Mon, 2 Sep 2024 00:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F34918D0065; Mon, 2 Sep 2024 00:41:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D37A38D0071; Mon, 2 Sep 2024 00:41:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A94538D0065 for ; Mon, 2 Sep 2024 00:41:43 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4E184AB108 for ; Mon, 2 Sep 2024 04:41:43 +0000 (UTC) X-FDA: 82518550086.12.D48E600 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf10.hostedemail.com (Postfix) with ESMTP id 8A4E1C000B for ; Mon, 2 Sep 2024 04:41:41 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="mIYC77/c"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3BELVZgYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BELVZgYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725252025; a=rsa-sha256; cv=none; b=i0zQcpUV//1OVb0YizDoo16GZCHeOscARzXsVGWc7k9MEa3hWt/yGxB3q/FL+QmJ0HxBkJ Hxccm/pA3Knp+hP1hSNCpiBL3Jj782GX+Lg+TKuB9vcKU6QtxLVkHe4BU4ujdGPPMaZP/w HsQdPxf3zcfdI6rIi1Nan9GXOVTzrAI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="mIYC77/c"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3BELVZgYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3BELVZgYKCBsJLI5E27FF7C5.3FDC9ELO-DDBM13B.FI7@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725252025; 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=Nlt0d2kKMzLV8FpvC+sskMXVjz4TJlE3ZyIfZQBAJUA=; b=nViQcTg+AAORNBuTUYhI5CwHnNrabC3+p/JRyH8hJwVd7yQMJJ4G8dYL/ChS7C5CN+LwpW /Ie+1/zuTa6q7Pa19adhghE+T0JTNZ/pJ+KJudp16QK1E/fyXnomnCNT3dwAeIetd94qED Nrr308yu8zmooom1lHgPR//o+oKsIMY= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d4b832fb63so51626317b3.2 for ; Sun, 01 Sep 2024 21:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725252100; x=1725856900; 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=Nlt0d2kKMzLV8FpvC+sskMXVjz4TJlE3ZyIfZQBAJUA=; b=mIYC77/czyLMBgjCINDn0eCP4r7gTuzumyhuMEDZnTHYEHkCtRkShvOSTXsGpTYTj7 5jQ3ETtKbFrPzFIT+8L7tuapkzlOICMSBHNuHbu3v6KuvQnWsnmrCX5RHzCrHffsrg6i PDF718uOm+LNT6STucoiT6c2vxZVM1JEBLORgbJCbrCbGBF4Se7FgkDtYTBNb5qsqqSG ufGl3xzdbqEQDXqY2sKzJZ8pHkTpr6GOU9xkZNbEp+2Mv3ay27/p6lOt8w9Lf73O6lDX HSoHrvOZrqwJGg/SOLtuuHyuKyPCQUzCe1lj3Es7gP5O3MN2EddKJ2SGM7dYaUvQNQMD OYSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725252100; x=1725856900; 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=Nlt0d2kKMzLV8FpvC+sskMXVjz4TJlE3ZyIfZQBAJUA=; b=lAHcvai2BOOJzreSE1Nr1VBUhsBb/ahM9Zy0RZMhjJTvMjY9x88TOild2uC66J81e+ CeBbeSk02Mm+X3XaJ3ssTO5B1bHuJ0K0d4kdaBPiAM+DM23elxsVghMBqprMztpKWkDK TG4W5GCfnM6HfGvpM+eMm+C03JQ/+2ycSRtf/RyuY4/mXiF1MMQK2r9dgP/qOHeWv3Iu r37HJbOOuDS1OeLJC5c3zbL6je5gfmgS7IsOh8y/KQ0crrAXgBwvbI7nDtuJ0UygejPE WvkreysEwJtsJz2E+Qoa8dQ/UhkcyB7vhRYEBNRNclS1lDuEHYap5co8gyoE1rs5rjob co5g== X-Forwarded-Encrypted: i=1; AJvYcCVuohOFFNGjJ5G3TsAuPoxqQy8byTYTlvM/7KKlw6wGvbD56CvjyMF5oLyuO0Sn8oDpz0bJsZ+ZEw==@kvack.org X-Gm-Message-State: AOJu0Yy5B45MlgvmjumUdU4i7soEhn1sSouxzNv2YaJhPHPzgvJCgyy2 rPXoxN7osuS3cHwXpf4U6q0CjH3m9pUBbBVlRrlDU1o4KOL+4XmGkQLVnafHp6R/oWsUW+BmRuX cIA== X-Google-Smtp-Source: AGHT+IHSPd8nZJZH/UC+NYWl2T7llxAohdiabcKHZvTC/kXLRpqPrIn5YCFkqt976gAwR4y0XtmrRfdj/lI= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:7343:ecd2:aed:5b8f]) (user=surenb job=sendgmr) by 2002:a05:690c:6309:b0:691:41f5:7f42 with SMTP id 00721157ae682-6d40f340f7dmr6255217b3.4.1725252100605; Sun, 01 Sep 2024 21:41:40 -0700 (PDT) Date: Sun, 1 Sep 2024 21:41:26 -0700 In-Reply-To: <20240902044128.664075-1-surenb@google.com> Mime-Version: 1.0 References: <20240902044128.664075-1-surenb@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240902044128.664075-5-surenb@google.com> Subject: [PATCH v2 4/6] alloc_tag: introduce pgalloc_tag_ref to abstract page tag references From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, corbet@lwn.net, arnd@arndb.de, mcgrof@kernel.org, rppt@kernel.org, paulmck@kernel.org, thuth@redhat.com, tglx@linutronix.de, bp@alien8.de, xiongwei.song@windriver.com, ardb@kernel.org, david@redhat.com, vbabka@suse.cz, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, pasha.tatashin@soleen.com, souravpanda@google.com, keescook@chromium.org, dennis@kernel.org, jhubbard@nvidia.com, yuzhao@google.com, vvvvvv@google.com, rostedt@goodmis.org, iamjoonsoo.kim@lge.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8A4E1C000B X-Stat-Signature: 8fh9tz8wy9xy7dqring5x3xmoy6b534a X-Rspam-User: X-HE-Tag: 1725252101-985999 X-HE-Meta: U2FsdGVkX1+Z17NM+Bdv2mk3gUUu9j7F2UievRpM8Pv10TVyuhipK2otF7Wf0RmNaVXjl1R5oMopweZ0XCMwssS01U27ksWrAq9l+B9YQlslsuWNF2EheGmlLVb4LoeWls8T8jIwuVY1lfM6VHoQJy3GZv2YunW9HMlrgpvWpeFHucmGzddnkhQc2wPeQEZHiyCXF06CzeMPJAzZsFeQP2P2ijaO+yIHYiv+mbpdml94p2XQdaqA/77tbeVK6Fk7hGA1KzgnuecrjDVl4kAWs5D+9N2O1fmzl3uSvoSk38SUbw95ZdRnEtXrNyNgFR+RKcmPb1xrh5HZqcW6oKDF1eyXDQ0QHV+CBCQw4hcCuuoR7l03T/42gENGwTpLWAR2vdkQnTPXLLpWGbU3wnYpCvpG5v1utKpESWsBU74RU7LRrZKq+PwLzPq0qy3Shz8TCKE4Q6/lR1jhxsahBPCQwhIwaQg7U9X9LEDbQUkl9ayeSPQVsttCiOYIsXfOcNDamPg9pBnfowMd3w30YH7cFWUY0nKSfG5XWnJHQQGp1QbyKcdYMq+tat2u9+lxf2sQKtCoPvimyzlY5UxLXlLHrpJrOwM4pnn2cYkaqt6T1jHD/ADSKltwubDj6EAydiNBuEc8bj6a9xOhA2Xfdf/hhD1jrpqbJQaG2XyorCurKA0zD8p8xwCb4OgaVu6Gu3y5QmozYj3ICAG2RYr+pHRBiOJQ7VsTurER4aC4VcFejkf26WPkwToWeGhRUKwQQ2Z6D9CtGgfrPkc9DOUjns/UNIZ7QnyjGySWXCMhWbFzOlFLJ7GHdKuzPF+B3kxbuwrQXL8W2+xdK627j3uXake61f9b6gPRGgF61At9kHg0xs25/01wn/KB84jQl8WfS/EkdaKpYn5dg8yyIthRqHUoO9NXw1elQ8NM4H9lN1FaznVL/seE0DTeB3pog5vUoAy5tz9hm30fZRMko2MU8hU GhGcCOp4 w2viH4jxUeu9QzZrh/XOHtuoS69Pd/ysRnS6nFIEHlhXyOOMFKVKKQo9H8yQRnDehCreecbZ+mvsSZrAy2MZrbb5Jk9PVhWl5waOLj1pyt/wPplxHy7l6M9WbJHiimJBQK0IVa38sdrhBhegotUzl//GDb465pXuSEDbmo4HN/r+ePLG7L09QL4WwprOMzuDJFRSjo7+48p9+urBOPQ9bvu2kRIAuChLlCNh1bU8zS9W51GUmfV3srN0zd0hlye1veqOIe8I6FGaenQTLxrUa1gW5iD4VQ+A+x63+rqYxoB8qOpGNAS7e8bm8FDKcCcIAc7zBGBLykM+ODo2U/XQ8s61tsYNNEkPQqrEU/L5pkRLUjg7QlLthMzq8NPgH25q00wup37Q0dSUPI3FeUribCAoW1t6NGs5F4+fkx42HpozeUKZKHjmPWoLGc0LzzZLUcIXsDQS3ALdBd4tskX7C1JfBjwMmn6W1EfkUwjxYiJANkEIyEZyTTTAghXzV47SRIcJbAN0Fx32OIxYrh1fuFy+7PRLdVqL3hsmHKXNtbZ+NenYRtZHpW6JPgA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000045, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To simplify later changes to page tag references, introduce new pgalloc_tag_ref and pgtag_ref_handle types. This allows easy replacement of page_ext as a storage of page allocation tags Signed-off-by: Suren Baghdasaryan --- include/linux/pgalloc_tag.h | 144 +++++++++++++++++++++++------------- lib/alloc_tag.c | 3 +- 2 files changed, 95 insertions(+), 52 deletions(-) diff --git a/include/linux/pgalloc_tag.h b/include/linux/pgalloc_tag.h index 244a328dff62..c76b629d0206 100644 --- a/include/linux/pgalloc_tag.h +++ b/include/linux/pgalloc_tag.h @@ -9,48 +9,76 @@ #ifdef CONFIG_MEM_ALLOC_PROFILING +typedef union codetag_ref pgalloc_tag_ref; + +static inline void read_pgref(pgalloc_tag_ref *pgref, union codetag_ref *ref) +{ + ref->ct = pgref->ct; +} + +static inline void write_pgref(pgalloc_tag_ref *pgref, union codetag_ref *ref) +{ + pgref->ct = ref->ct; +} #include extern struct page_ext_operations page_alloc_tagging_ops; -static inline union codetag_ref *codetag_ref_from_page_ext(struct page_ext *page_ext) +static inline pgalloc_tag_ref *pgref_from_page_ext(struct page_ext *page_ext) { - return (union codetag_ref *)page_ext_data(page_ext, &page_alloc_tagging_ops); + return (pgalloc_tag_ref *)page_ext_data(page_ext, &page_alloc_tagging_ops); } -static inline struct page_ext *page_ext_from_codetag_ref(union codetag_ref *ref) +static inline struct page_ext *page_ext_from_pgref(pgalloc_tag_ref *pgref) { - return (void *)ref - page_alloc_tagging_ops.offset; + return (void *)pgref - page_alloc_tagging_ops.offset; } +typedef pgalloc_tag_ref *pgtag_ref_handle; + /* Should be called only if mem_alloc_profiling_enabled() */ -static inline union codetag_ref *get_page_tag_ref(struct page *page) +static inline pgtag_ref_handle get_page_tag_ref(struct page *page, union codetag_ref *ref) { if (page) { struct page_ext *page_ext = page_ext_get(page); - if (page_ext) - return codetag_ref_from_page_ext(page_ext); + if (page_ext) { + pgalloc_tag_ref *pgref = pgref_from_page_ext(page_ext); + + read_pgref(pgref, ref); + return pgref; + } } return NULL; } -static inline void put_page_tag_ref(union codetag_ref *ref) +static inline void put_page_tag_ref(pgtag_ref_handle pgref) { - if (WARN_ON(!ref)) + if (WARN_ON(!pgref)) return; - page_ext_put(page_ext_from_codetag_ref(ref)); + page_ext_put(page_ext_from_pgref(pgref)); +} + +static inline void update_page_tag_ref(pgtag_ref_handle pgref, union codetag_ref *ref) +{ + if (WARN_ON(!pgref || !ref)) + return; + + write_pgref(pgref, ref); } static inline void clear_page_tag_ref(struct page *page) { if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - set_codetag_empty(ref); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + set_codetag_empty(&ref); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } @@ -59,11 +87,14 @@ static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int nr) { if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - alloc_tag_add(ref, task->alloc_tag, PAGE_SIZE * nr); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_add(&ref, task->alloc_tag, PAGE_SIZE * nr); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } @@ -71,53 +102,58 @@ static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) { if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - if (ref) { - alloc_tag_sub(ref, PAGE_SIZE * nr); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_sub(&ref, PAGE_SIZE * nr); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } } } static inline void pgalloc_tag_split(struct page *page, unsigned int nr) { - int i; - struct page_ext *first_page_ext; - struct page_ext *page_ext; - union codetag_ref *ref; + pgtag_ref_handle first_pgref; + union codetag_ref first_ref; struct alloc_tag *tag; + int i; if (!mem_alloc_profiling_enabled()) return; - first_page_ext = page_ext = page_ext_get(page); - if (unlikely(!page_ext)) + first_pgref = get_page_tag_ref(page, &first_ref); + if (unlikely(!first_pgref)) return; - ref = codetag_ref_from_page_ext(page_ext); - if (!ref->ct) + if (!first_ref.ct) goto out; - tag = ct_to_alloc_tag(ref->ct); - page_ext = page_ext_next(page_ext); + tag = ct_to_alloc_tag(first_ref.ct); for (i = 1; i < nr; i++) { - /* Set new reference to point to the original tag */ - ref = codetag_ref_from_page_ext(page_ext); - alloc_tag_add_check(ref, tag); - if (ref) { - ref->ct = &tag->ct; + pgtag_ref_handle handle; + union codetag_ref ref; + + page++; + handle = get_page_tag_ref(page, &ref); + if (handle) { + /* Set new reference to point to the original tag */ + alloc_tag_add_check(&ref, tag); + ref.ct = &tag->ct; /* * We need in increment the call counter every time we split a * large allocation into smaller ones because when we free each * part the counter will be decremented. */ this_cpu_inc(tag->counters->calls); + update_page_tag_ref(handle, &ref); + put_page_tag_ref(handle); } - page_ext = page_ext_next(page_ext); } out: - page_ext_put(first_page_ext); + put_page_tag_ref(first_pgref); } static inline struct alloc_tag *pgalloc_tag_get(struct page *page) @@ -125,13 +161,15 @@ static inline struct alloc_tag *pgalloc_tag_get(struct page *page) struct alloc_tag *tag = NULL; if (mem_alloc_profiling_enabled()) { - union codetag_ref *ref = get_page_tag_ref(page); - - alloc_tag_sub_check(ref); - if (ref) { - if (ref->ct) - tag = ct_to_alloc_tag(ref->ct); - put_page_tag_ref(ref); + pgtag_ref_handle handle; + union codetag_ref ref; + + handle = get_page_tag_ref(page, &ref); + if (handle) { + alloc_tag_sub_check(&ref); + if (ref.ct) + tag = ct_to_alloc_tag(ref.ct); + put_page_tag_ref(handle); } } @@ -146,8 +184,12 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) #else /* CONFIG_MEM_ALLOC_PROFILING */ -static inline union codetag_ref *get_page_tag_ref(struct page *page) { return NULL; } -static inline void put_page_tag_ref(union codetag_ref *ref) {} +typedef void *pgtag_ref_handle; + +static inline pgtag_ref_handle +get_page_tag_ref(struct page *page, union codetag_ref *ref) { return NULL; } +static inline void put_page_tag_ref(pgtag_ref_handle handle) {} +static inline void update_page_tag_ref(pgtag_ref_handle handle, union codetag_ref *ref) {} static inline void clear_page_tag_ref(struct page *page) {} static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, unsigned int nr) {} diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 19ef02a18611..53bd3236d30b 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -436,7 +437,7 @@ static __init void init_page_alloc_tagging(void) } struct page_ext_operations page_alloc_tagging_ops = { - .size = sizeof(union codetag_ref), + .size = sizeof(pgalloc_tag_ref), .need = need_page_alloc_tagging, .init = init_page_alloc_tagging, };