From patchwork Mon Oct 23 16:22: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: 13433185 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 90C34C001E0 for ; Mon, 23 Oct 2023 16:23:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F876B00FA; Mon, 23 Oct 2023 12:23:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13FB06B00FD; Mon, 23 Oct 2023 12:23:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E09926B00FB; Mon, 23 Oct 2023 12:23:03 -0400 (EDT) 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 C080C6B00F9 for ; Mon, 23 Oct 2023 12:23:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 98FACC0878 for ; Mon, 23 Oct 2023 16:23:03 +0000 (UTC) X-FDA: 81377245446.20.CBACAC0 Received: from out-194.mta0.migadu.com (out-194.mta0.migadu.com [91.218.175.194]) by imf10.hostedemail.com (Postfix) with ESMTP id EB120C0004 for ; Mon, 23 Oct 2023 16:23:01 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rkq81ZIH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.194 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698078182; 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=bMe0IukHdtXUzp2BGVWle8stWPjWZ8/o4+6QYAoowVk=; b=V+k3DKDgXqAZNWNUPRLkWoBo8VKuWk50zLJHPS7NwaqpH25aC6yYiNaYv/YcgI9qY6pkXE OQdGAX3VgSy0hH+EMqeSmWMJXLJQYebn/MY/k95bbFui7cCdbfvhhjCXr995ZGINQ+bs8L YA/Owf9Pzg/fLjweSoTxbp16A7CRN/I= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rkq81ZIH; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.194 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698078182; a=rsa-sha256; cv=none; b=fU5Nm2YCLC4+9HQuQyz9i9150709ylYtvc4D561G09wwVEiR822icZJ62kcWNQ5YAPqTgr lEkmXwXO5a895huBYwKfKATu4clcYsqwdMDWnd5FMOmyPcu6T3QcnjmnJk39RgnMLz5a03 DhmjtUQz8yYeahiswtGm1J0s0be5NYs= 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=1698078180; 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=bMe0IukHdtXUzp2BGVWle8stWPjWZ8/o4+6QYAoowVk=; b=rkq81ZIHIptQkPMqAJh4zbGsz6Tf/Km8HtCA+J1L5FmEVUWRXZFPtR3mYiLwbXzLU1ve+m ipP9E4g9fFYH2AhD85YBltaGTWSFkAJKRvJkJTSAujCAdfb7pv+ffb4OXZf2EtpweYEmBM QWsHiUJVDHj2Hr+JhC9QlyMPSRnLRJ0= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v3 05/19] lib/stackdepot: use fixed-sized slots for stack records Date: Mon, 23 Oct 2023 18:22:36 +0200 Message-Id: <4340f57fa82fde81e00f64f98d69ee4a5d5ed9a8.1698077459.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: EB120C0004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6et3b7rcxnk3uq33zt77iyac89mb65sc X-HE-Tag: 1698078181-841708 X-HE-Meta: U2FsdGVkX18NUuwTnK4YcA0CHX+Mfq09kfebONvyBWlk46KcPmLNsSTtPH9/y7riKGRnpERDnpvLWYzCyigDqesbnWj/5N5J7ethy3U9sAOR8Mzue2oY/yRaxPlfrtAwm38LZ9UTsvaGS/yg7rD07+/hyS3GQGe96ULkTQ5Rp5+sRlEQFg8Tp09BaDtmbsrR86YD8VK9rHNMGH5wZUeQ+zUGrdme0T7hdvc61cq9MnKLp4ihNYiXbuGakh336n523JyW5fInejDdIzGHv5eS0ukZ6/VMFmirR4ogzC/u4bS3vmLBX8NkexKT5PMtMCl84LSAB/HDk6i7uCv85W8B42aK+LV+z5KxdeoXCopDlsht2MI6sVs8Ba+/XNUmiCYga9Tx+FO/Dzq9n8y12Iq1hYulopvbHROXxWZRqwlQHFhbpqBdqxjNH0k/xz23TIpCSf8k8vp2TCxJPgodi5VS2T1S9uTXoxhKokl5VF+ySBLS7oSovbxoDD3zehQ7b5yKLlJz5lNohaSDGo04OiFW51BzaCosfJYn6/qOOs9vuxaiprtyF98OVdXbbMEdyPM8gy2EIgMcuvYCPa1eYSQT72b0uSwJge2XuP4EhT8M7flsYgYqfeb49ZUquBBiqAFgb1ErvaeVwSp6bG9B5vOeU9jB2H3m/Bjmb8A3MvQPTWkj/i7FTeK43k8QJfTI2T7WC2pbHhAWc0o0mOsxD3DF00wwlAlE5EUcL21hzTi9cjKuLfU60IsGrRFUAbxlKzQTsKE5iQuNv89CNveVX997/gUKvG+qNRCHUN2OR2ABE70kccAODhzrt0euTKwI+kX0kIK+uSGVeoULdCCyBJO4v8Mw+9FXOLs/orNmf43Cm82bKLn4w+eXnrhGTInUuWiF/A6B2c5q1cTqeBJ9qSburZx9UFVggaK4lz8HcHLXBZBpQpYx6+4QVwqk8Ud3OdtrwpeZYpoKQJAflkffzJi qIt9casI RqU2FB2c/EzN8cPbEikUe9sIoJxjsWoCDEq3S+0qB8w3ZQYL3bRyatn/xdIZn7OmRfeIltRtFDmCYx7hnUYpTDiLbRXvmdeTJqLZR+tT8rh3LQ34= 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Instead of storing stack records in stack depot pools one right after another, use fixed-sized slots. Add a new Kconfig option STACKDEPOT_MAX_FRAMES that allows to select the size of the slot in frames. Use 64 as the default value, which is the maximum stack trace size both KASAN and KMSAN use right now. Also add descriptions for other stack depot Kconfig options. This is preparatory patch for implementing the eviction of stack records from the stack depot. Signed-off-by: Andrey Konovalov --- Changes v2->v3: - Keep previously existing Kconfig options not configurable by users. Changes v1->v2: - Add and use STACKDEPOT_MAX_FRAMES Kconfig option. --- lib/Kconfig | 10 ++++++++++ lib/stackdepot.c | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index c686f4adc124..5f3fa3659fa9 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -710,10 +710,20 @@ config ARCH_STACKWALK config STACKDEPOT bool select STACKTRACE + help + Stack depot: stack trace storage that avoids duplication config STACKDEPOT_ALWAYS_INIT bool select STACKDEPOT + help + Always initialize stack depot during early boot + +config STACKDEPOT_MAX_FRAMES + int "Maximum number of frames in trace saved in stack depot" + range 1 256 + default 64 + depends on STACKDEPOT config REF_TRACKER bool diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 9a004f15f59d..128ece21afe9 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -58,9 +58,12 @@ struct stack_record { u32 hash; /* Hash in the hash table */ u32 size; /* Number of stored frames */ union handle_parts handle; - unsigned long entries[]; /* Variable-sized array of frames */ + unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ }; +#define DEPOT_STACK_RECORD_SIZE \ + ALIGN(sizeof(struct stack_record), 1 << DEPOT_STACK_ALIGN) + 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; @@ -258,9 +261,7 @@ static struct stack_record * 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 << DEPOT_STACK_ALIGN); + size_t required_size = DEPOT_STACK_RECORD_SIZE; /* Check if there is not enough space in the current pool. */ if (unlikely(pool_offset + required_size > DEPOT_POOL_SIZE)) { @@ -295,6 +296,10 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) if (stack_pools[pool_index] == NULL) return NULL; + /* Limit number of saved frames to CONFIG_STACKDEPOT_MAX_FRAMES. */ + if (size > CONFIG_STACKDEPOT_MAX_FRAMES) + size = CONFIG_STACKDEPOT_MAX_FRAMES; + /* Save the stack trace. */ stack = stack_pools[pool_index] + pool_offset; stack->hash = hash;