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: 55590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1181591wrn; Fri, 10 Feb 2023 13:19:35 -0800 (PST) X-Google-Smtp-Source: AK7set83YES+mPZIShiGcRnm5xsfIQAnrmzOPwzVfpd6oaJpDSbg0l9cloIJq1RrkZtVOenmDlMy X-Received: by 2002:a17:906:4990:b0:888:497a:c51c with SMTP id p16-20020a170906499000b00888497ac51cmr16244762eju.12.1676063975426; Fri, 10 Feb 2023 13:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676063975; cv=none; d=google.com; s=arc-20160816; b=NFRFVtgttau050vZAuYhicv7qelJnDr6yIU+DTwQfDwJejg3EfJAFW8Q5vBIOc5q4S Q0Vk1BJ/qvX6yxWt3PHp9etRJHo+sAPVEuVeZCZWRPYzycBSEbrEfdAD2wBY6hyZLyUy LHykeoCSEioWwkQyB4SdJn4PZS9J4ffOzBsw1JFx219BCp0GANonGELId9Dyu5dq0RtQ kFquwlz7TIwkek7FrJdZDofhrUrQEh23422+4PJC3oTmqrwkQOfDs2d3v+VKGbprPjyv mqGvlh/t+1F7GKE05TXfZ8LMoXOf4XQVyk5WaQr6S+TmMfgllM2ZTdZSvzDGUkLevy5j iK7Q== 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=IMmtEbwX6SEFFs7KeDaMCDunDTh7JDSXGutwuFTHEE4=; b=VACjKkVjEMOLmXt4iOgGzqFdS6+uefArGhjzTwVClzNpwCL8T1yyMSj0aWq0Ani6q/ mONRqsHc0p/lXaCcntJvep4eQ2fNzEUa8eAbiDo/SWuqezQHPyVh6m7xPUMT/Fs2AF71 6ULyuwOV2y1RP2ClKB0fH2yl3LH94FGvrzP94phCPFy5De0zcHPULhSVqamFJrM7ws9g I4hE7uDQj7UvkaGYnKZSC3L3p40inAk+Z7/+GVK89F+tj9QCNSAyq849rmtYS610PTfd vpabPN+lKq4ZPYAv7FH1+C7erwKytA4QaeVALKTPEcaCsUo9Ufp4bgwEw52t8YBJeGyQ Lurg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="gCrR/J+B"; 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 mv15-20020a170907838f00b008787aa103d0si6219745ejc.270.2023.02.10.13.19.12; Fri, 10 Feb 2023 13:19:35 -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="gCrR/J+B"; 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 S233298AbjBJVRk (ORCPT + 99 others); Fri, 10 Feb 2023 16:17:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232871AbjBJVRf (ORCPT ); Fri, 10 Feb 2023 16:17:35 -0500 Received: from out-37.mta1.migadu.com (out-37.mta1.migadu.com [95.215.58.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF8926A72 for ; Fri, 10 Feb 2023 13:17:15 -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=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-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?1757480459001519104?= X-GMAIL-MSGID: =?utf-8?q?1757480459001519104?= 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) {