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: 50467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390520wrn; Mon, 30 Jan 2023 12:52:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvznyuKN86c9l8j6K/uX5oMUa4TUGkYnbjB4hzItAV4klZnRNGjckWlwpekhZ14JZovyUaH X-Received: by 2002:a05:6402:e94:b0:47e:d7ea:d980 with SMTP id h20-20020a0564020e9400b0047ed7ead980mr55008553eda.14.1675111978296; Mon, 30 Jan 2023 12:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111978; cv=none; d=google.com; s=arc-20160816; b=XKMwtShUi4Me/aJZG7fONS9KtO6mIy/94TetfbTcy5w2JCopQ3W91KEe+WScZSgg2c shCOV4uVIPxUAyrAZEc62o1KnaB6vSGmQ6eud6b1cQJQBVwPAC/cuW4YK6P7FZvFrmsE qXbagqVA0kr5QFE9P9iZQKC6/NY3ThhxwDhu2YmSC2a5ZdziQKfUPAI7p6FIp5/luK7l uIvYBBUxr9D0c5kOMGlzKrBOdDmqLWrKG2NMHC8krSbkohGHDrG62mw2mpcA3EucKL+9 fnFgpECnYZRl2RTFkbDSt/Yhg8dLpvtc7eiobwaR07djwcAaHSZzcCLTeWXcztwrHuOV mEyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=Dw1b4SGmh8m42B7Ap5EI6ev0ut8EXxqQLQ4iRrabyaYGwG8sZXau4joNkjafsydeyG 9wElXNaj9U4xqsd0AP2hXImcjef+WtpQkhTDqiuPWgR8JCyCUXuuGPFzM4N6beDZwBjb F6rfGgYPg+sKqn0saLm7eFuvo9JrpsDhTjw6IpKFdkYC48V/H4jStY0xqurESSV2whU0 Y9ZmgpBX+aaQ5zob7Ga+FkcAtlRVNIDeWAgJwlYmM1r7V6wdmazhge74e92i+FXmf4yE 6LDOU4LgE+YNfhtXLG5yspxVv4OA1LPaeXOnwmgtQUtO2FJ3uhcuqgdwy89ecS2JdD0r Zgyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx5-20020a0564020b4500b0047ae036876fsi7555953edb.59.2023.01.30.12.52.35; Mon, 30 Jan 2023 12:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjA3UvI (ORCPT + 99 others); Mon, 30 Jan 2023 15:51:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbjA3Uu5 (ORCPT ); Mon, 30 Jan 2023 15:50:57 -0500 Received: from out-200.mta0.migadu.com (out-200.mta0.migadu.com [IPv6:2001:41d0:1004:224b::c8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03AEA10AA2 for ; Mon, 30 Jan 2023 12:50:55 -0800 (PST) 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482217962478879?= X-GMAIL-MSGID: =?utf-8?q?1756482217962478879?= 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) {