Skip to content

Commit 8151c7a

Browse files
osalvadorvilardagaakpm00
authored andcommitted
lib/stackdepot: move stack_record struct definition into the header
In order to move the heavy lifting into page_owner code, this one needs to have access to the stack_record structure, which right now sits in lib/stackdepot.c. Move it to the stackdepot.h header so page_owner can access stack_record's struct fields. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Oscar Salvador <[email protected]> Reviewed-by: Marco Elver <[email protected]> Reviewed-by: Vlastimil Babka <[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 3ee34ea commit 8151c7a

File tree

2 files changed

+47
-43
lines changed

2 files changed

+47
-43
lines changed

include/linux/stackdepot.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,53 @@ typedef u32 depot_stack_handle_t;
3030
*/
3131
#define STACK_DEPOT_EXTRA_BITS 5
3232

33+
#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8)
34+
35+
#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */
36+
#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER))
37+
#define DEPOT_STACK_ALIGN 4
38+
#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN)
39+
#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \
40+
STACK_DEPOT_EXTRA_BITS)
41+
42+
#ifdef CONFIG_STACKDEPOT
43+
/* Compact structure that stores a reference to a stack. */
44+
union handle_parts {
45+
depot_stack_handle_t handle;
46+
struct {
47+
/* pool_index is offset by 1 */
48+
u32 pool_index : DEPOT_POOL_INDEX_BITS;
49+
u32 offset : DEPOT_OFFSET_BITS;
50+
u32 extra : STACK_DEPOT_EXTRA_BITS;
51+
};
52+
};
53+
54+
struct stack_record {
55+
struct list_head hash_list; /* Links in the hash table */
56+
u32 hash; /* Hash in hash table */
57+
u32 size; /* Number of stored frames */
58+
union handle_parts handle; /* Constant after initialization */
59+
refcount_t count;
60+
union {
61+
unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */
62+
struct {
63+
/*
64+
* An important invariant of the implementation is to
65+
* only place a stack record onto the freelist iff its
66+
* refcount is zero. Because stack records with a zero
67+
* refcount are never considered as valid, it is safe to
68+
* union @entries and freelist management state below.
69+
* Conversely, as soon as an entry is off the freelist
70+
* and its refcount becomes non-zero, the below must not
71+
* be accessed until being placed back on the freelist.
72+
*/
73+
struct list_head free_list; /* Links in the freelist */
74+
unsigned long rcu_state; /* RCU cookie */
75+
};
76+
};
77+
};
78+
#endif
79+
3380
typedef u32 depot_flags_t;
3481

3582
/*

lib/stackdepot.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,55 +36,12 @@
3636
#include <linux/memblock.h>
3737
#include <linux/kasan-enabled.h>
3838

39-
#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8)
40-
41-
#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */
42-
#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER))
43-
#define DEPOT_STACK_ALIGN 4
44-
#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN)
45-
#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \
46-
STACK_DEPOT_EXTRA_BITS)
4739
#define DEPOT_POOLS_CAP 8192
4840
/* The pool_index is offset by 1 so the first record does not have a 0 handle. */
4941
#define DEPOT_MAX_POOLS \
5042
(((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \
5143
(1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP)
5244

53-
/* Compact structure that stores a reference to a stack. */
54-
union handle_parts {
55-
depot_stack_handle_t handle;
56-
struct {
57-
u32 pool_index : DEPOT_POOL_INDEX_BITS; /* pool_index is offset by 1 */
58-
u32 offset : DEPOT_OFFSET_BITS;
59-
u32 extra : STACK_DEPOT_EXTRA_BITS;
60-
};
61-
};
62-
63-
struct stack_record {
64-
struct list_head hash_list; /* Links in the hash table */
65-
u32 hash; /* Hash in hash table */
66-
u32 size; /* Number of stored frames */
67-
union handle_parts handle; /* Constant after initialization */
68-
refcount_t count;
69-
union {
70-
unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */
71-
struct {
72-
/*
73-
* An important invariant of the implementation is to
74-
* only place a stack record onto the freelist iff its
75-
* refcount is zero. Because stack records with a zero
76-
* refcount are never considered as valid, it is safe to
77-
* union @entries and freelist management state below.
78-
* Conversely, as soon as an entry is off the freelist
79-
* and its refcount becomes non-zero, the below must not
80-
* be accessed until being placed back on the freelist.
81-
*/
82-
struct list_head free_list; /* Links in the freelist */
83-
unsigned long rcu_state; /* RCU cookie */
84-
};
85-
};
86-
};
87-
8845
static bool stack_depot_disabled;
8946
static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);
9047
static bool __stack_depot_early_init_passed __initdata;

0 commit comments

Comments
 (0)