From nobody Sun Dec 14 06:36:56 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 862C8C83F1A for ; Tue, 29 Aug 2023 17:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237649AbjH2RMK (ORCPT ); Tue, 29 Aug 2023 13:12:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237650AbjH2RLn (ORCPT ); Tue, 29 Aug 2023 13:11:43 -0400 Received: from out-253.mta1.migadu.com (out-253.mta1.migadu.com [95.215.58.253]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38954CCE for ; Tue, 29 Aug 2023 10:11:40 -0700 (PDT) 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=1693329098; 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=etRrGOIqY063bnkRK0UomaeBxyJpZf9uP5poWvb3gqc=; b=vWRwTzQB5vMYolMaxpPDvyneGGFmDZgws8+tFLq59cWPXaVn3GV0VaYcUF5RzitZxoe+T3 ZMExK1/RpceRrBL2M3n8y25ttAi3ULTCCP+y0Sbt1jt2hAnxV/2IzWEEpOegOi8gP9Lc6d hE8F8O5yYsTdFlsVFcDlLuY0x9gpyyU= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 05/15] stackdepot: use fixed-sized slots for stack records Date: Tue, 29 Aug 2023 19:11:15 +0200 Message-Id: <89c2f64120a7dd6b2255a9a281603359a50cf6f7.1693328501.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andrey Konovalov Instead of storing stack records in stack depot pools one right after another, use 32-frame-sized slots. This is preparatory patch for implementing the eviction of stack records from the stack depot. Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 2128108f2acb..93191ee70fc3 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -42,6 +42,7 @@ #define DEPOT_MAX_POOLS \ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) +#define DEPOT_STACK_MAX_FRAMES 32 =20 /* Compact structure that stores a reference to a stack. */ union handle_parts { @@ -58,9 +59,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[DEPOT_STACK_MAX_FRAMES]; /* Frames */ }; =20 +#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 =3D IS_ENABLED(C= ONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; @@ -258,9 +262,7 @@ static struct stack_record * depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **preal= loc) { struct stack_record *stack; - size_t required_size =3D struct_size(stack, entries, size); - - required_size =3D ALIGN(required_size, 1 << DEPOT_STACK_ALIGN); + size_t required_size =3D DEPOT_STACK_RECORD_SIZE; =20 /* Check if there is not enough space in the current pool. */ if (unlikely(pool_offset + required_size > DEPOT_POOL_SIZE)) { @@ -295,6 +297,10 @@ depot_alloc_stack(unsigned long *entries, int size, u3= 2 hash, void **prealloc) if (stack_pools[pool_index] =3D=3D NULL) return NULL; =20 + /* Limit number of saved frames to DEPOT_STACK_MAX_FRAMES. */ + if (size > DEPOT_STACK_MAX_FRAMES) + size =3D DEPOT_STACK_MAX_FRAMES; + /* Save the stack trace. */ stack =3D stack_pools[pool_index] + pool_offset; stack->hash =3D hash; --=20 2.25.1