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 807D1C4828F for ; Fri, 9 Feb 2024 00:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F016F6B0071; Thu, 8 Feb 2024 19:28:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB1576B0072; Thu, 8 Feb 2024 19:28:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA1526B0074; Thu, 8 Feb 2024 19:28:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id CAD466B0071 for ; Thu, 8 Feb 2024 19:28:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 992C6A02BB for ; Fri, 9 Feb 2024 00:28:23 +0000 (UTC) X-FDA: 81770378886.15.E9D8EB5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id B92D5A0017 for ; Fri, 9 Feb 2024 00:28:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=FWJXAuSJ; dmarc=none; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707438500; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bLfd+V1tPZVOSY2cUl5n07cZFA949f5DwuJC/I/1MfI=; b=VBrELsd11KCxJpuULFqveWVh6nRkpugGgUMXUAJRxIjCvqumuWGCmtauSb0eQWtzJVUBJw 6ifi+jPktc3XVc1zFc5L8LfUVnkgqCo5rRpVQcy+JPpADSPaxKhzUIGvJWXiu4kK2MfB26 rTET4Hr45nq5Sp7UORsuUOVDYC0japc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=FWJXAuSJ; dmarc=none; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707438500; a=rsa-sha256; cv=none; b=wX84tMUUx7AMxxmjEOmUrkwKnGhU2DQcF6jV2G+tiOpRi/bK3UlW9FNvs+8kncB0+DzmzA aD4O6eNpagsxAfPXLWukdQzfGdVXeY+t34s0g2yWiT/umm51ImutqBvDchTdhozBQlJAvG bBa9mnlRLZ6Lq1V19KW2sAa9Pc34zDU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A3BB661F95; Fri, 9 Feb 2024 00:28:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CBB8C433C7; Fri, 9 Feb 2024 00:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1707438499; bh=11T3RfqVBk/00J32ASxKzhqAcS03aS5TfH8i2dHZWXg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FWJXAuSJWVE93DhOHvg+/cLaQAIitptg/4rNbc99uElVG5kHmZlZbuPuwENF7F+CO VvvzASS76WReP2nLQA1TE/1yLKePgkiUteXzC9sxCl4YjO26j7cDKUfcl41IOuxX0R CfYlvU6fLhBQKc7ag499ReV+f+m8VJzbSA8cViQc= Date: Thu, 8 Feb 2024 16:28:18 -0800 From: Andrew Morton To: Oscar Salvador Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Vlastimil Babka , Marco Elver , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH v7 0/4] page_owner: print stacks and their outstanding allocations Message-Id: <20240208162818.369c7abc3ecb06d49adaeebb@linux-foundation.org> In-Reply-To: <20240208234539.19113-1-osalvador@suse.de> References: <20240208234539.19113-1-osalvador@suse.de> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B92D5A0017 X-Stat-Signature: p41wi4jgwjbg9q8gzmp5irqbn5x8jyhd X-HE-Tag: 1707438500-910805 X-HE-Meta: U2FsdGVkX1/x8xDofVK1GJyt4MKLOXWo2wHUn3BvHRqWKY9ZZyOzc4UTDdG9EDiG2HbTGsnyPWM+VDgYkqMdPrgOnbIgFcHZMzd87GpuXQJUwWemlEKHXRmBaWBU78Hdds4PdxsuWvu9OxkgMEOeJuI92b8qAxvR09xazYx/3VDCbiGMA5wjDI2W7IkuKsOOhS0FUeKGUqj40FB2ahIgOjZ4BG61dn/FphuJRhltTwK4GrE/CFvMhnYbDxQ5z0DOAX3OUiT+xCU/uyihJ1P2O0At27aGwJTB2q6Q6u6BjQqG+KsjVSosAMFzGiCjpl0juOYFPyNgqceUtNbFqFEB6x3a4URJHfjaRMr6anRA0J2tamY46lMKqXInjsmip9M81dPHf4UZScRYKqzZ5mRjZQtDrIvxd7rOiNx+AvQV1GGL2mgUCb4JMCqKhLb82KcTHHOivOZWf7+O36KSg9AhUlL0+MfBREm107AeBtntfrT/ATjIZFZUu9cSkluW0QjF2+o3VIDp7xmGuWw50XlIIhs+L5qYpiY8bhn57yPTyeYj361TYlF3+YMTSE/MK0k32Pa0J0KmB72RVYUrGlu6AcShODNneTgAAbmQHSxCbaRQoZCASKhywN1PxPGT5Q3UDOT0CFYjGkA9OFU+j8k5tNjKBv4DiLdLFGTFHR93bFa3aDv5aOiiyID748PQ6NuYzwqAfiJ9K/EOfwWSONv3tbGVUpbogKyTPaBjDwUR1hYCZ8cFmFTx+vb0Tq35dq0y8BYdXQicP/Z8C5fwkiev8vlLGWd7wpeOjBsg2xeMOQ4BDrfyY1gVkVVh+8V4oeo0GlOJ0O9/9Q+mcZuLWAJb1uKXYWeC1DEFcPDBLC1EpSCPXcX6GoodjWh9krsgUvxvV3gcg0z7WwsBIrrZcmr50azGCnsRWkX9nE881/uO4Togd9o0EUAO3/AE2bx3jKiCVyKM7OwqCNMH+dbHMLq mMUzaTq4 etdN6YE346xNk8jdDMMxifj1CaOE4G5yO96oq8ZJjBNJdAkvnkmkSyQDo8xn2EuS3u7QXOac8SyFDAid4EqCqP5k06Geg+rFKZQX7q84TQ+THGYqnKfl/nwX96rQCUJcnSRUdeE7yo/GEKfLQMRdEs1oC35BrC4l9HEYYgPG5L88ZiVHUh8TzO3j94rcARuKdmUHQlAaez3g9NbWwpUArk1dHb0v43cWAtygIWxhSsFBjTa2MjDzwhQzxv/tNx5NsttsbpLDtWmvRQFHxL8lSn0lvsdu6q/rwTRi6f8DrxpjgQqA= 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 Fri, 9 Feb 2024 00:45:35 +0100 Oscar Salvador wrote: > page_owner is a great debug functionality tool that lets us know > about all pages that have been allocated/freed and their specific > stacktrace. > This comes very handy when debugging memory leaks, since with > some scripting we can see the outstanding allocations, which might point > to a memory leak. > > In my experience, that is one of the most useful cases, but it can get > really tedious to screen through all pages and try to reconstruct the > stack <-> allocated/freed relationship, becoming most of the time a > daunting and slow process when we have tons of allocation/free operations. > > This patchset aims to ease that by adding a new functionality into > page_owner. > This functionality creates a new read-only file called "page_owner_stacks", The full path would be appreciated. > which prints out all the stacks followed by their outstanding number > of allocations (being that the times the stacktrace has allocated > but not freed yet). > This gives us a clear and a quick overview of stacks <-> allocated/free. > > We take advantage of the new refcount_f field that stack_record struct > gained, and increment/decrement the stack refcount on every > __set_page_owner() (alloc operation) and __reset_page_owner (free operation) > call. > > Unfortunately, we cannot use the new stackdepot api > STACK_DEPOT_FLAG_{GET,PUT} because it does not fulfill page_owner needs, > meaning we would have to special case things, at which point > makes more sense for page_owner to do its own {dec,inc}rementing > of the stacks. > E.g: Using STACK_DEPOT_FLAG_PUT, once the refcount reaches 0, > such stack gets evicted, so page_owner would lose information. > > This patch also creates a new file called 'page_owner_threshold'. > By writing a value to it, the stacks which refcount is below such > value will be filtered out. > > In order to better exercise the path in stack_depot_get_next_stack(), > I artificially filled the buckets with more than one stack, making sure > I was getting all of then when reading from it. > > On a side note, stack_depot_get_next_stack() could be somehow reconstructed > to be in page_owner code, but we would have to move stack_table > into the header, so page_owner can access it. > I can do that if that's preferred, so stackdepot.c would not get "poluted". > > A PoC can be found below: > > # cat /sys/kernel/debug/page_owner_stacks > page_owner_full_stacks.txt Oh, there it is. I wonder why we didn't use /sys/kernel/mm/ Would a new /sys/kernel/debug/page_owner_something/ be a good idea? We might add more things later. Then it can be /sys/kernel/debug/page_owner_something/full_stacks. /sys/kernel/debug/page_owner/ would be nice, but it's too late for that. > Oscar Salvador (4): > lib/stackdepot: Move stack_record struct definition into the header > mm,page_owner: Implement the tracking of the stacks count > mm,page_owner: Display all stacks and their count > mm,page_owner: Filter out stacks by a threshold > > include/linux/stackdepot.h | 72 ++++++++++++++++++++ > lib/stackdepot.c | 97 ++++++++++++++------------ > mm/page_owner.c | 136 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 262 insertions(+), 43 deletions(-) Documentation/mm/page_owner.rst?