From patchwork Tue Aug 29 17:11:15 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: 13369233 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 195D3C83F12 for ; Tue, 29 Aug 2023 17:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC7CD8E0031; Tue, 29 Aug 2023 13:11:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D768E8E002F; Tue, 29 Aug 2023 13:11:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3E6D8E0031; Tue, 29 Aug 2023 13:11:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A9F868E002F for ; Tue, 29 Aug 2023 13:11:41 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7D2FB801E1 for ; Tue, 29 Aug 2023 17:11:41 +0000 (UTC) X-FDA: 81177784002.16.DFE7FBC Received: from out-253.mta1.migadu.com (out-253.mta1.migadu.com [95.215.58.253]) by imf27.hostedemail.com (Postfix) with ESMTP id CA2F440020 for ; Tue, 29 Aug 2023 17:11:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vWRwTzQB; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.253 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=1693329100; 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=etRrGOIqY063bnkRK0UomaeBxyJpZf9uP5poWvb3gqc=; b=uchqxte+6iEk0GoLxehLcqTyeN/Gs5Lmj3STQGaRwkdqKWI/fWNWsmTt4iUAkWm7D+VeX9 A3dstMZ/6amKVozQy1L9xzvrlSSShI4l7UyDeo7sNdOpjAJVKQ3phb1XY8uKgiVt7Pzkkk hjJ98xK8DePZj+TbeWDM76hNzeo5zXY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=vWRwTzQB; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.253 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693329100; a=rsa-sha256; cv=none; b=C3o1+6mWEHH6b24xI0QoaLUDag3b7T0jGxFyLnt85qFJ+i6cjJ9XUascEaahpomnZ1twzh /MU89IYmCvb5b/1QNqV6RypPsqzcpUzTSS5Toor9GXPljuUdRWgsndMdTIZSjaeMB9jcDV BqFm0uh157nD0gZk/bQ2qqOxdrrJtp4= 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 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: CA2F440020 X-Rspam-User: X-Stat-Signature: 349qhifmubgpbpkanhwzezrngab45p6u X-Rspamd-Server: rspam01 X-HE-Tag: 1693329099-294711 X-HE-Meta: U2FsdGVkX1/P/JbTwauP3NvmmZNj1OWaD+AiZ0ObXMbUD0cGMTcYkLWiCi5gwpborZ5ifUo3KkmtaiFsA70OKEGhlL9Cq7wSDkXcBUJR1wCARjE9+pa2asagVSYtkpGNAzDFuAREWkr+G4bYuAkMDzhqjlv6cHkwpOknSFlO0lWFN8DnpjJ6okbisGja+iEDrmwaDE4o6i8OAo1/zEcw+tA3QdgnSP6EtzeM4uCQVsCS0YjYjut0Su1mDeCNaoWKtwo0EeabfV0hXKn+LvsL6r1SysVtvWWwTOJfO6AEVxZZrJ7uRyTo/wCBM1/gdcSXA/wg2aXebkKvQJ9TKexfDDlP1igd0z95sj5qS++7N3py0yYNnAPF3M1Gu4pZtUOdUdgDmPL3oiyuePWviSgtlzdHV2PF7fUJ48Paah2nuphHen7uRw8DJn3A5u8oG7oBATEUJAZJYTX0+5Y3e89+cwMd4EJ2Po2vOLdZaSsjlxIRGJ+mN70UJ1EcmHF7nAsmY7jzmZT5gpNNCClIr5zIbx5bC7xrfRL4TFtLGXC/47vCjwWDyyTnkYZfMd8/YQe1mZG3f3aPkuAbsNOE6rx3lN484kGKvdeG3QRt6bX+f9MPVuDzczXtvKZ7Z7hZ0zeu24auhe3GiHREQnQgFDK/GigkrJcx9xgICbJ37/ZVNr30sxQpjUtaJThd/spLpeZ2mU4QXhxzmUvmW4J9eFc0uc4kwIW3289SKugRcW5LVUp5G16CYbHJ0C4UyKaGf1Vp9vtqkJDFODK7Vw11ZF940nMbvhnZ2ECFR7QAIruZAJei7j/0xNh1l+HYLzi96rK7W2LvXuQp7++INmeNUxPtB+7eaj0PAhwh6CiB68aGkklvZyqWhgy8KI3imNUJlBguvoOJobedJeGhjeYXG1E7qhdvPZih8bgzc4rkrNrvzygrr+7VhK91hNILsQGVC9mLylFbz2DEkHA8/yxT0Is XVDTQtcF KQeEc1vWeNeZpvOlkMmTOrfjJqwel0iW9uQmNkCaU4JHUUishd1I405oXsWLmzq4+YMVT62LQQ4M8j9MRw3mGSkPvVbpCTBqWow1v 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 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 /* 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 */ }; +#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 +262,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 +297,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 DEPOT_STACK_MAX_FRAMES. */ + if (size > DEPOT_STACK_MAX_FRAMES) + size = DEPOT_STACK_MAX_FRAMES; + /* Save the stack trace. */ stack = stack_pools[pool_index] + pool_offset; stack->hash = hash;