Skip to content

Commit 34a023d

Browse files
surenbaghdasaryanakpm00
authored andcommitted
mm: handle profiling for fake memory allocations during compaction
During compaction isolated free pages are marked allocated so that they can be split and/or freed. For that, post_alloc_hook() is used inside split_map_pages() and release_free_list(). split_map_pages() marks free pages allocated, splits the pages and then lets alloc_contig_range_noprof() free those pages. release_free_list() marks free pages and immediately frees them. This usage of post_alloc_hook() affect memory allocation profiling because these functions might not be called from an instrumented allocator, therefore current->alloc_tag is NULL and when debugging is enabled (CONFIG_MEM_ALLOC_PROFILING_DEBUG=y) that causes warnings. To avoid that, wrap such post_alloc_hook() calls into an instrumented function which acts as an allocator which will be charged for these fake allocations. Note that these allocations are very short lived until they are freed, therefore the associated counters should usually read 0. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Suren Baghdasaryan <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Pasha Tatashin <[email protected]> Cc: Sourav Panda <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b4601d0 commit 34a023d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

mm/compaction.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ static inline bool is_via_compact_memory(int order) { return false; }
7979
#define COMPACTION_HPAGE_ORDER (PMD_SHIFT - PAGE_SHIFT)
8080
#endif
8181

82+
static struct page *mark_allocated_noprof(struct page *page, unsigned int order, gfp_t gfp_flags)
83+
{
84+
post_alloc_hook(page, order, __GFP_MOVABLE);
85+
return page;
86+
}
87+
#define mark_allocated(...) alloc_hooks(mark_allocated_noprof(__VA_ARGS__))
88+
8289
static void split_map_pages(struct list_head *freepages)
8390
{
8491
unsigned int i, order;
@@ -93,7 +100,7 @@ static void split_map_pages(struct list_head *freepages)
93100

94101
nr_pages = 1 << order;
95102

96-
post_alloc_hook(page, order, __GFP_MOVABLE);
103+
mark_allocated(page, order, __GFP_MOVABLE);
97104
if (order)
98105
split_page(page, order);
99106

@@ -122,7 +129,7 @@ static unsigned long release_free_list(struct list_head *freepages)
122129
* Convert free pages into post allocation pages, so
123130
* that we can free them via __free_page.
124131
*/
125-
post_alloc_hook(page, order, __GFP_MOVABLE);
132+
mark_allocated(page, order, __GFP_MOVABLE);
126133
__free_pages(page, order);
127134
if (pfn > high_pfn)
128135
high_pfn = pfn;

0 commit comments

Comments
 (0)