Skip to content

Commit e0a955b

Browse files
yuzhaogoogleakpm00
authored andcommitted
mm/codetag: add pgalloc_tag_copy()
Add pgalloc_tag_copy() to transfer the codetag from the old folio to the new one during migration. This makes original allocation sites persist cross migration rather than lump into the get_new_folio callbacks passed into migrate_pages(), e.g., compaction_alloc(): # echo 1 >/proc/sys/vm/compact_memory # grep compaction_alloc /proc/allocinfo Before this patch: 132968448 32463 mm/compaction.c:1880 func:compaction_alloc After this patch: 0 0 mm/compaction.c:1880 func:compaction_alloc Link: https://lkml.kernel.org/r/[email protected] Fixes: dcfe378 ("lib: introduce support for page allocation tagging") Signed-off-by: Yu Zhao <[email protected]> Acked-by: Suren Baghdasaryan <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 95599ef commit e0a955b

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

include/linux/alloc_tag.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,16 @@ static inline void alloc_tag_sub_check(union codetag_ref *ref) {}
137137
/* Caller should verify both ref and tag to be valid */
138138
static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
139139
{
140+
alloc_tag_add_check(ref, tag);
141+
if (!ref || !tag)
142+
return;
143+
140144
ref->ct = &tag->ct;
145+
}
146+
147+
static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
148+
{
149+
__alloc_tag_ref_set(ref, tag);
141150
/*
142151
* We need in increment the call counter every time we have a new
143152
* allocation or when we split a large allocation into smaller ones.
@@ -147,22 +156,9 @@ static inline void __alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag
147156
this_cpu_inc(tag->counters->calls);
148157
}
149158

150-
static inline void alloc_tag_ref_set(union codetag_ref *ref, struct alloc_tag *tag)
151-
{
152-
alloc_tag_add_check(ref, tag);
153-
if (!ref || !tag)
154-
return;
155-
156-
__alloc_tag_ref_set(ref, tag);
157-
}
158-
159159
static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, size_t bytes)
160160
{
161-
alloc_tag_add_check(ref, tag);
162-
if (!ref || !tag)
163-
return;
164-
165-
__alloc_tag_ref_set(ref, tag);
161+
alloc_tag_ref_set(ref, tag);
166162
this_cpu_add(tag->counters->bytes, bytes);
167163
}
168164

include/linux/mm.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,10 +4108,37 @@ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new
41084108
}
41094109
}
41104110
}
4111+
4112+
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
4113+
{
4114+
struct alloc_tag *tag;
4115+
union codetag_ref *ref;
4116+
4117+
tag = pgalloc_tag_get(&old->page);
4118+
if (!tag)
4119+
return;
4120+
4121+
ref = get_page_tag_ref(&new->page);
4122+
if (!ref)
4123+
return;
4124+
4125+
/* Clear the old ref to the original allocation tag. */
4126+
clear_page_tag_ref(&old->page);
4127+
/* Decrement the counters of the tag on get_new_folio. */
4128+
alloc_tag_sub(ref, folio_nr_pages(new));
4129+
4130+
__alloc_tag_ref_set(ref, tag);
4131+
4132+
put_page_tag_ref(ref);
4133+
}
41114134
#else /* !CONFIG_MEM_ALLOC_PROFILING */
41124135
static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
41134136
{
41144137
}
4138+
4139+
static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
4140+
{
4141+
}
41154142
#endif /* CONFIG_MEM_ALLOC_PROFILING */
41164143

41174144
#endif /* _LINUX_MM_H */

mm/migrate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio)
743743
folio_set_readahead(newfolio);
744744

745745
folio_copy_owner(newfolio, folio);
746+
pgalloc_tag_copy(newfolio, folio);
746747

747748
mem_cgroup_migrate(folio, newfolio);
748749
}

0 commit comments

Comments
 (0)