From mboxrd@z Thu Jan 1 00:00:00 1970 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 11AD0C47DDF for ; Fri, 26 Jan 2024 14:08:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D4276B007D; Fri, 26 Jan 2024 09:08:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 583EB6B007E; Fri, 26 Jan 2024 09:08:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 425156B0081; Fri, 26 Jan 2024 09:08:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 332256B007D for ; Fri, 26 Jan 2024 09:08:18 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BFCCC1A0FA7 for ; Fri, 26 Jan 2024 14:08:17 +0000 (UTC) X-FDA: 81721641834.17.C0F5091 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by imf30.hostedemail.com (Postfix) with ESMTP id 1302580016 for ; Fri, 26 Jan 2024 14:08:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="fnQB/xVT"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of elver@google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=elver@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706278096; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/VI/OXzcFzlYXsdPLN9N03OpjAt6MEKivygrHh6SqEg=; b=xUoY2YYfcXD+CrAjhjJcYzZouRWOn5O++UHV+5gMZrFBkY60+TD6E/Fdmn7CcgcQwBDZyE mRhur/uZqEjIqEPvOTZjBCNTtmzrRQ20eox/cqx1bsSt0vdXos+v890ylsofaUZz2LNqef Knqss8Wm/7cRXz8m6e7L0WVo8fTAwn0= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="fnQB/xVT"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of elver@google.com designates 209.85.128.42 as permitted sender) smtp.mailfrom=elver@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706278096; a=rsa-sha256; cv=none; b=DeI0hqhJ4e5xIglj82IrXbSpoZ+dWLjIK19BEaIBH2qNh4is/c4xeWtLqugjkYzXXUZHl3 Xgrj/t5Ek33gIqsFsUKGYKw+ANnknmE3bpnIwXrhxGi2NUlnJPFJtrPUDXqZxYz+Ofq0cl AHatZcB0hckWnx5w8uXyojbTzr+Ru8c= Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-40ee705e9e3so3821375e9.1 for ; Fri, 26 Jan 2024 06:08:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706278094; x=1706882894; darn=kvack.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=/VI/OXzcFzlYXsdPLN9N03OpjAt6MEKivygrHh6SqEg=; b=fnQB/xVTrPyDVEtJ7tUeIWRaRQWoppnX6B4jsA7tLJbNiw0dfqoaFAcMIDT7sh9V5+ BPVl8GpKnhcLEchM0biMiS8lbLqnd6jFQJoTF7HDjZY0urm/+bd+iBJ3RB0UHUZCg9tM zN+Xs3EeZWqxWf/DMFtea+5TgevUvbNkypEz/b08kBT9GdoOpic0JZiqRLPNPHyT8VyT D3CsSqf8b7jrE4B5HlyX0g5EJuQmLkG7YuOovWRMwUYAYH6sMir4tvB2J+h3Kz3kN0iD xNuxxTXhCdgKgGDyBArQIpV2GoSDVnUf5uutopP1e5FMtTE/K0TR3753a5ySWayhLTB6 yrzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706278094; x=1706882894; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/VI/OXzcFzlYXsdPLN9N03OpjAt6MEKivygrHh6SqEg=; b=O52s3VKiMWzKAVZ123blTgdkNMHEx9OSh4N+qsk7yw4w5Wot0OnxaQBjAfaAYI92Rq Ogn3H99jTBv5i5EC3h9XTU2VliaxvDl7s0Q6X1HB+tqNq5HB6gH9iNU+8WgJYa6fUzSy GZFixBxrYyMBoLv8mQXJDaMsNo4U1ur08UNTMKhpWcRfqS0YNIM2IsffaQGLFTaY0YSg YPH2BLYCIaljYKurxSBq3n0UzD7ukjER3mG3KOmjpT97zJ7RxejuatkWAnzMPOmV4Mlj W6aGaXCb/tI4yjdOSGHVNRBYlQwR1ydXtdjLgkswCIGdwf2PqVgsyvBt8Lbz8GdSWnCT hCNQ== X-Gm-Message-State: AOJu0YwfEfkS3rDpBG7ULLftEIGev1LtKct7qqVDQeZKpBtPgle/B2w/ 2Db1V5lZL2hMnEQQh3/8iRTSa7pNwnooKIvGE/hnqfXphhdPEEMpvuKpNEbT6A== X-Google-Smtp-Source: AGHT+IEuIgVMUDoiT2x4vpiW9DICFBzG/KvTN8gQG9YPJHasf4Ybq4Sh2N8x29vJZwfDAMNF0phVGg== X-Received: by 2002:a05:600c:3421:b0:40e:c363:bc15 with SMTP id y33-20020a05600c342100b0040ec363bc15mr979356wmp.65.1706278094299; Fri, 26 Jan 2024 06:08:14 -0800 (PST) Received: from elver.google.com ([2a00:79e0:9c:201:3837:e733:e624:7fe2]) by smtp.gmail.com with ESMTPSA id k35-20020a05600c1ca300b0040e4ca7fcb4sm2013199wms.37.2024.01.26.06.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:08:13 -0800 (PST) Date: Fri, 26 Jan 2024 15:08:08 +0100 From: Marco Elver To: Andrey Konovalov Cc: Andrew Morton , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , Andrey Ryabinin , Vincenzo Frascino , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: Re: [PATCH 1/2] stackdepot: use variable size records for non-evictable entries Message-ID: References: <20240125094815.2041933-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) X-Rspamd-Queue-Id: 1302580016 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cqunsugh8j6jncy1wubtdds8sh1hha9a X-HE-Tag: 1706278095-756388 X-HE-Meta: U2FsdGVkX190Aw58UJauuGs78WtgM0VJCnPENHaomA2XA+uMoIBKfa1omOLRHRrY9Qx8X/c2cd88ewkaTGMEAyK7CC3QeirLELg1GzQ+KSu7275geO3pTeirCAslpg7H24BVKmLec1RhTdfO57ZhvYohQvtgzktPGXhxI8MX2Xy7kvfZuzQKa6EZfrq2QVMZTAzU6wPWazhPFNeotdns/TEYAaFQ29hfPUQzv/YtW0v03ACknWm521Cw+dcdSx64JGcgrwtvjiahoNEpeD6qZmZwksa9vfOJEUdpzVNAKS16C+5k2XMbgZlBFq77+3lmjJqipT7lLOFpPA4rNaC8CJL4l4g/A78EaafIPzvgYpa43gJv+9A0FQQffUkNOGav25hpcGxcye8QdQWc3Cruwts8/z8G7oIbeakq3LzCHWHaF/S5qQXNrV9JctlRceIV14XXZhHabP7l3NJuEf4/42xrIIjdTUG88s1r7TjNsMZL/rbeKdtr2nqGYT487YhTFZ9EPQ2EN+u1OYAVi0CrvECUToyyH23Upl1whIN5qiNQyhdTimzMWkEPr2AGAFta7uyD5bOKouE1m27oHYwBJQ2pT77TGZCzcFcEvJZAYCwoUfPhjR20plOO/P3WbkTDQZYg/lBGReTGzonp60O7WJukc2LKbd15++kewvOp2j4gr5aL8TBB7GdstEK8VSltuj1LCor6nhLhRMzZpg6L01qmO22y30z/eBE+ZD0J1dcZsoXIU/yJ7L9qm6zt8viml4HbLJ/gHP61/DkdGBcJOKcgrMdaO3K6Z2YrOfpWMcOiOOPfSswlXxQvQ1OHUu4lIEK8vaPDyuB3Y7FyCM0CkoFm8i2tNgw8vQxUc0feY6CsM8qlsHxoE9a4LmUQjydlzgN3hwubA4TijynlngTTrLVEaAYZ+bvh8EtLEHkBFNlnL1TnsfDEfFymWknrWmhocqzSRYpp0wdGh6Uo1RC hWmetJ7I T5v+ybeu1SzjR0h3/9csQPtRnFOsuoaZzQGCtW2XoHEd4bNG/FvkB0MF4PoA+40uy+Vc8zgm9NKJawX6o8pJV67/VJ3K46ZKejNBcDdf+0DPSAEuArlkzc9P/iJ04xMJKEQ+TYSenn+Mj6uDWRhNqyImTtw== 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: On Thu, Jan 25, 2024 at 11:35PM +0100, Andrey Konovalov wrote: [...] > I wonder if we should separate the stat counters for > evictable/non-evictable cases. For non-evictable, we could count the > amount of consumed memory. [...] > > We can also now drop the special case for DEPOT_POOLS_CAP for KMSAN. > > Otherwise, looks good to me. > > Reviewed-by: Andrey Konovalov > > Thank you for cleaning this up! Thanks - probably will add this change for v2: diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 1b0d948a053c..8f3b2c84ec2d 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -44,17 +44,7 @@ #define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) #define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_OFFSET_BITS - \ STACK_DEPOT_EXTRA_BITS) -#if IS_ENABLED(CONFIG_KMSAN) && CONFIG_STACKDEPOT_MAX_FRAMES >= 32 -/* - * KMSAN is frequently used in fuzzing scenarios and thus saves a lot of stack - * traces. As KMSAN does not support evicting stack traces from the stack - * depot, the stack depot capacity might be reached quickly with large stack - * records. Adjust the maximum number of stack depot pools for this case. - */ -#define DEPOT_POOLS_CAP (8192 * (CONFIG_STACKDEPOT_MAX_FRAMES / 16)) -#else #define DEPOT_POOLS_CAP 8192 -#endif #define DEPOT_MAX_POOLS \ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) @@ -128,18 +118,22 @@ static DEFINE_RAW_SPINLOCK(pool_lock); /* Statistics counters for debugfs. */ enum depot_counter_id { - DEPOT_COUNTER_ALLOCS, - DEPOT_COUNTER_FREES, - DEPOT_COUNTER_INUSE, + DEPOT_COUNTER_REFD_ALLOCS, + DEPOT_COUNTER_REFD_FREES, + DEPOT_COUNTER_REFD_INUSE, DEPOT_COUNTER_FREELIST_SIZE, + DEPOT_COUNTER_PERSIST_COUNT, + DEPOT_COUNTER_PERSIST_BYTES, DEPOT_COUNTER_COUNT, }; static long counters[DEPOT_COUNTER_COUNT]; static const char *const counter_names[] = { - [DEPOT_COUNTER_ALLOCS] = "allocations", - [DEPOT_COUNTER_FREES] = "frees", - [DEPOT_COUNTER_INUSE] = "in_use", + [DEPOT_COUNTER_REFD_ALLOCS] = "refcounted_allocations", + [DEPOT_COUNTER_REFD_FREES] = "refcounted_frees", + [DEPOT_COUNTER_REFD_INUSE] = "refcounted_in_use", [DEPOT_COUNTER_FREELIST_SIZE] = "freelist_size", + [DEPOT_COUNTER_PERSIST_COUNT] = "persistent_count", + [DEPOT_COUNTER_PERSIST_BYTES] = "persistent_bytes", }; static_assert(ARRAY_SIZE(counter_names) == DEPOT_COUNTER_COUNT); @@ -388,7 +382,7 @@ static struct stack_record *depot_pop_free_pool(void **prealloc, size_t size) return stack; } -/* Try to find next free usable entry. */ +/* Try to find next free usable entry from the freelist. */ static struct stack_record *depot_pop_free(void) { struct stack_record *stack; @@ -466,9 +460,13 @@ depot_alloc_stack(unsigned long *entries, int nr_entries, u32 hash, depot_flags_ if (flags & STACK_DEPOT_FLAG_GET) { refcount_set(&stack->count, 1); + counters[DEPOT_COUNTER_REFD_ALLOCS]++; + counters[DEPOT_COUNTER_REFD_INUSE]++; } else { /* Warn on attempts to switch to refcounting this entry. */ refcount_set(&stack->count, REFCOUNT_SATURATED); + counters[DEPOT_COUNTER_PERSIST_COUNT]++; + counters[DEPOT_COUNTER_PERSIST_BYTES] += record_size; } /* @@ -477,8 +475,6 @@ depot_alloc_stack(unsigned long *entries, int nr_entries, u32 hash, depot_flags_ */ kmsan_unpoison_memory(stack, record_size); - counters[DEPOT_COUNTER_ALLOCS]++; - counters[DEPOT_COUNTER_INUSE]++; return stack; } @@ -546,8 +542,8 @@ static void depot_free_stack(struct stack_record *stack) list_add_tail(&stack->free_list, &free_stacks); counters[DEPOT_COUNTER_FREELIST_SIZE]++; - counters[DEPOT_COUNTER_FREES]++; - counters[DEPOT_COUNTER_INUSE]--; + counters[DEPOT_COUNTER_REFD_FREES]++; + counters[DEPOT_COUNTER_REFD_INUSE]--; printk_deferred_exit(); raw_spin_unlock_irqrestore(&pool_lock, flags);