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 BCAEFC433FE for ; Mon, 10 Oct 2022 08:57:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08B706B0071; Mon, 10 Oct 2022 04:57:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03A1C6B0073; Mon, 10 Oct 2022 04:57:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E1CE2900002; Mon, 10 Oct 2022 04:57:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C9A9B6B0071 for ; Mon, 10 Oct 2022 04:57:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A200C1A0CCB for ; Mon, 10 Oct 2022 08:57:40 +0000 (UTC) X-FDA: 80004436680.15.9B0A9C4 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf09.hostedemail.com (Postfix) with ESMTP id 09ACF14000B for ; Mon, 10 Oct 2022 08:57:39 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 33456218B5; Mon, 10 Oct 2022 08:57:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1665392258; h=from:from:reply-to: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; bh=/GJeMJcm8hXSrZyUxyPGtmH7w1EUbF6JJHgm6aL826Q=; b=XpVEPQNr4JpLchfnbWg/yC9QA8+wVWd8pRuDeCS9EIS4vwxsGXp45yDRs3cN0xs6YQZbE3 HOgHIIvtfTwMpoeb1MsKJHUsMcS3Gdj/j6L53VRpzHt7I9OJjU1a2vCiZpivNOpOiuOOOp oUoNGreoz47/JgubDCG976QTm6nSk9A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1665392258; h=from:from:reply-to: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; bh=/GJeMJcm8hXSrZyUxyPGtmH7w1EUbF6JJHgm6aL826Q=; b=2Jygt+R11U9FYm7wJOkr8oW8YTM2YBHqrLO246w8R0cYNWocaqBocj8qw88WOYjZb/wxIn KPVH8XeXJpbA33AQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E32B413479; Mon, 10 Oct 2022 08:57:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id C2doNoHeQ2OxfAAAMHmgww (envelope-from ); Mon, 10 Oct 2022 08:57:37 +0000 Message-ID: <5f7aafae-4761-3031-7a7d-963e813e73c3@suse.cz> Date: Mon, 10 Oct 2022 10:57:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH] mm: add stackdepot information on page->private for tracking To: Zhaoyang Huang Cc: "zhaoyang.huang" , Andrew Morton , Catalin Marinas , Matthew Wilcox , Marco Elver , Imran Khan , Dmitry Vyukov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, steve.kang@unisoc.com, Suren Baghdasaryan , Kent Overstreet References: <1665026390-16096-1-git-send-email-zhaoyang.huang@unisoc.com> Content-Language: en-US From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665392260; a=rsa-sha256; cv=none; b=CB9JQ6sUDLcfJloF7Z4nnJLQFdrUCpJbUuGmjidvfC6Ys623nAolBLI19eYMqSkTucVxcc FQA/9vfnB+a73OemqhqfShx1wYVDCynzp3dW4jebEHc07vUNwh2jrWCyzNGpoUb0Bw+3C/ s7Avyh/x+jXxxGmkK2/PGKQZfOHjm6U= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=XpVEPQNr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2Jygt+R1; dmarc=none; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665392260; 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=/GJeMJcm8hXSrZyUxyPGtmH7w1EUbF6JJHgm6aL826Q=; b=mKrT88JnEAljEFWQO+L9Pw97IiPMNoV4cTLFiOq2QL8U3LTCtDWMsEmWnbTbIreM65bwxd fWa31ddddzJj7sUx1fYgfUve1q9raiNadoGV0tB0MBQqzSUtRHkubPGVKyACi5AOZntKaV +WkRCCCAIYJSoKd6Vv2oJluWZXmodRU= X-Stat-Signature: 5zpxuo6z8ft117res15f6gen1j7qn1kj X-Rspamd-Queue-Id: 09ACF14000B Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=XpVEPQNr; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=2Jygt+R1; dmarc=none; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1665392259-579676 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: On 10/9/22 04:25, Zhaoyang Huang wrote: > On Fri, Oct 7, 2022 at 6:08 PM Vlastimil Babka wrote: >> >> On 10/6/22 05:19, zhaoyang.huang wrote: >> > From: Zhaoyang Huang >> > >> > Private is vacant for most of Non-LRU pages while the user has explicitly >> > operation on page->private via set_page_private, I would like introduce >> > stackdepot information on page->private for a simplified tracking mechanism >> > which could be help for kernel driver's memory leak. >> > >> > Signed-off-by: Zhaoyang Huang >> >> This duplicates the existing page_owner functionality in a way that >> unconditionally adds overhead to all kernels that have CONFIG_STACKDEPOT >> enabled build-time (and also misses the need to initialize stackdepot properly). > Sure. This patch could be deemed as a light and complement of the page > owner which depends on proc fs in lived system for showing the result. > This patch could be mainly helpful on RAM dump as it is hard to find > page_ext for page owners. I also would like to make this optional via > defconfig item. I'm still not convinced we need this, between existing page_owner and the proposed code tagging framework. https://lore.kernel.org/all/20220830214919.53220-1-surenb@google.com/ For finding page_ext in crash dumps, it's possible with a scriptable debugger like drgn or crash-python. >> >> Also wouldn't be suprised if some existing page->private users were actually >> confused by the field suddenly being non-zero without their own action. > IMO, the existing page->private users will cover this field directly > without distrubed by handle. Well the bot wasn't happy so far https://lore.kernel.org/all/202210072204.cfea59d3-oliver.sang@intel.com/ >> >> > --- >> > mm/page_alloc.c | 28 +++++++++++++++++++++++++++- >> > 1 file changed, 27 insertions(+), 1 deletion(-) >> > >> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c >> > index e5486d4..b79a503 100644 >> > --- a/mm/page_alloc.c >> > +++ b/mm/page_alloc.c >> > @@ -75,6 +75,7 @@ >> > #include >> > #include >> > #include >> > +#include >> > #include >> > #include >> > #include >> > @@ -2464,6 +2465,25 @@ static inline bool should_skip_init(gfp_t flags) >> > return (flags & __GFP_SKIP_ZERO); >> > } >> > >> > +#ifdef CONFIG_STACKDEPOT >> > +static noinline depot_stack_handle_t set_track_prepare(void) >> > +{ >> > + depot_stack_handle_t trace_handle; >> > + unsigned long entries[16]; >> > + unsigned int nr_entries; >> > + >> > + nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 3); >> > + trace_handle = stack_depot_save(entries, nr_entries, GFP_NOWAIT); >> > + >> > + return trace_handle; >> > +} >> > +#else >> > +static inline depot_stack_handle_t set_track_prepare(void) >> > +{ >> > + return 0; >> > +} >> > +#endif >> > + >> > inline void post_alloc_hook(struct page *page, unsigned int order, >> > gfp_t gfp_flags) >> > { >> > @@ -2471,8 +2491,14 @@ inline void post_alloc_hook(struct page *page, unsigned int order, >> > !should_skip_init(gfp_flags); >> > bool init_tags = init && (gfp_flags & __GFP_ZEROTAGS); >> > int i; >> > + depot_stack_handle_t stack_handle = set_track_prepare(); >> > >> > - set_page_private(page, 0); >> > + /* >> > + * Don't worry, user will cover private directly without checking >> > + * this field and has ability to trace the page. This also will not >> > + * affect expected state when freeing >> > + */ >> > + set_page_private(page, stack_handle); >> > set_page_refcounted(page); >> > >> > arch_alloc_page(page, order); >>