-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: introduce support for page allocation tagging
Introduce helper functions to easily instrument page allocators by storing a pointer to the allocation tag associated with the code that allocated the page in a page_ext field. Link: https://lkml.kernel.org/r/20240321163705.3067592-15-surenb@google.com Signed-off-by: Suren Baghdasaryan <surenb@google.com> Co-developed-by: Kent Overstreet <kent.overstreet@linux.dev> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Tested-by: Kees Cook <keescook@chromium.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Alex Gaynor <alex.gaynor@gmail.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andreas Hindborg <a.hindborg@samsung.com> Cc: Benno Lossin <benno.lossin@proton.me> Cc: "Björn Roy Baron" <bjorn3_gh@protonmail.com> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Dennis Zhou <dennis@kernel.org> Cc: Gary Guo <gary@garyguo.net> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tejun Heo <tj@kernel.org> Cc: Wedson Almeida Filho <wedsonaf@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
- Loading branch information
1 parent
22d407b
commit dcfe378
Showing
7 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* page allocation tagging | ||
*/ | ||
#ifndef _LINUX_PGALLOC_TAG_H | ||
#define _LINUX_PGALLOC_TAG_H | ||
|
||
#include <linux/alloc_tag.h> | ||
|
||
#ifdef CONFIG_MEM_ALLOC_PROFILING | ||
|
||
#include <linux/page_ext.h> | ||
|
||
extern struct page_ext_operations page_alloc_tagging_ops; | ||
extern struct page_ext *page_ext_get(struct page *page); | ||
extern void page_ext_put(struct page_ext *page_ext); | ||
|
||
static inline union codetag_ref *codetag_ref_from_page_ext(struct page_ext *page_ext) | ||
{ | ||
return (void *)page_ext + page_alloc_tagging_ops.offset; | ||
} | ||
|
||
static inline struct page_ext *page_ext_from_codetag_ref(union codetag_ref *ref) | ||
{ | ||
return (void *)ref - page_alloc_tagging_ops.offset; | ||
} | ||
|
||
/* Should be called only if mem_alloc_profiling_enabled() */ | ||
static inline union codetag_ref *get_page_tag_ref(struct page *page) | ||
{ | ||
if (page) { | ||
struct page_ext *page_ext = page_ext_get(page); | ||
|
||
if (page_ext) | ||
return codetag_ref_from_page_ext(page_ext); | ||
} | ||
return NULL; | ||
} | ||
|
||
static inline void put_page_tag_ref(union codetag_ref *ref) | ||
{ | ||
page_ext_put(page_ext_from_codetag_ref(ref)); | ||
} | ||
|
||
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); | ||
} | ||
} | ||
} | ||
|
||
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); | ||
} | ||
} | ||
} | ||
|
||
#else /* CONFIG_MEM_ALLOC_PROFILING */ | ||
|
||
static inline void pgalloc_tag_add(struct page *page, struct task_struct *task, | ||
unsigned int nr) {} | ||
static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {} | ||
|
||
#endif /* CONFIG_MEM_ALLOC_PROFILING */ | ||
|
||
#endif /* _LINUX_PGALLOC_TAG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters