From: Suren Baghdasaryan <surenb@google.com>
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
Subject: [PATCH v2 4/6] alloc_tag: introduce pgalloc_tag_ref to abstract page tag references
Date: Sun, 1 Sep 2024 21:41:26 -0700 [thread overview]
Message-ID: <20240902044128.664075-5-surenb@google.com> (raw)
In-Reply-To: <20240902044128.664075-1-surenb@google.com>
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 <surenb@google.com>
---
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 <linux/page_ext.h>
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 <linux/gfp.h>
#include <linux/module.h>
#include <linux/page_ext.h>
+#include <linux/pgalloc_tag.h>
#include <linux/proc_fs.h>
#include <linux/seq_buf.h>
#include <linux/seq_file.h>
@@ -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,
};
--
2.46.0.469.g59c65b2a67-goog
next prev parent reply other threads:[~2024-09-02 4:41 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-02 4:41 [PATCH v2 0/6] page allocation tag compression Suren Baghdasaryan
2024-09-02 4:41 ` [PATCH v2 1/6] maple_tree: add mas_for_each_rev() helper Suren Baghdasaryan
2024-09-02 4:41 ` [PATCH v2 2/6] alloc_tag: load module tags into separate continuous memory Suren Baghdasaryan
2024-09-02 4:41 ` [PATCH v2 3/6] alloc_tag: eliminate alloc_tag_ref_set Suren Baghdasaryan
2024-09-02 4:41 ` Suren Baghdasaryan [this message]
2024-09-02 4:41 ` [PATCH v2 5/6] alloc_tag: make page allocation tag reference size configurable Suren Baghdasaryan
2024-09-02 5:09 ` Andrew Morton
2024-09-04 1:07 ` Suren Baghdasaryan
2024-09-04 1:16 ` Kent Overstreet
2024-09-04 2:04 ` Suren Baghdasaryan
2024-09-04 16:25 ` Kent Overstreet
2024-09-04 16:35 ` Suren Baghdasaryan
2024-09-02 4:41 ` [PATCH v2 6/6] alloc_tag: config to store page allocation tag refs in page flags Suren Baghdasaryan
2024-09-02 5:16 ` Andrew Morton
2024-09-03 18:19 ` Suren Baghdasaryan
2024-09-04 1:25 ` John Hubbard
2024-09-04 2:05 ` John Hubbard
2024-09-04 16:08 ` Suren Baghdasaryan
2024-09-04 18:58 ` John Hubbard
2024-09-04 21:07 ` Suren Baghdasaryan
2024-09-04 2:18 ` Matthew Wilcox
2024-09-04 16:18 ` Suren Baghdasaryan
2024-09-04 16:21 ` Kent Overstreet
2024-09-04 16:35 ` Matthew Wilcox
2024-09-04 16:37 ` Kent Overstreet
2024-09-04 16:39 ` Suren Baghdasaryan
2024-09-04 2:41 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240902044128.664075-5-surenb@google.com \
--to=surenb@google.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=david@redhat.com \
--cc=dennis@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=iamjoonsoo.kim@lge.com \
--cc=jhubbard@nvidia.com \
--cc=kaleshsingh@google.com \
--cc=keescook@chromium.org \
--cc=kent.overstreet@linux.dev \
--cc=kernel-team@android.com \
--cc=liam.howlett@oracle.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mhocko@suse.com \
--cc=minchan@google.com \
--cc=pasha.tatashin@soleen.com \
--cc=paulmck@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=souravpanda@google.com \
--cc=tglx@linutronix.de \
--cc=thuth@redhat.com \
--cc=vbabka@suse.cz \
--cc=vvvvvv@google.com \
--cc=willy@infradead.org \
--cc=xiongwei.song@windriver.com \
--cc=yuzhao@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox