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 04B0EC433FE for ; Sun, 9 Oct 2022 02:26:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 852036B0071; Sat, 8 Oct 2022 22:26:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 801CB6B0073; Sat, 8 Oct 2022 22:26:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C8766B0074; Sat, 8 Oct 2022 22:26:13 -0400 (EDT) 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 557A66B0071 for ; Sat, 8 Oct 2022 22:26:13 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2B85812075C for ; Sun, 9 Oct 2022 02:26:13 +0000 (UTC) X-FDA: 79999821426.10.61488C2 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by imf29.hostedemail.com (Postfix) with ESMTP id A4D9A120026 for ; Sun, 9 Oct 2022 02:26:12 +0000 (UTC) Received: by mail-lj1-f175.google.com with SMTP id f9so9747925ljk.12 for ; Sat, 08 Oct 2022 19:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=F4Ndqn8mcqwaJbQaI8C5dwRVGTyPE8l0jxeXirt3rHc=; b=GOy6ht1b3z6Nch5I+lxTYiokqV19xJ5XrFL7Mfhqc/yl19vQ+uscITbHA3XQblsySp iwA2YhzOQAM443abCWu7kffIfL9oJQJFlLtwFso0Hs9RqG7Rq3y3d4X2LYqQNB92WEhe Fm2Q431j5QjeI0SQ7tuxzeW0N+5CYFtpySDYq0UVWZuF5xF9qwdhmI6CCCJUMp2jNLYa fh2Ke5z4hPEIdsb6vZ0cCGDmFenxRxR0CXBXv5lZzJpWNdAp0B7y7wipEdth7p4wQbLh kXur6B5POLW2u/t+FCBQaexERlqfXNDiXwSUE8A+1wwgMJla3u3YCRDisz8kMWJCZoWh 9OQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=F4Ndqn8mcqwaJbQaI8C5dwRVGTyPE8l0jxeXirt3rHc=; b=0gucCjb8Qf64NDQPcWnZFuETTwu1QZFhgiD6y9vr8wi7P/dDP56+kBuJnY2gsis0pF GUZ4v1RAvNXS4ZBFUD4iUylrbZJXY1WFDSO1BwXblV2zcQebpIZaP8AIgwo6h70OaD0Z zIoszraVYnmgoLc6MGpjVV4D7t3LBC5bAf74JhBKD08sdV7Y4PtiSh1CmlRdcxV7s9wc dz3xnJ91BaD1yAKkObzHVAP9Y/tulXG5wwfJ6JAPdoZVXb/IEutqQ5gR6Iejd1799ew5 JsXfDDBiueglgUuqB8X4Zzkg2upXXlwg5MwVDW2Wv3C8xNUuNTi6D3LyDFv3nk8IFC1Q +Q9g== X-Gm-Message-State: ACrzQf0BexBfCmTpHHY6LjczDERb5gl9IloIaGiRopT/AYLra7WctJHz SBpmYZA+S9VsM+BVFlDLSffS58qaDI4dTzn/VBw= X-Google-Smtp-Source: AMsMyM6JjeD9ChTGv/mp2MLb0Cib5y9fxexHwwynGKJXjBwMxjRXk9IF2L+0HUCgRg66Bpy8msUBITmU63rSxRb6QvQ= X-Received: by 2002:a05:651c:222c:b0:26b:dec5:a4f0 with SMTP id y44-20020a05651c222c00b0026bdec5a4f0mr4652013ljq.359.1665282370836; Sat, 08 Oct 2022 19:26:10 -0700 (PDT) MIME-Version: 1.0 References: <1665026390-16096-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Sun, 9 Oct 2022 10:25:42 +0800 Message-ID: Subject: Re: [PATCH] mm: add stackdepot information on page->private for tracking To: Vlastimil Babka 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 Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665282372; a=rsa-sha256; cv=none; b=kOZNVZmR3wJP72AaILVnVoqt3H4zpRyUcNCNRrdypxSIA6yReTDCHnKdqoZITt0rRi3J8s Nmgsfh7IipHMLUEks4ueAAnwVBiZNHzWN7wGYVS12bluCCrcPZ3NbV/lxMJqKh3cQ9iDaG 3h8RxjbxZvEYGqPNa6ROj+VVlfLEwN4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GOy6ht1b; spf=pass (imf29.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665282372; 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=F4Ndqn8mcqwaJbQaI8C5dwRVGTyPE8l0jxeXirt3rHc=; b=5TU8Y+Whb0tyO+7hYw5MRPp6UemfddsIiACoWcVWuoabINonv14XQ+kYggkadD8FfWi5z0 3jh2u3Zae6yU6aJBEYfcwjeRfmR5JA43R2YpQagf+EhqcaAIyjitP/WSJqSkkjSGOIbq/5 dYi9Jo/QKQIK3g6XY9GNjPyKcJpADN0= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GOy6ht1b; spf=pass (imf29.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.208.175 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 76qa8ykn7j4s561in7g7dubhrxx41s6c X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A4D9A120026 X-Rspam-User: X-HE-Tag: 1665282372-185268 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 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. > > 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. > > > --- > > 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); >