Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7601707rdb; Thu, 4 Jan 2024 01:26:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWazt6BzDdbCUIfpv1MTWd3ivFGVLADtGnVBvvwEuH7HuTB75qKsouiPebLizQpWK01Jpx X-Received: by 2002:a62:b619:0:b0:6da:b959:c9e with SMTP id j25-20020a62b619000000b006dab9590c9emr279745pff.29.1704360408896; Thu, 04 Jan 2024 01:26:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704360408; cv=none; d=google.com; s=arc-20160816; b=Jl0zFB4kmrBXrFsKdqmE3B6BOlMqafLHR1AJgFysQoLCF3qE9g90wkVfnsr3GMbUW4 cj3+mPk7YX/OH3VwHXL9h/GF1zgKtBP1sBu7qrJplO7QrCwxOXlq2f2EFbl2prGKhHwP e948p3las1rDPK0ZNE3ydG65lBLiIiKJyuUzfiGdks1s8MXeTMlTlgSvmejMdDAQlV+u 4RmI0/xCmidVN51PlKBdGidTsc2S218mrGKwjnKePErBdc/0Y7AZ8OEVFSHxTzFYYa9p Hvcm4tbQ0hZcFhSpBUOWBz3Xe4LBTflyjoiD1uLZKAvMDpFrpCq4hSN4oy7mu+C/LoFs soKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=JGeZ8w8hYuhNSoX/scf5I633EqoYMFGVRc1Mgn4PFeU=; fh=AnoIy5yXpmYRAA/ZJLVC0D5vdVMFCXYVFmK8go1Xijw=; b=tXi/NSnx7m3aAsyAu/+Pi3rIQdldUpbSlgObc2p+D/9HiIbg7CexGIAJs6dM51MY2M AOMYqRq0J1jOrP41sau56pR7HXNWH350GFuho4c/dQtexAzg6QcUybgZqEy8KzXALNfV G80SUDoX/DHiHsSNXlse3tWmf9DfsbG9sYOK61ihnFK8HWzTAbWO3d6Luq1w5aXjEMMx X0+FaA7XGKftdS0LvmC6n/RjVF9GAEHDB9SNuMqsvhzrWt/LSP+6IJ0TcyUY1xHBXq58 4O42PsxbNc+MDMrkFcyw4tnC8yMYOAftbP7a1gY8zktIaIfV5EStapOZxKFAyD4yzlA8 EG3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aL0mf8Do; spf=pass (google.com: domain of linux-kernel+bounces-16439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16439-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h33-20020a63f921000000b005cd8b9dc455si23156408pgi.567.2024.01.04.01.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:26:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aL0mf8Do; spf=pass (google.com: domain of linux-kernel+bounces-16439-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16439-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8DE94287642 for ; Thu, 4 Jan 2024 09:26:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02AAF2031E; Thu, 4 Jan 2024 09:26:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aL0mf8Do" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC28320B0D for ; Thu, 4 Jan 2024 09:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-4b731a13d76so96891e0c.1 for ; Thu, 04 Jan 2024 01:26:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704360378; x=1704965178; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=JGeZ8w8hYuhNSoX/scf5I633EqoYMFGVRc1Mgn4PFeU=; b=aL0mf8DocOo8DiTLd1kU3TzjxwJgscizrbdUy+eDnVra7DUKgRZiHvcOYpS3q8HA2S ajcKcPmjlUn6BJtS04JJ5LHqutXquysOgNyEK5RJt4I3VeqO7MUMVDnMmFM0H9U39nR3 qid3IpBf8dDI8juwcZy51YuHmc0H+4GNQvFxVVnj1muUan7KnvlJQ1xIREOMxKga5Yyl IEK6VmYx1hp3jxdw44Tl4sQjGIGfi+9q4n72lKFXwEseGgTpx05divGaEq2+9jOT74kf JRA24g+vpRcVAu9hmonk9836ozFcEyA7j/j0XU7KPrJpKal4cRHLi+13MfvOYVFIPc8f rfrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704360378; x=1704965178; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JGeZ8w8hYuhNSoX/scf5I633EqoYMFGVRc1Mgn4PFeU=; b=NEjDbZucRRXUwM0u6NVZY8rAA4p9gvuM2U7tFTWo/WYUdIS3oE7Md5r/HdPNCu6P3b tNNejL9J5mFGamh0+A7O+OhwxOVx9DyX13UdOp+lOsDflBCpuz2pHilmFc7S5CHyDUHe vxGUs/W/5E7sUfAytBFDseI2C+qpb1MeDqULQZK1MttByOCBuqZcGtwiNPhdcJo+Rnij 4PM5JUk/+0rRJHmKFr4Lj1/D3sf/HuQtQDrEeCbJM1hEGSBLEr01Lrc7JK647vycxT9J vkRGiJIYye/qQVebSGYmtNMMAytaCk+ahfygmD7aq5znBZH2IcM5Z2pmm9Zi7vZsjg4t SOOw== X-Gm-Message-State: AOJu0YwH0HdhG9LrYtUcah/0Yyq/nuSiIqNQTYSBKe7/SsZfVGJYVCEC K/V51LO3uRFzxUv5rdzB4qQoE7usMllIxtnqyK6C4YO0Ia3b X-Received: by 2002:a05:6122:45aa:b0:4b6:d5f1:7c8a with SMTP id de42-20020a05612245aa00b004b6d5f17c8amr245659vkb.4.1704360378266; Thu, 04 Jan 2024 01:26:18 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <1d1ad5692ee43d4fc2b3fd9d221331d30b36123f.1700502145.git.andreyknvl@google.com> In-Reply-To: From: Marco Elver Date: Thu, 4 Jan 2024 10:25:40 +0100 Message-ID: Subject: Re: [PATCH v4 17/22] lib/stackdepot: allow users to evict stack traces To: Oscar Salvador Cc: andrey.konovalov@linux.dev, Andrew Morton , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" On Thu, 4 Jan 2024 at 09:52, Oscar Salvador wrote: > > 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. I think a boolean makes the interface more confusing for everyone else. At that point stack_depot_put merely decrements the refcount and becomes a wrapper around refcount_dec, right? I think you want to expose the stack_record struct anyway for your series, so why not simply avoid calling stack_depot_put and decrement the refcount with your own helper (there needs to be a new stackdepot function to return a stack_record under the pool_rwlock held as reader). Also, you need to ensure noone else calls stack_depot_put on the stack traces you want to keep. If there is a risk someone else may call stack_depot_put on them, it obviously won't work (I think the only option then is to introduce a way to pin stacks). > 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