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 90879C47073 for ; Thu, 4 Jan 2024 08:52:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 075966B00CA; Thu, 4 Jan 2024 03:52:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F16856B03C0; Thu, 4 Jan 2024 03:52:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB6826B03C1; Thu, 4 Jan 2024 03:52:06 -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 CA1936B03BF for ; Thu, 4 Jan 2024 03:52:06 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 915B81A030D for ; Thu, 4 Jan 2024 08:52:06 +0000 (UTC) X-FDA: 81641011452.30.479B341 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf06.hostedemail.com (Postfix) with ESMTP id 3D5EA18001B for ; Thu, 4 Jan 2024 08:52:03 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="1TRI/m90"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CA1G1rqE; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="1TRI/m90"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CA1G1rqE; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704358324; 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=e2YJJ/wHF3T/z8OvARyhcqLm9IAHtRiaRn7YI2Y5QEw=; b=402Fjf9b22f+1bNZdU1R2TvRqw2dXc09UOXWVGn14Lek75i5oV7S3jel/j1r5CggOcekXW L4mxNbH5qTUAtFZ1Zqo4rGorKuDdCKkBAKcdbi8LBEBYK3BijwLgoPuXeFUa20C8HXbxFp kqpm4NxAfxPnWYZN8aanxeg5m1+AGS0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="1TRI/m90"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CA1G1rqE; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="1TRI/m90"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=CA1G1rqE; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf06.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704358324; a=rsa-sha256; cv=none; b=6Q2gnoI3Bb5rjAUaPW4WePL8z5q9mf7pUZajco4t6zBU1E3JKqCLBSwhR32d9WxRFyRJ3N R+uwZK2LN2Hq6iQQ1OHf6waBYrAxgz7kYQuVj/VbPAjSvhtRkSEFsc8qVVzvonsOVulIK/ g4sWTNW5S4RaoIHx3L2BoBmEeTrw0sM= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8DA501F7F6; Thu, 4 Jan 2024 08:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704358322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e2YJJ/wHF3T/z8OvARyhcqLm9IAHtRiaRn7YI2Y5QEw=; b=1TRI/m90ROrYdJZsQaXHP/1gHytvXKxr5PQ1CJXiURHxAO8NrbfjR7CklOn0hrg3bqLb8X rt3ZmF0KKMqv2cu84k5piyh/4xveQvGvXrXIhSeeLbepzLnH4GaRUE4P/egSyxTlaZIdhi aTM0Jdo/kZBKMF071V2MKSmEPFOfLtk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704358322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e2YJJ/wHF3T/z8OvARyhcqLm9IAHtRiaRn7YI2Y5QEw=; b=CA1G1rqEwBXCavUcVP9PAxQth9MeLV2sVC0gf84o8wAPJEQPnviR8yqy8tloJL3q6I91RW hGMlFYWSY9FJh8Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1704358322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e2YJJ/wHF3T/z8OvARyhcqLm9IAHtRiaRn7YI2Y5QEw=; b=1TRI/m90ROrYdJZsQaXHP/1gHytvXKxr5PQ1CJXiURHxAO8NrbfjR7CklOn0hrg3bqLb8X rt3ZmF0KKMqv2cu84k5piyh/4xveQvGvXrXIhSeeLbepzLnH4GaRUE4P/egSyxTlaZIdhi aTM0Jdo/kZBKMF071V2MKSmEPFOfLtk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1704358322; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=e2YJJ/wHF3T/z8OvARyhcqLm9IAHtRiaRn7YI2Y5QEw=; b=CA1G1rqEwBXCavUcVP9PAxQth9MeLV2sVC0gf84o8wAPJEQPnviR8yqy8tloJL3q6I91RW hGMlFYWSY9FJh8Bw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CF48913722; Thu, 4 Jan 2024 08:52:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QM5NL7FxlmW7VQAAD6G6ig (envelope-from ); Thu, 04 Jan 2024 08:52:01 +0000 Date: Thu, 4 Jan 2024 09:52:53 +0100 From: Oscar Salvador To: andrey.konovalov@linux.dev Cc: Andrew Morton , Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH v4 17/22] lib/stackdepot: allow users to evict stack traces Message-ID: References: <1d1ad5692ee43d4fc2b3fd9d221331d30b36123f.1700502145.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1d1ad5692ee43d4fc2b3fd9d221331d30b36123f.1700502145.git.andreyknvl@google.com> X-Rspamd-Queue-Id: 3D5EA18001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bei4rbfgogcwdm6cgyoniccoxnynqfoc X-HE-Tag: 1704358323-874708 X-HE-Meta: U2FsdGVkX1+vRUcRglD0fET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ulzK8aRsqXfYyjo2jO3ZkQfTrHMVmBlgTS4ucDOU8i9zdvrYippRFLMzDbueHehFdAtNcvSII6MF+jpjdZLrGv+MdOKonKFCelI4KkYkSeB/XQPQPw9H2rvzi0jvMO8YQG4prx8WBsxRcP4OIgRDleXPtXpTR+pAbwnkZ0H8KyMPC 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 Mon, Nov 20, 2023 at 06:47:15PM +0100, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > Add stack_depot_put, a function that decrements the reference counter > on a stack record and removes it from the stack depot once the counter > reaches 0. > > Internally, when removing a stack record, the function unlinks it from > the hash table bucket and returns to the freelist. > > With this change, the users of stack depot can call stack_depot_put > when keeping a stack trace in the stack depot is not needed anymore. > This allows avoiding polluting the stack depot with irrelevant stack > traces and thus have more space to store the relevant ones before the > stack depot reaches its capacity. > > Signed-off-by: Andrey Konovalov I yet have to review the final bits of this series, but I'd like to comment on something below > +void stack_depot_put(depot_stack_handle_t handle) > +{ > + struct stack_record *stack; > + unsigned long flags; > + > + if (!handle || stack_depot_disabled) > + return; > + > + write_lock_irqsave(&pool_rwlock, flags); > + > + stack = depot_fetch_stack(handle); > + if (WARN_ON(!stack)) > + goto out; > + > + if (refcount_dec_and_test(&stack->count)) { > + /* Unlink stack from the hash table. */ > + list_del(&stack->list); > + > + /* Free stack. */ > + depot_free_stack(stack); It would be great if stack_depot_put would also accept a boolean, which would determine whether we want to erase the stack or not. For the feature I'm working on page_ower [1], I need to keep track of how many times we allocated/freed from a certain path, which may expose a potential leak, and I was using the refcount to do that, but I don't want the record to be erased, because this new functionality won't be exclusive with the existing one. e.g: you can check /sys/kernel/debug/page_owner AND /sys/kernel/debug/page_owner_stacks So, while the new functionaliy won't care if a record has been erased, the old one will, so information will be lost. [1] https://patchwork.kernel.org/project/linux-mm/cover/20231120084300.4368-1-osalvador@suse.de/ -- Oscar Salvador SUSE Labs