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 8077DC433F5 for ; Fri, 7 Oct 2022 10:08:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBF6D6B0074; Fri, 7 Oct 2022 06:08:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6F496B0075; Fri, 7 Oct 2022 06:08:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE8896B0078; Fri, 7 Oct 2022 06:08:57 -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 A7DA96B0074 for ; Fri, 7 Oct 2022 06:08:57 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 78252AB3EC for ; Fri, 7 Oct 2022 10:08:57 +0000 (UTC) X-FDA: 79993729914.09.EA1BE6F Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf01.hostedemail.com (Postfix) with ESMTP id CB53940025 for ; Fri, 7 Oct 2022 10:08:55 +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 45454218F8; Fri, 7 Oct 2022 10:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1665137334; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QCUtX+6Pp4BHdc+B7LF5dBVoNepGL493nNhdOWATKJA=; b=Oz1lqOvovtbmDHYNQxD/+K61Yr9/o3KejO6qDZ1dSCFg4dbsoJGuTB83E3FJLQ4svSP3YZ TwPhSnrp9eMo2hkEjHKWmdlpYap3RiZdfYjSr5xPosMGavstHiJ5a2FXCzjquvm+bZgeHQ T4xVT8WyCNjbeZOPjNXIWB6O5XenG08= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1665137334; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QCUtX+6Pp4BHdc+B7LF5dBVoNepGL493nNhdOWATKJA=; b=VX2fui18sfZZxAPBvRU5oeB4LaDciqC+et2vB4JNXDam0Zc65zkRGaw5OiyzeHPhQ8FM2W tSEXh7q4DIN4c8DA== 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 0C79013A9A; Fri, 7 Oct 2022 10:08:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id F19xArb6P2NkIwAAMHmgww (envelope-from ); Fri, 07 Oct 2022 10:08:54 +0000 Message-ID: Date: Fri, 7 Oct 2022 12:08:53 +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 Content-Language: en-US To: "zhaoyang.huang" , Andrew Morton , Catalin Marinas , Matthew Wilcox , Marco Elver , Imran Khan , Dmitry Vyukov , Zhaoyang Huang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com, steve.kang@unisoc.com References: <1665026390-16096-1-git-send-email-zhaoyang.huang@unisoc.com> From: Vlastimil Babka In-Reply-To: <1665026390-16096-1-git-send-email-zhaoyang.huang@unisoc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665137336; a=rsa-sha256; cv=none; b=SAJ6IsyjHkfpx3qIHaiknI2ZoLooDjnyXK1BVx9Lb75v93xpUlI4WjKsa0hji7Zb5Yz4C4 EsePrTYTOiB02f/+yfY6nh77kUd8TF1OmmrtXuNcVFqSKFMXWwUXDYanbj/wQ0WX3M+19z h+yx1IKi0ntxd8RoIJCTAREC6P5pFIg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Oz1lqOvo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=VX2fui18; dmarc=none; spf=pass (imf01.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=1665137336; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=QCUtX+6Pp4BHdc+B7LF5dBVoNepGL493nNhdOWATKJA=; b=OBjMNjszTX39iNB2Zzzh6WtbPve1LG/VGY61T6oIofJHGSy+S/Usps00XhKKLeVsIp+rWf vivZhr2EOWL1IJYrIwt1RC2oR/O7F9Dugq3YP5GoMTiStBJFKRbu2KclnDo4wm7hPeLNqL SQRcewilAWgcduSKg7N6gUck6wF+DnM= X-Stat-Signature: 3ayan53mcfe9w5hpokqjeex3ah7bh8oj X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CB53940025 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Oz1lqOvo; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=VX2fui18; dmarc=none; spf=pass (imf01.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-HE-Tag: 1665137335-401176 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/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). 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. > --- > 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);