Skip to content

Commit 4bedfb3

Browse files
osalvadorvilardagaakpm00
authored andcommitted
mm,page_owner: maintain own list of stack_records structs
page_owner needs to increment a stack_record refcount when a new allocation occurs, and decrement it on a free operation. In order to do that, we need to have a way to get a stack_record from a handle. Implement __stack_depot_get_stack_record() which just does that, and make it public so page_owner can use it. Also, traversing all stackdepot buckets comes with its own complexity, plus we would have to implement a way to mark only those stack_records that were originated from page_owner, as those are the ones we are interested in. For that reason, page_owner maintains its own list of stack_records, because traversing that list is faster than traversing all buckets while keeping at the same time a low complexity. For now, add to stack_list only the stack_records of dummy_handle and failure_handle, and set their refcount of 1. Further patches will add code to increment or decrement stack_records count on allocation and free operation. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Oscar Salvador <[email protected]> Reviewed-by: Vlastimil Babka <[email protected]> Reviewed-by: Marco Elver <[email protected]> Acked-by: Andrey Konovalov <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Michal Hocko <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8151c7a commit 4bedfb3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

include/linux/stackdepot.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,
178178
depot_stack_handle_t stack_depot_save(unsigned long *entries,
179179
unsigned int nr_entries, gfp_t gfp_flags);
180180

181+
/**
182+
* __stack_depot_get_stack_record - Get a pointer to a stack_record struct
183+
*
184+
* @handle: Stack depot handle
185+
*
186+
* This function is only for internal purposes.
187+
*
188+
* Return: Returns a pointer to a stack_record struct
189+
*/
190+
struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle);
191+
181192
/**
182193
* stack_depot_fetch - Fetch a stack trace from stack depot
183194
*

lib/stackdepot.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
687687
}
688688
EXPORT_SYMBOL_GPL(stack_depot_save);
689689

690+
struct stack_record *__stack_depot_get_stack_record(depot_stack_handle_t handle)
691+
{
692+
if (!handle)
693+
return NULL;
694+
695+
return depot_fetch_stack(handle);
696+
}
697+
690698
unsigned int stack_depot_fetch(depot_stack_handle_t handle,
691699
unsigned long **entries)
692700
{

mm/page_owner.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ struct page_owner {
3636
pid_t free_tgid;
3737
};
3838

39+
struct stack {
40+
struct stack_record *stack_record;
41+
struct stack *next;
42+
};
43+
static struct stack dummy_stack;
44+
static struct stack failure_stack;
45+
static struct stack *stack_list;
46+
3947
static bool page_owner_enabled __initdata;
4048
DEFINE_STATIC_KEY_FALSE(page_owner_inited);
4149

@@ -95,6 +103,13 @@ static __init void init_page_owner(void)
95103
register_early_stack();
96104
static_branch_enable(&page_owner_inited);
97105
init_early_allocated_pages();
106+
/* Initialize dummy and failure stacks and link them to stack_list */
107+
dummy_stack.stack_record = __stack_depot_get_stack_record(dummy_handle);
108+
failure_stack.stack_record = __stack_depot_get_stack_record(failure_handle);
109+
refcount_set(&dummy_stack.stack_record->count, 1);
110+
refcount_set(&failure_stack.stack_record->count, 1);
111+
dummy_stack.next = &failure_stack;
112+
stack_list = &dummy_stack;
98113
}
99114

100115
struct page_ext_operations page_owner_ops = {

0 commit comments

Comments
 (0)