From patchwork Fri Feb 10 21:15:55 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: 13136458 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 D5FDAC6379F for ; Fri, 10 Feb 2023 21:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EBAC6B0190; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 574476B0191; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32FFA6B0193; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0F3856B0191 for ; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DFC1EA1180 for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) X-FDA: 80452642956.13.74E10A6 Received: from out-198.mta1.migadu.com (out-198.mta1.migadu.com [95.215.58.198]) by imf02.hostedemail.com (Postfix) with ESMTP id 2C17D8001E for ; Fri, 10 Feb 2023 21:17:15 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gCrR/J+B"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.198 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=1676063836; a=rsa-sha256; cv=none; b=3DC2kcmE2ers4E88MXkD9qH/VzSLEUOreaArXH8xXfpW7Km5mr7sL6IyFie6B22GJkz0cj feg2NaC43MhbjHiY5/f01AvMgQl0GXr6adGetxQCfHR0gF2U9rRIc0So4BWL2T2TuHtrnS szZ55EaS66CDFlqq7/4P7t9NHEPuTms= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gCrR/J+B"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.198 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=1676063836; 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=IMmtEbwX6SEFFs7KeDaMCDunDTh7JDSXGutwuFTHEE4=; b=bvmMwMoAyKwTwek6JtdKArCE0Iwp8UyAI6FWviKiprTwLEZ80u0pL/0MxeRKmOqTJfJVHa 9BINno1JjOC6iwOZflXKyCKVrZ/YKJmKSf9M95Dvhbf4WnMQyzrONnrNtgx46fQCv5OGfm bJQIim2hynrcM4DCBoFsimBkkJ7gBa4= 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=1676063834; 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=IMmtEbwX6SEFFs7KeDaMCDunDTh7JDSXGutwuFTHEE4=; b=gCrR/J+BL8uRipK+1P9oz0iyvJaqaAsbV6wrhymIwhr711MIK77R5Rm//kctV9oSok7pb7 peWTsywOV6H6eTgzHOJLcPPKMIOiPJt9TZzJeiLrcDJVV6iCUitSNz8en5c/vesUMIL5LW gej1rXj6zjHhtOWEii8sTUmmez6Agco= 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 v2 07/18] lib/stackdepot: reorder and annotate global variables Date: Fri, 10 Feb 2023 22:15:55 +0100 Message-Id: <5606a6c70659065a25bee59cd10e57fc60bb4110.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 2C17D8001E X-Rspamd-Server: rspam01 X-Stat-Signature: mrwkgyqzf9asetkxxehnctmm54qc9df5 X-HE-Tag: 1676063835-558619 X-HE-Meta: U2FsdGVkX19hhr3JGC/ZHMIPGqOK4Sxg0ptAi2y1VvCAsneO54W7+pzvsjJnrOdKp9eS8nQmwAybQYNhBVzvz9WQBrqnIzx3Akxj/YZtBIPQyXcRcW1lc0vRz/7k05FrlVuWGYjLUJwDGR6GM8vhaRi4ypTTlFyhs0xMz0wzuzzmc5N0bdFkhsqhqbusDRdCJpx30xxsp/KHEDy9Tfftygv+UQ1gAfQjXg5ovLPvM7jdrm9LyK5AuzM24AhMuQIgF/MK8QJrmRs8DD9Xc/rTXERtEVOcytLNdRNY4ZrToB91CO5u5d0kJGe5tRZSQXoObMQFG1WcSHV5XDpLS1UIKok8lS5eAN6cL1GbWf49CzzeCjJUfD6wkjpxK819SIxl/FpIh814NRPzY3B0Tqz4b7/cKDomCe10fmo3BvEvIKkNFFmLu5eGjYja3ebBu53xAJUw9+H6a09epSfEozXMIxBNEsA8AoG1rq82Z2K8iyzZFzDZm9Q7hR6xFPoMNm+H7Vkgt79Hvo1Sb09h/IrpXRM/6YJN/JvjMHPeVQiSZfPoMm6B51T7QFY4DFwBip3EyJbJ9dlCaGPHf/Uw60TeO9PbXYsBwuRb5avKYC4PE1LY0KOg9Z1XaAGfRyWw+FDnVZPLCwgc0yDluoNFqr5j8mgPCUPe7cQNxgI/jeiv9yWeVc1BLmlSQROEIcxe7PPEmrWGm/8BYZFGaF2yu/j2TIhzs0g/ep1B4qjqkAD/odlgx6zYWtxnXXJNVFbDLoein7jsD5DhqZVoPQd4MEQpAx9NPkLm0TqbC5dHfnbC6qiI0WYyMrUwbDReSnWbP6797OJfD8OC/w5q7eUTGjp0aMeRV0kiIh+Z++Wu6swihE9+miHUsJr9B20KeUEWyyeWGNlsudByDMPaUwnj0MBFPdckZdoQxwWnJZ2T6vDJy9thGPt6g4c0LMbwMZolN0by96fIqdOWMDYN3c0d6AD Pq+Hmpre GumQU3htt8OjBXVJGqRLXkSOhcKBpkqkCucnc7BhFcaAhWdZGakAL6Et6GO2CEK1N2WgdhGV1OvgoLLz77f9bm335IVkAvooAUmPpJUyAvhYw9aw= 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 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 Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 3c713f70b0a3..de1afe3fb24d 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) {