From patchwork Mon Jan 30 20:49:32 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: 13121817 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 98EB8C54EAA for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D02706B0072; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAF776B0073; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB8056B0078; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9DA296B0073 for ; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 77F60A0BC2 for ; Mon, 30 Jan 2023 20:50:55 +0000 (UTC) X-FDA: 80412659670.08.3EC7F96 Received: from out-77.mta0.migadu.com (out-77.mta0.migadu.com [91.218.175.77]) by imf13.hostedemail.com (Postfix) with ESMTP id AD70A20019 for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.77 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=1675111853; a=rsa-sha256; cv=none; b=bU3b2ypwHD4Wicdfa8MntAKPp4tUQMBLmJi8QRGxM0EqgMMFgZhCm4YD4o42ZsgaUZPtOP UjNHfjznteEsOzsd15vA4O3iujVcxLiBTR7WpLb95xHdWAHnCeFy9NNNUKnIhgC8oWE+Ac IH7hqLpkEfi68xDRjSPeehs5wP5hNr8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.77 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=1675111853; 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=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=AYsr8HLx/+I6lorzdmK+LDQEXWA3+mfZb56ZCE55FfzR7AGxWkPlKTIc7fBXZ7xJqUv374 oyT8eR67YG4AigRb5fZHdzaWVe5aqKscQKzJjRO3DD47LDQtryqO3w7sPAqtS13/7Xe2n2 ifnVTomD1loPux6H6foMxSa+oKLNfS0= 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=1675111852; 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=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=X7HUu+4VKFLQaJcV8B6kbT97Jm9iANg+sHOULAtlvOJSDASHctA+opcf+7oIrknNH8pARg ZnVh8nbjs5qes+RW9pvG2fcJuq86Fn6L9IoAgFzfLRdGB/OQfojrMtYNskx0G2E5v3XKHj VqRPxgIzxVdiKqMCcMhLKgpakaL0HPw= 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 08/18] lib/stackdepot: reorder and annotate global variables Date: Mon, 30 Jan 2023 21:49:32 +0100 Message-Id: <4ed1d0828e837e15566a7cfa7688a47006e3f4b3.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: AD70A20019 X-Rspamd-Server: rspam01 X-Stat-Signature: cnioc7u4qx71hjeciuuxhpqf9jydwd7w X-HE-Tag: 1675111853-178430 X-HE-Meta: U2FsdGVkX18+GAtutDkcZKOSW5R8bVgMNsH96YU/KM0wfoujhWy+5srLgLHRvvf1q3qOv46ckCFdIuKjHkWW35Cy89TfkFfHHa2tOLG2lVINd6nxVWP2zfUa2vQ0l7GF76RrapELlLX8k5uMCC48K0IlL5p5wyqvYzh32SV5pltTSLO5RNXtzMBsrSpQVyOXBrFlpDLT9CfgG1tk1O+y+D2sUuhMciqNyCJPEvyAiGrPH4qyKODPShcmuzVzrSJYgiTOi2sIQqLo2mdWpq+t5SnMa5I6hqlF76i3yemAvf77kZc7S2bYuBt1qDyEePp31dqIea5lS8eji059A8TCgdlqzPwGnSunhOxhO+5d4jk15aImuB1yHvK25Vb1SzBtLLW5Em5k0W1jr1TI781P4tjWiKXw23dXSx4nvD8cOvZTMOWwcC2nwMTZsUT3MKd8t8E1Y4cNFhz1x2rQs47kGMjjE1dZe5zhgFf8Rbo8iX6KlAD2xxZkDXK6Sb5zd4r8AoalK74Qk53aiP/al+DQBdfdIOVjXACp9zLEj1tHNXiWuHHUYkenrhShSxoHVOlpMtVkwkYyIyCIzymTVnOC/Ven0ctxmYoxI2+peF+jlZ99I1B7v1fqzqfj0e1wv+o3hxJDj7V2pa/RZN2KP/biOEhRWWTt8YuJcuLXuIKzy7iwoMNVDKirQlC7gzGqnE6fhIjVpc8PL63UBheG1hYALW9rg/CGcAU7ym7LMOOxIk1ZqazytWDF2eOleztob8+43Ml8WjMSHxjUVpeLgjatIkfWPPLZ9R2s+7ZIeItShr5q0GIa0w8w4cAsU+vIuw8xnI/Av0x9XKtYaWCvO0dVY9xhjjl9qBnXNrAQ5RkSqwyZhIlpeXqtkSNGSKitulNr4F+S+pVYLOH4kxYju8uAJuBU0nqob0/KoxZqfRqZOQR0yNq5Aw2XbmyeMFCI11VT7vpbHt31Zsp/cuUbQuN 6o3WBhGx IePwv4ULdGx4Dv7aX6SPg0NEPQvKMw/mbKEygmsE64fujy6S1RNOUcO5H6Ua+gpR2serX0cs/t6bwolRvRBHsyuEcXNCqGyE9iTUt 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 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) {