From patchwork Wed Sep 13 17:14:30 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: 13383618 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 E702EEE01F1 for ; Wed, 13 Sep 2023 17:15:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F7B16B0256; Wed, 13 Sep 2023 13:14:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00B106B0257; Wed, 13 Sep 2023 13:14:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D02356B0258; Wed, 13 Sep 2023 13:14:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B30126B0256 for ; Wed, 13 Sep 2023 13:14:54 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 837681A0ECF for ; Wed, 13 Sep 2023 17:14:54 +0000 (UTC) X-FDA: 81232224108.25.7CA4140 Received: from out-213.mta0.migadu.com (out-213.mta0.migadu.com [91.218.175.213]) by imf24.hostedemail.com (Postfix) with ESMTP id A4371180012 for ; Wed, 13 Sep 2023 17:14:52 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=S9us7jlk; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.213 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=1694625292; 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=gml8DcgHPrqnYJfUQnrXQLUWDOAsSsS+HJ/vnfgqmKg=; b=DPgYPLERUOc/FB4QcYtZMqCxtpIAiwozE/00p1Rk5ykuXLD+smwzZWXHVfQvb5sVhF5syd 331SEHRlH0OIczIuln3cGsFom/bsEiPq8MGXTsqW53hM/G4a+MRnhSu199dQZd1e3wDkYI xD2PsaWynrm2YaO7jNQv7X9UrsSAyfw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694625292; a=rsa-sha256; cv=none; b=JJjfSBrYKXXbujilwDdMz0rka+uKoeIeS5mmgBfBX63++Mc3+UN8fWZaY6R6ul/Wif9KOS cJGfVmsyur8+b6kRsLclFL8wBaDbRcw26+/wEQvSURxLeznS/kzdZ8KHnvKOs8ZNEBfvHx mdd6YFBiiNOVkZYoX54pgmtlO3OE4NY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=S9us7jlk; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.213 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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=1694625291; 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=gml8DcgHPrqnYJfUQnrXQLUWDOAsSsS+HJ/vnfgqmKg=; b=S9us7jlkKOCVp2Io5I0Tx7rlmHRdUo7dp4fSfiusTxeMqFjArjUdWXOxPxa7TRsS+UTSGt szqyWIxKS4Bt5+b4uJDHImZmEPS4RWHjhTLuJQarfEMznDy8FYztx69TSQNHWeON9BhC+T q2mjKPkhq8D4BrojemcgDiouTfk4yj8= 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 v2 05/19] lib/stackdepot: use fixed-sized slots for stack records Date: Wed, 13 Sep 2023 19:14:30 +0200 Message-Id: <658f5f34d4f94721844ad8ba41452d54b4f8ace5.1694625260.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: A4371180012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: s8g97wrdckzggou9z7zrk3mzcp3xiia5 X-HE-Tag: 1694625292-653536 X-HE-Meta: U2FsdGVkX1+kUNejxeJkoax9/E3AJA7FbJ2TQ+ewBrFSS3tmZKfFNyCmnTONPJc83O2OZTk0849FJyATckoNCPwD30flSLscl0dfFpEoOITakbT5l1CHN+4lJSeQjtJi3GF3E36dZO7M7eo/dvBIwKQLsASfcYyDotTbk74/0S1ZiNMDoXkXShvKDykj05XU6D5AX31Cl1Xs9em2GjM99Exo3s3Tf8G0leOKg6w9ndG60FKOitloYuV8zzgORmZj5wizu5QNDfCStqlD/TM81WS4qhIKcYveBhdRtimU8o9aEYRTdY79avFCvpR+V2bAynu/S//tpUfF/Lruf4VkJtO1uQO1pxkP4rr3BW/jxD2FxX5txenTa4wEo0qENfGmhs29YBXzCF6V6WRn5J3DvbHXT8XoGT41p5HPhrDd5KANDSACadQgPgMAvf6PlZaI9MBCXi0O6pH4fZpDtKfgvFqGcM1/D55SJXfvR/kBcx7B293qpxfTsexWk1jkQpsa7AgqEI2CjTMez0x9oosJN1mT2Xzlx8IGFqeKnAVQuI9/TWkUaHWWrixN29yinZqKu1qqXCi0dH3kQy+fKfEHKSeKwui7RXtxz3kPg0zYJJREdQU7YR3t3eqG3g+sP+O4or9nxXUO+p3OdafTVBUMCew9k8be3Tws9Go/VIlYIgZoJNcJnoUXTodcdc+E9Z8SfCAyudo2/yN9uVutmcgK+bGmls+dOunEXXUjbdmNMg1dZrSxeiwB97hbwzKABF0ZNainUxOPS4w+yeUzAC0syJ3z3rYsErDBhktnfDgZ8uxNWbfiEbft4qdCWAua8rdCsPS6w8pOAXEpY47pOxkFIGHSO8UnbijxaaoxuxmJpD5RVXBuNv1uxj9Qn8e3WAhhtd5VwpZ+apCeLtPthkITsRdDGJzo9HIJ4XmZFAZ0/hVNok/OIvTbEWjhZ4sydp6/wxIuv6mDoGI1EBH4gv7 YBUtRuuY TaT7ie69x+hQqB3GalAP/Cc++PdTO9FlssROB5LoyCGWeV0iOcsxH8DLuKghFR3xmwcJ6VKQ1yPnXGKMNiCp61kOshBAYqbBnyRsB 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 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 v1->v2: - Add and use STACKDEPOT_MAX_FRAMES Kconfig option. --- lib/Kconfig | 10 ++++++++-- lib/stackdepot.c | 13 +++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index c686f4adc124..7c32f424a6f3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -708,13 +708,19 @@ config ARCH_STACKWALK bool config STACKDEPOT - bool + bool "Stack depot: stack trace storage that avoids duplication" select STACKTRACE config STACKDEPOT_ALWAYS_INIT - bool + bool "Always initialize stack depot during early boot" select STACKDEPOT +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 depends on STACKTRACE_SUPPORT 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;