From: Marco Elver <elver@google.com>
To: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>,
David Rientjes <rientjes@google.com>,
Christoph Lameter <cl@linux.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Pekka Enberg <penberg@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, patches@lists.linux.dev,
linux-kernel@vger.kernel.org, Oliver Glitta <glittao@gmail.com>,
Faiyaz Mohammed <faiyazm@codeaurora.org>,
Dmitry Vyukov <dvyukov@google.com>,
Eric Dumazet <edumazet@google.com>,
Jarkko Sakkinen <jarkko@kernel.org>,
Johannes Berg <johannes.berg@intel.com>,
Yury Norov <yury.norov@gmail.com>, Arnd Bergmann <arnd@arndb.de>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Matteo Croce <mcroce@microsoft.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Imran Khan <imran.f.khan@oracle.com>,
Zqiang <qiang.zhang@windriver.com>
Subject: Re: [PATCH] lib/stackdepot: Use page allocator if both slab and memblock is unavailable
Date: Mon, 28 Feb 2022 08:00:00 +0100 [thread overview]
Message-ID: <CANpmjNOyVTQZroOEVF_ZLASCtQ=SiC12WGWEwOib3vDk3sCbtw@mail.gmail.com> (raw)
In-Reply-To: <YhrrM7NTYXG5JluY@ip-172-31-19-208.ap-northeast-1.compute.internal>
On Sun, 27 Feb 2022 at 04:08, Hyeonggon Yoo <42.hyeyoo@gmail.com> wrote:
>
> After commit 2dba5eb1c73b ("lib/stackdepot: allow optional init and
> stack_table allocation by kvmalloc()"), stack_depot_init() is called
> later if CONFIG_STACKDEPOT_ALWAYS_INIT=n to remove unnecessary memory
> usage. It allocates stack_table using memblock_alloc() or kvmalloc()
> depending on availability of slab allocator.
>
> But when stack_depot_init() is called while creating boot slab caches,
> both slab allocator and memblock is not available. So kernel crashes.
> Allocate stack_table from page allocator when both slab allocator and
> memblock is unavailable.
This is odd - who is calling stack_depot_init() while neither slab nor
memblock are available? Do you have a stacktrace?
> Limit size of stack_table when using page allocator because vmalloc()
> is also unavailable in kmem_cache_init(). it must not be larger than
> (PAGE_SIZE << (MAX_ORDER - 1)).
>
> This patch was tested on both CONFIG_STACKDEPOT_ALWAYS_INIT=y and n.
>
> Fixes: 2dba5eb1c73b ("lib/stackdepot: allow optional init and stack_table allocation by kvmalloc()")
> Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> ---
> lib/stackdepot.c | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index bf5ba9af0500..606f80ae2bf7 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -73,6 +73,14 @@ static int next_slab_inited;
> static size_t depot_offset;
> static DEFINE_RAW_SPINLOCK(depot_lock);
>
> +static unsigned int stack_hash_size = (1 << CONFIG_STACK_HASH_ORDER);
> +static inline unsigned int stack_hash_mask(void)
> +{
> + return stack_hash_size - 1;
> +}
> +
> +#define STACK_HASH_SEED 0x9747b28c
> +
> static bool init_stack_slab(void **prealloc)
> {
> if (!*prealloc)
> @@ -142,10 +150,6 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc)
> return stack;
> }
>
> -#define STACK_HASH_SIZE (1L << CONFIG_STACK_HASH_ORDER)
> -#define STACK_HASH_MASK (STACK_HASH_SIZE - 1)
> -#define STACK_HASH_SEED 0x9747b28c
> -
> static bool stack_depot_disable;
> static struct stack_record **stack_table;
>
> @@ -172,18 +176,28 @@ __ref int stack_depot_init(void)
>
> mutex_lock(&stack_depot_init_mutex);
> if (!stack_depot_disable && !stack_table) {
> - size_t size = (STACK_HASH_SIZE * sizeof(struct stack_record *));
> + size_t size = (stack_hash_size * sizeof(struct stack_record *));
> int i;
>
> if (slab_is_available()) {
> pr_info("Stack Depot allocating hash table with kvmalloc\n");
> stack_table = kvmalloc(size, GFP_KERNEL);
> + } else if (totalram_pages() > 0) {
> + /* Reduce size because vmalloc may be unavailable */
> + size = min(size, PAGE_SIZE << (MAX_ORDER - 1));
> + stack_hash_size = size / sizeof(struct stack_record *);
> +
> + pr_info("Stack Depot allocating hash table with __get_free_pages\n");
> + stack_table = (struct stack_record **)
> + __get_free_pages(GFP_KERNEL, get_order(size));
> } else {
> pr_info("Stack Depot allocating hash table with memblock_alloc\n");
> stack_table = memblock_alloc(size, SMP_CACHE_BYTES);
> }
> +
> if (stack_table) {
> - for (i = 0; i < STACK_HASH_SIZE; i++)
> + pr_info("Stack Depot hash table size=%u\n", stack_hash_size);
> + for (i = 0; i < stack_hash_size; i++)
> stack_table[i] = NULL;
> } else {
> pr_err("Stack Depot hash table allocation failed, disabling\n");
> @@ -363,7 +377,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries,
> goto fast_exit;
>
> hash = hash_stack(entries, nr_entries);
> - bucket = &stack_table[hash & STACK_HASH_MASK];
> + bucket = &stack_table[hash & stack_hash_mask()];
>
> /*
> * Fast path: look the stack trace up without locking.
> --
> 2.33.1
next prev parent reply other threads:[~2022-02-28 7:00 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 18:03 [PATCH 0/5] SLUB debugfs improvements based on stackdepot Vlastimil Babka
2022-02-25 18:03 ` [PATCH 1/5] mm/slub: move struct track init out of set_track() Vlastimil Babka
2022-02-26 10:41 ` Hyeonggon Yoo
2022-02-25 18:03 ` [PATCH 2/5] mm/slub: use stackdepot to save stack trace in objects Vlastimil Babka
2022-02-26 10:24 ` Hyeonggon Yoo
2022-02-28 18:44 ` Vlastimil Babka
2022-02-27 3:08 ` [PATCH] lib/stackdepot: Use page allocator if both slab and memblock is unavailable Hyeonggon Yoo
2022-02-27 5:06 ` kernel test robot
2022-02-27 9:23 ` [PATCH v2] " Hyeonggon Yoo
2022-02-27 10:00 ` [PATCH] " kernel test robot
2022-02-28 7:00 ` Marco Elver [this message]
2022-02-28 10:05 ` Hyeonggon Yoo
2022-02-28 10:50 ` Marco Elver
2022-02-28 11:48 ` Hyeonggon Yoo
2022-02-28 15:09 ` [PATCH] mm/slub: initialize stack depot in boot process Hyeonggon Yoo
2022-02-28 16:28 ` Marco Elver
2022-03-01 2:12 ` Hyeonggon Yoo
2022-03-01 0:28 ` Vlastimil Babka
2022-02-27 9:44 ` [PATCH 2/5] mm/slub: use stackdepot to save stack trace in objects Hyeonggon Yoo
2022-03-02 16:51 ` Vlastimil Babka
2022-03-02 17:22 ` Hyeonggon Yoo
2022-02-25 18:03 ` [PATCH 3/5] mm/slub: aggregate and print stack traces in debugfs files Vlastimil Babka
2022-02-27 0:18 ` Hyeonggon Yoo
2022-02-27 0:22 ` Hyeonggon Yoo
2022-02-25 18:03 ` [PATCH 4/5] mm/slub: sort debugfs output by frequency of stack traces Vlastimil Babka
2022-02-26 11:03 ` Hyeonggon Yoo
2022-02-25 18:03 ` [PATCH 5/5] slab, documentation: add description of debugfs files for SLUB caches Vlastimil Babka
2022-02-27 3:49 ` Hyeonggon Yoo
2022-03-02 16:31 ` Vlastimil Babka
2022-02-26 7:19 ` [PATCH 0/5] SLUB debugfs improvements based on stackdepot Hyeonggon Yoo
2022-02-28 19:10 ` Vlastimil Babka
2022-02-28 20:01 ` Mike Rapoport
2022-02-28 21:20 ` Hyeonggon Yoo
2022-02-28 23:38 ` Vlastimil Babka
2022-03-01 9:21 ` Mike Rapoport
2022-03-01 9:41 ` Vlastimil Babka
2022-03-01 14:52 ` Mike Rapoport
2022-02-28 21:27 ` Hyeonggon Yoo
2022-03-01 9:23 ` Mike Rapoport
2022-03-02 8:37 ` Mike Rapoport
2022-03-02 9:09 ` Vlastimil Babka
2022-03-02 12:30 ` Mike Rapoport
2022-03-02 17:02 ` Hyeonggon Yoo
2022-03-02 17:27 ` Marco Elver
2022-02-26 12:18 ` Hyeonggon Yoo
2022-03-04 17:25 ` Vlastimil Babka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANpmjNOyVTQZroOEVF_ZLASCtQ=SiC12WGWEwOib3vDk3sCbtw@mail.gmail.com' \
--to=elver@google.com \
--cc=42.hyeyoo@gmail.com \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=arnd@arndb.de \
--cc=cl@linux.com \
--cc=dvyukov@google.com \
--cc=edumazet@google.com \
--cc=faiyazm@codeaurora.org \
--cc=glittao@gmail.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=imran.f.khan@oracle.com \
--cc=jarkko@kernel.org \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mcroce@microsoft.com \
--cc=patches@lists.linux.dev \
--cc=penberg@kernel.org \
--cc=qiang.zhang@windriver.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox