Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp417116rwi; Mon, 10 Oct 2022 02:12:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM692gUi4Xp241GCas7Ssrt5UaVxpcCRiNVrwRE04jioRE7K7C1bezz1Cw43ul3FUVeFYSe8 X-Received: by 2002:a17:907:75c1:b0:783:a093:2d34 with SMTP id jl1-20020a17090775c100b00783a0932d34mr13905521ejc.454.1665393158439; Mon, 10 Oct 2022 02:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665393158; cv=none; d=google.com; s=arc-20160816; b=pn7PHrjOyswc83oAlPgruATK4Yw9GN80awr8/gon2b3oiN8peA6kkdPTLYx6n45zVy m3LSXMX0r/HrAPeZoK8KMRQOszVbkmMbLRnlcmit4yIQMyCnFTRshOusfXcZrHF/ZoiZ /cfVTCZGYjJa4uyxZ1shwDcqzdquWeu7tGUWOUK1MeALl0dZxreG43SRdwZwJuMJ54I2 AVgz0RDbeBB02+ZolKC9Si/vSPr8fOE99d+CU7nQ198b6Yd5p+wkwVmSOBzkhK7EXrrq PNWKDOhfRjcKD57zLFB8mryWvHOaj1XEHrIN03ipBVYo8AAiwU32HK4SMp4fAJ5t4k9U sB3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=/GJeMJcm8hXSrZyUxyPGtmH7w1EUbF6JJHgm6aL826Q=; b=FaROSmwwkVEVDrpf62EPO/c0KetW7sInjmjJ+e2Anrxwk7n/u/iSZZH9sQ0BR97hHr hu0ccKuj1QQuKPzwobipbrXy3lofJ7nKM/5HIvToqzAE34fVBBzxLkrr2Dg5aLkYUchy JwE3YyPeTmLjx/N136xfg6vxYv+RfMLYLtglRDnIiGheDnm3QyakCoBGbvKEELU8RnuI u5f6tT4Tj8Np0klRNYPCHgbHMeQyaC3bUAckFC0YAf24RX1nRkLlisHJ/mI8Mp/u3SMs sLxJ+V6Fi74gE8p5jADezMfu2yRirlXbWPUr3eELyfY3+BD2kX/zs5DmCKYCuExt53EY wScw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=XpVEPQNr; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji9-20020a170907980900b0078d49f236d9si8856863ejc.48.2022.10.10.02.12.12; Mon, 10 Oct 2022 02:12:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=XpVEPQNr; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbiJJI5o (ORCPT + 99 others); Mon, 10 Oct 2022 04:57:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231534AbiJJI5l (ORCPT ); Mon, 10 Oct 2022 04:57:41 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 853A567161 for ; Mon, 10 Oct 2022 01:57:39 -0700 (PDT) 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 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); >>