From patchwork Thu Oct 6 03:19:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 12999897 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 4C363C4332F for ; Thu, 6 Oct 2022 03:21:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87B426B0071; Wed, 5 Oct 2022 23:21:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 835AD6B0073; Wed, 5 Oct 2022 23:21:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CB8E8E0001; Wed, 5 Oct 2022 23:21:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5B6626B0071 for ; Wed, 5 Oct 2022 23:21:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2BC4A402C1 for ; Thu, 6 Oct 2022 03:21:56 +0000 (UTC) X-FDA: 79989075432.03.A97038F Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf19.hostedemail.com (Postfix) with ESMTP id C524A1A001B for ; Thu, 6 Oct 2022 03:21:54 +0000 (UTC) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 2963KCDm058218 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Thu, 6 Oct 2022 11:20:12 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 6 Oct 2022 11:20:11 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Matthew Wilcox , Vlastimil Babka , Marco Elver , Imran Khan , Dmitry Vyukov , Zhaoyang Huang , , , , Subject: [PATCH] mm: add stackdepot information on page->private for tracking Date: Thu, 6 Oct 2022 11:19:50 +0800 Message-ID: <1665026390-16096-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 2963KCDm058218 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665026515; 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:in-reply-to: references; bh=WLxUHBXubI6bJrCZ3mQyZGxqo8q4Q9eCafBnxtT4+P8=; b=momyveNBtj7jChfNhgSejQHaSu3nDvUcbinu8sWSKwx3B4tbvOpK8B6mUD8JJY8Y5KJo7W GH0MnAB280mhkqTdhhv+8hBcoO+pfXFOSrwqm8TiSEm4ZnOmlaat3hq2Ouyt4VK0LN2GDY PIZ2Hpesp0C74qwTXuFuwkfOB9k4rR8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665026515; a=rsa-sha256; cv=none; b=zNQkE8/Fxt9JiQ7qLkMU/ArqP51lqG4lSpABifoinpw8Hnpv0WPJl+jNYmWC7+DCRFYNG3 K86EVzvEHuylxPdKHVuF+R1k1JPpvoRA9hjsv0eS8C2VjPSuqrfJnzFm+m4rc4cR3KE9ng 2UDFY3EpQuIb1K63XnvPensMv11lruM= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C524A1A001B X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com X-Stat-Signature: 9um31ow9qsb8uhuxx8q59ppzay7faxw8 X-HE-Tag: 1665026514-349672 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: 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 --- 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);