Skip to content

Commit b7fc16a

Browse files
surenbaghdasaryanakpm00
authored andcommitted
mm/codetag: uninline and move pgalloc_tag_copy and pgalloc_tag_split
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>
1 parent 4835f74 commit b7fc16a

File tree

3 files changed

+53
-58
lines changed

3 files changed

+53
-58
lines changed

include/linux/mm.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4166,62 +4166,4 @@ static inline int do_mseal(unsigned long start, size_t len_in, unsigned long fla
41664166
}
41674167
#endif
41684168

4169-
#ifdef CONFIG_MEM_ALLOC_PROFILING
4170-
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
4171-
{
4172-
int i;
4173-
struct alloc_tag *tag;
4174-
unsigned int nr_pages = 1 << new_order;
4175-
4176-
if (!mem_alloc_profiling_enabled())
4177-
return;
4178-
4179-
tag = pgalloc_tag_get(&folio->page);
4180-
if (!tag)
4181-
return;
4182-
4183-
for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
4184-
union pgtag_ref_handle handle;
4185-
union codetag_ref ref;
4186-
4187-
if (get_page_tag_ref(folio_page(folio, i), &ref, &handle)) {
4188-
/* Set new reference to point to the original tag */
4189-
alloc_tag_ref_set(&ref, tag);
4190-
update_page_tag_ref(handle, &ref);
4191-
put_page_tag_ref(handle);
4192-
}
4193-
}
4194-
}
4195-
4196-
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
4197-
{
4198-
union pgtag_ref_handle handle;
4199-
union codetag_ref ref;
4200-
struct alloc_tag *tag;
4201-
4202-
tag = pgalloc_tag_get(&old->page);
4203-
if (!tag)
4204-
return;
4205-
4206-
if (!get_page_tag_ref(&new->page, &ref, &handle))
4207-
return;
4208-
4209-
/* Clear the old ref to the original allocation tag. */
4210-
clear_page_tag_ref(&old->page);
4211-
/* Decrement the counters of the tag on get_new_folio. */
4212-
alloc_tag_sub(&ref, folio_size(new));
4213-
__alloc_tag_ref_set(&ref, tag);
4214-
update_page_tag_ref(handle, &ref);
4215-
put_page_tag_ref(handle);
4216-
}
4217-
#else /* !CONFIG_MEM_ALLOC_PROFILING */
4218-
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
4219-
{
4220-
}
4221-
4222-
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
4223-
{
4224-
}
4225-
#endif /* CONFIG_MEM_ALLOC_PROFILING */
4226-
42274169
#endif /* _LINUX_MM_H */

include/linux/pgalloc_tag.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ static inline void pgalloc_tag_sub_pages(struct alloc_tag *tag, unsigned int nr)
230230
this_cpu_sub(tag->counters->bytes, PAGE_SIZE * nr);
231231
}
232232

233+
void pgalloc_tag_split(struct folio *folio, int old_order, int new_order);
234+
void pgalloc_tag_copy(struct folio *new, struct folio *old);
235+
233236
void __init alloc_tag_sec_init(void);
234237

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

245250
#endif /* CONFIG_MEM_ALLOC_PROFILING */
246251

lib/alloc_tag.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,54 @@ size_t alloc_tag_top_users(struct codetag_bytes *tags, size_t count, bool can_sl
163163
return nr;
164164
}
165165

166+
void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
167+
{
168+
int i;
169+
struct alloc_tag *tag;
170+
unsigned int nr_pages = 1 << new_order;
171+
172+
if (!mem_alloc_profiling_enabled())
173+
return;
174+
175+
tag = pgalloc_tag_get(&folio->page);
176+
if (!tag)
177+
return;
178+
179+
for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
180+
union pgtag_ref_handle handle;
181+
union codetag_ref ref;
182+
183+
if (get_page_tag_ref(folio_page(folio, i), &ref, &handle)) {
184+
/* Set new reference to point to the original tag */
185+
alloc_tag_ref_set(&ref, tag);
186+
update_page_tag_ref(handle, &ref);
187+
put_page_tag_ref(handle);
188+
}
189+
}
190+
}
191+
192+
void pgalloc_tag_copy(struct folio *new, struct folio *old)
193+
{
194+
union pgtag_ref_handle handle;
195+
union codetag_ref ref;
196+
struct alloc_tag *tag;
197+
198+
tag = pgalloc_tag_get(&old->page);
199+
if (!tag)
200+
return;
201+
202+
if (!get_page_tag_ref(&new->page, &ref, &handle))
203+
return;
204+
205+
/* Clear the old ref to the original allocation tag. */
206+
clear_page_tag_ref(&old->page);
207+
/* Decrement the counters of the tag on get_new_folio. */
208+
alloc_tag_sub(&ref, folio_size(new));
209+
__alloc_tag_ref_set(&ref, tag);
210+
update_page_tag_ref(handle, &ref);
211+
put_page_tag_ref(handle);
212+
}
213+
166214
static void shutdown_mem_profiling(bool remove_file)
167215
{
168216
if (mem_alloc_profiling_enabled())

0 commit comments

Comments
 (0)