From patchwork Mon Jan 30 20:49:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13121823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A596EC636CD for ; Mon, 30 Jan 2023 20:51:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D6CD6B0071; Mon, 30 Jan 2023 15:51:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 387046B007B; Mon, 30 Jan 2023 15:51:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24EDE6B007D; Mon, 30 Jan 2023 15:51:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 15E5B6B0071 for ; Mon, 30 Jan 2023 15:51:58 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E32C81C6324 for ; Mon, 30 Jan 2023 20:51:57 +0000 (UTC) X-FDA: 80412662274.15.59937B8 Received: from out-111.mta0.migadu.com (out-111.mta0.migadu.com [91.218.175.111]) by imf10.hostedemail.com (Postfix) with ESMTP id 3540EC0014 for ; Mon, 30 Jan 2023 20:51:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.111 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z64aIL/3pnEFiG6bV8LdN1R6x92gKwWr8osFMwIva5I=; b=fZ/CstHNLfAw5R7a6LY7D4l3rE+Blpf4NYxTLHNWjy4ZADAavXQHHizqyy/cAu/dd+1Pmo rb92wxIW5j4/2pKUfu2ILmbxWwnOVEWYwpzzul1uC539iG+kzujYCcpbzBzb7xnZ2eSYND zwIzNGyPWcp6dXGgu0USzMUirOwyF3U= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.111 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111916; a=rsa-sha256; cv=none; b=1NggxT37I6XhYtKAspLJoSrjF7GNYEuIZCwZxZe9N+gRlmzz8bxN2A9YgYKFhZ8P7NxWSI CP96R1TkEwgTIkuue3p9p9LQSAgGumIZ+GQK5IRbhVhTWqpG14EN+Of4Z/FfbucZH395Xa qZo/2TuJtJPNFsOA0SlSI47SUkfxtyU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1675111914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z64aIL/3pnEFiG6bV8LdN1R6x92gKwWr8osFMwIva5I=; b=nfu6OwnDko1AKNqOQs12TRjWFH8CN3YRKYr2n98lnDMcdAtDTRf96kmqyCC0GgRU/w/evf HwHPm3R3lvim0v6dnV3z8SWxN4TpG9QvLzrWmN59lv13gbzTnZyVXd9w81iz5uKj4/obys 9aoIBAek+zEi9/NdwK4PCRLjc1Z/mw8= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 12/18] lib/stackdepot: rename handle and slab constants Date: Mon, 30 Jan 2023 21:49:36 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3540EC0014 X-Stat-Signature: gx7nrx7du3sgbno8pkgxc76w6piigmu6 X-Rspam-User: X-HE-Tag: 1675111915-453741 X-HE-Meta: U2FsdGVkX19S1h51eAUsMOHTWlJhmqexkIQRX3UOcIggL1YJS6Mp1yw6khWjiqug/ydVhn99bgudSlJoF85/KZpHf7KHq4cjy9BpNXG3FNZRVz8kmDD1OSLDH86kxOui+q1GpCn7CNV2mwUD9oFPajpzSm8+5PJeJTGfrueuYVm2KGUCPjcABLRsRSLE5YHf7ZIF7KdFwm1eVPdE1J1/+LIE+QbVUBLgMvMijY016Ct8y8McCnlwJnn0deObEI6e1rOQ6te2iGPJiOyE/Q6QnyZ/odyvunb4ct6Kv/CbDHv1Apo+oWMglj0TqvD8id2EMRFXbWN4pWesEjJis0RjhluUsOhmdMPgJsayMcN3X9xpixgSthKA04KwqE6ZVCUslFZnB3BGqGsD+pbdpdq0DGZgrtrL4bsZY0gwKlQrsnTZvYC4PeyaRPVlelvetqZbrj5yQQRmdRP6lD6EF2GwDGTg13g+ANjZ87VHJLXgBA2Opiek0DSp9lqkDtjjNTDxhCxHIn4JuO+WUyex+/cvwK9IM5JazWIfLBWb55rVrCjUdsmg0a5G892H/Rrp0TJkAscMVjroavBJwpaZzn8Ujc60B0dY0nwwruQK2iiYTVgVe48XnjMGqIvBtrvKIlf+Oy3Abcetp9jS69dn+nWGHzjlQTysMfzYEXIx6lv3rbteOqWc9LZ19o5qy6SbHfY5dtyEAA34lJ90Y4R+m0TcIxSPYtEck//yP/v/s675ioN88iXfBo+tjE/XoqBjP/Ox3JRbbZUsy0c5NqR9nqmK76t18uHfLySYa2TgyjUb3sjrHaseI+ZHtEL6aDse6p1ikl5Nc5iXS/u3osrm91gCJAp9zT94rABSspVrfIRn2HdxAvwpd3fszlsxu+eqMzl+FcZZVt3KXTVDWU2x68Xs6KJT0xFdllRnaP0Jk/+KyAwL4tBAvd/JIklSDUJt/5sc8lZQAy+8lwonQRrbl6E 1P6g+PT4 JgaF9L9sIoJijEiPoaoIFTieu+iYuziU+AQwbzU6yow8zwVhC44/swq2l/ojfhV9Lpjh290RwhvfQ98fFs4oZDA9ttg6HHcpaTliljtBoH00zNJQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Change the "STACK_ALLOC_" prefix to "DEPOT_" for the constants that define the number of bits in stack depot handles and the maximum number of slabs. The old prefix is unclear and makes wonder about how these constants are related to stack allocations. The new prefix is also shorter. Also simplify the comment for DEPOT_SLAB_ORDER. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 56 +++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 023f299bedf6..b946ba74fea0 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -36,30 +36,28 @@ #include #include -#define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) - -#define STACK_ALLOC_NULL_PROTECTION_BITS 1 -#define STACK_ALLOC_ORDER 2 /* 'Slab' size order for stack depot, 4 pages */ -#define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER)) -#define STACK_ALLOC_ALIGN 4 -#define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ - STACK_ALLOC_ALIGN) -#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ - STACK_ALLOC_NULL_PROTECTION_BITS - \ - STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) -#define STACK_ALLOC_SLABS_CAP 8192 -#define STACK_ALLOC_MAX_SLABS \ - (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ - (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP) +#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_VALID_BITS 1 +#define DEPOT_SLAB_ORDER 2 /* Slab size order, 4 pages */ +#define DEPOT_SLAB_SIZE (1LL << (PAGE_SHIFT + DEPOT_SLAB_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_SLAB_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_SLAB_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_VALID_BITS - \ + DEPOT_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) +#define DEPOT_SLABS_CAP 8192 +#define DEPOT_MAX_SLABS \ + (((1LL << (DEPOT_SLAB_INDEX_BITS)) < DEPOT_SLABS_CAP) ? \ + (1LL << (DEPOT_SLAB_INDEX_BITS)) : DEPOT_SLABS_CAP) /* The compact structure to store the reference to stacks. */ union handle_parts { depot_stack_handle_t handle; struct { - u32 slab_index : STACK_ALLOC_INDEX_BITS; - u32 offset : STACK_ALLOC_OFFSET_BITS; - u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; + u32 slab_index : DEPOT_SLAB_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 valid : DEPOT_VALID_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; }; }; @@ -91,7 +89,7 @@ static unsigned int stack_bucket_number_order; static unsigned int stack_hash_mask; /* Array of memory regions that store stack traces. */ -static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; +static void *stack_slabs[DEPOT_MAX_SLABS]; /* Currently used slab in stack_slabs. */ static int slab_index; /* Offset to the unused space in the currently used slab. */ @@ -235,7 +233,7 @@ static bool depot_init_slab(void **prealloc) *prealloc = NULL; } else { /* If this is the last depot slab, do not touch the next one. */ - if (slab_index + 1 < STACK_ALLOC_MAX_SLABS) { + if (slab_index + 1 < DEPOT_MAX_SLABS) { stack_slabs[slab_index + 1] = *prealloc; *prealloc = NULL; /* @@ -256,10 +254,10 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) struct stack_record *stack; size_t required_size = struct_size(stack, entries, size); - required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); + required_size = ALIGN(required_size, 1 << DEPOT_STACK_ALIGN); - if (unlikely(slab_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(slab_index + 1 >= STACK_ALLOC_MAX_SLABS)) { + if (unlikely(slab_offset + required_size > DEPOT_SLAB_SIZE)) { + if (unlikely(slab_index + 1 >= DEPOT_MAX_SLABS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } @@ -270,7 +268,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) * |next_slab_inited| in stack_depot_save() and * depot_init_slab(). */ - if (slab_index + 1 < STACK_ALLOC_MAX_SLABS) + if (slab_index + 1 < DEPOT_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } depot_init_slab(prealloc); @@ -282,7 +280,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) stack->hash = hash; stack->size = size; stack->handle.slab_index = slab_index; - stack->handle.offset = slab_offset >> STACK_ALLOC_ALIGN; + stack->handle.offset = slab_offset >> DEPOT_STACK_ALIGN; stack->handle.valid = 1; stack->handle.extra = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); @@ -413,7 +411,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, alloc_flags &= ~GFP_ZONEMASK; alloc_flags &= (GFP_ATOMIC | GFP_KERNEL); alloc_flags |= __GFP_NOWARN; - page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER); + page = alloc_pages(alloc_flags, DEPOT_SLAB_ORDER); if (page) prealloc = page_address(page); } @@ -445,7 +443,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, exit: if (prealloc) { /* Nobody used this memory, ok to free it. */ - free_pages((unsigned long)prealloc, STACK_ALLOC_ORDER); + free_pages((unsigned long)prealloc, DEPOT_SLAB_ORDER); } if (found) retval.handle = found->handle.handle; @@ -490,7 +488,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, { union handle_parts parts = { .handle = handle }; void *slab; - size_t offset = parts.offset << STACK_ALLOC_ALIGN; + size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; *entries = NULL;