Skip to content

Commit

Permalink
mm/codetag: uninline and move pgalloc_tag_copy and pgalloc_tag_split
Browse files Browse the repository at this point in the history
pgalloc_tag_copy() and pgalloc_tag_split() are sizable and outside of any
performance-critical paths, so it should be fine to uninline them.  Also
move their declarations into pgalloc_tag.h which seems like a more
appropriate place for them.  No functional changes other than uninlining.

Link: https://lkml.kernel.org/r/20241024162318.1640781-1-surenb@google.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Suggested-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Yu Zhao <yuzhao@google.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Sourav Panda <souravpanda@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
surenbaghdasaryan authored and akpm00 committed Nov 7, 2024
1 parent 4835f74 commit b7fc16a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 58 deletions.
58 changes: 0 additions & 58 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4166,62 +4166,4 @@ static inline int do_mseal(unsigned long start, size_t len_in, unsigned long fla
}
#endif

#ifdef CONFIG_MEM_ALLOC_PROFILING
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
{
int i;
struct alloc_tag *tag;
unsigned int nr_pages = 1 << new_order;

if (!mem_alloc_profiling_enabled())
return;

tag = pgalloc_tag_get(&folio->page);
if (!tag)
return;

for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
union pgtag_ref_handle handle;
union codetag_ref ref;

if (get_page_tag_ref(folio_page(folio, i), &ref, &handle)) {
/* Set new reference to point to the original tag */
alloc_tag_ref_set(&ref, tag);
update_page_tag_ref(handle, &ref);
put_page_tag_ref(handle);
}
}
}

static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
{
union pgtag_ref_handle handle;
union codetag_ref ref;
struct alloc_tag *tag;

tag = pgalloc_tag_get(&old->page);
if (!tag)
return;

if (!get_page_tag_ref(&new->page, &ref, &handle))
return;

/* Clear the old ref to the original allocation tag. */
clear_page_tag_ref(&old->page);
/* Decrement the counters of the tag on get_new_folio. */
alloc_tag_sub(&ref, folio_size(new));
__alloc_tag_ref_set(&ref, tag);
update_page_tag_ref(handle, &ref);
put_page_tag_ref(handle);
}
#else /* !CONFIG_MEM_ALLOC_PROFILING */
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
{
}

static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
{
}
#endif /* CONFIG_MEM_ALLOC_PROFILING */

#endif /* _LINUX_MM_H */
5 changes: 5 additions & 0 deletions include/linux/pgalloc_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
this_cpu_sub(tag->counters->bytes, PAGE_SIZE * nr);
}

void pgalloc_tag_split(struct folio *folio, int old_order, int new_order);
void pgalloc_tag_copy(struct folio *new, struct folio *old);

void __init alloc_tag_sec_init(void);

#else /* CONFIG_MEM_ALLOC_PROFILING */
Expand All @@ -241,6 +244,8 @@ static inline void pgalloc_tag_sub(struct page *page, unsigned int nr) {}
static inline struct alloc_tag *pgalloc_tag_get(struct page *page) { return NULL; }
static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr) {}
static inline void alloc_tag_sec_init(void) {}
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order) {}
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old) {}

#endif /* CONFIG_MEM_ALLOC_PROFILING */

Expand Down
48 changes: 48 additions & 0 deletions lib/alloc_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,54 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl
return nr;
}

void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
{
int i;
struct alloc_tag *tag;
unsigned int nr_pages = 1 << new_order;

if (!mem_alloc_profiling_enabled())
return;

tag = pgalloc_tag_get(&folio->page);
if (!tag)
return;

for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
union pgtag_ref_handle handle;
union codetag_ref ref;

if (get_page_tag_ref(folio_page(folio, i), &ref, &handle)) {
/* Set new reference to point to the original tag */
alloc_tag_ref_set(&ref, tag);
update_page_tag_ref(handle, &ref);
put_page_tag_ref(handle);
}
}
}

void pgalloc_tag_copy(struct folio *new, struct folio *old)
{
union pgtag_ref_handle handle;
union codetag_ref ref;
struct alloc_tag *tag;

tag = pgalloc_tag_get(&old->page);
if (!tag)
return;

if (!get_page_tag_ref(&new->page, &ref, &handle))
return;

/* Clear the old ref to the original allocation tag. */
clear_page_tag_ref(&old->page);
/* Decrement the counters of the tag on get_new_folio. */
alloc_tag_sub(&ref, folio_size(new));
__alloc_tag_ref_set(&ref, tag);
update_page_tag_ref(handle, &ref);
put_page_tag_ref(handle);
}

static void shutdown_mem_profiling(bool remove_file)
{
if (mem_alloc_profiling_enabled())
Expand Down

0 comments on commit b7fc16a

Please sign in to comment.