2023-01-30 20:51:11

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH 08/18] lib/stackdepot: reorder and annotate global variables

From: Andrey Konovalov <[email protected]>

Group stack depot global variables by their purpose:

1. Hash table-related variables,
2. Slab-related variables,

and add comments.

Also clean up comments for hash table-related constants.

Signed-off-by: Andrey Konovalov <[email protected]>
---
lib/stackdepot.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index cb098bc99286..89aee133303a 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -75,24 +75,31 @@ static bool stack_depot_disabled;
static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT);
static bool __stack_depot_early_init_passed __initdata;

-static void *stack_slabs[STACK_ALLOC_MAX_SLABS];
-
-static int depot_index;
-static int next_slab_inited;
-static size_t depot_offset;
-static DEFINE_RAW_SPINLOCK(depot_lock);
-
-/* one hash table bucket entry per 16kB of memory */
+/* Use one hash table bucket per 16 KB of memory. */
#define STACK_HASH_SCALE 14
-/* limited between 4k and 1M buckets */
+/* Limit the number of buckets between 4K and 1M. */
#define STACK_HASH_ORDER_MIN 12
#define STACK_HASH_ORDER_MAX 20
+/* Initial seed for jhash2. */
#define STACK_HASH_SEED 0x9747b28c

+/* Hash table of pointers to stored stack traces. */
+static struct stack_record **stack_table;
+/* Fixed order of the number of table buckets. Used when KASAN is enabled. */
static unsigned int stack_hash_order;
+/* Hash mask for indexing the table. */
static unsigned int stack_hash_mask;

-static struct stack_record **stack_table;
+/* Array of memory regions that store stack traces. */
+static void *stack_slabs[STACK_ALLOC_MAX_SLABS];
+/* Currently used slab in stack_slabs. */
+static int depot_index;
+/* Offset to the unused space in the currently used slab. */
+static size_t depot_offset;
+/* Lock that protects the variables above. */
+static DEFINE_RAW_SPINLOCK(depot_lock);
+/* Whether the next slab is initialized. */
+static int next_slab_inited;

static int __init disable_stack_depot(char *str)
{
--
2.25.1



2023-01-31 10:43:37

by Alexander Potapenko

[permalink] [raw]
Subject: Re: [PATCH 08/18] lib/stackdepot: reorder and annotate global variables

On Mon, Jan 30, 2023 at 9:50 PM <[email protected]> wrote:
>
> From: Andrey Konovalov <[email protected]>
>
> Group stack depot global variables by their purpose:
>
> 1. Hash table-related variables,
> 2. Slab-related variables,
>
> and add comments.
>
> Also clean up comments for hash table-related constants.
>
> Signed-off-by: Andrey Konovalov <[email protected]>
Reviewed-by: Alexander Potapenko <[email protected]>

...
> +/* Lock that protects the variables above. */
> +static DEFINE_RAW_SPINLOCK(depot_lock);
> +/* Whether the next slab is initialized. */
> +static int next_slab_inited;
Might be worth clarifying what happens if there's no next slab (see my
comment to patch 01).

2023-01-31 19:01:54

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH 08/18] lib/stackdepot: reorder and annotate global variables

On Tue, Jan 31, 2023 at 11:43 AM Alexander Potapenko <[email protected]> wrote:
>
> On Mon, Jan 30, 2023 at 9:50 PM <[email protected]> wrote:
> >
> > From: Andrey Konovalov <[email protected]>
> >
> > Group stack depot global variables by their purpose:
> >
> > 1. Hash table-related variables,
> > 2. Slab-related variables,
> >
> > and add comments.
> >
> > Also clean up comments for hash table-related constants.
> >
> > Signed-off-by: Andrey Konovalov <[email protected]>
> Reviewed-by: Alexander Potapenko <[email protected]>
>
> ...
> > +/* Lock that protects the variables above. */
> > +static DEFINE_RAW_SPINLOCK(depot_lock);
> > +/* Whether the next slab is initialized. */
> > +static int next_slab_inited;
> Might be worth clarifying what happens if there's no next slab (see my
> comment to patch 01).

Will do in v2. Thanks!