From patchwork Fri Oct 7 01:52:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13000842 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 00E0AC433FE for ; Fri, 7 Oct 2022 01:53:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 124416B0072; Thu, 6 Oct 2022 21:53:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D3F76B0073; Thu, 6 Oct 2022 21:53:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDE768E0001; Thu, 6 Oct 2022 21:53:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DC1C26B0072 for ; Thu, 6 Oct 2022 21:53:38 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A4F8B160594 for ; Fri, 7 Oct 2022 01:53:38 +0000 (UTC) X-FDA: 79992481716.24.98D6C83 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf16.hostedemail.com (Postfix) with ESMTP id 7ABF8180011 for ; Fri, 7 Oct 2022 01:53:37 +0000 (UTC) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 2971r3ga065216 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Fri, 7 Oct 2022 09:53:03 +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; Fri, 7 Oct 2022 09:53:02 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Matthew Wilcox , Vlastimil Babka , Marco Elver , Imran Khan , Dmitry Vyukov , Zhaoyang Huang , , , , Subject: [Resend PATCH] mm: add stackdepot information on page->private for tracking Date: Fri, 7 Oct 2022 09:52:41 +0800 Message-ID: <1665107561-23030-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 2971r3ga065216 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665107618; a=rsa-sha256; cv=none; b=1Qev0BJHiToS5MJImJnZ/UQhckTdomffZFdZJt3pkbyXLmdLMzS7FkBma9/jiFrdIw09vU esS4Z0efLFSUUjDtpJUQF+bZfGoA4+27BdJmUy4Dep61FpRnugbYeTQ4+fHqTSPDstaGXc Yi4WNQ31GHruu5KjbtJD/iQEnLao2bk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665107618; 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=Ji4aWmo5IPv7Ivrd/aYu/MSL+K/jK8MPiYLIcyFMjqQNaz+4OkW+u0R8vgXP3Mtt+IoiRL zbLLeAt4Be7VbkVpNoqULEKMWN3uuhla2XLnnqHrEqNT6xIYLvIKlcUXPvGWIhQH78Uwxy ikOfyRyv4aP5I0IpNEl9k7JRWq24jU8= X-Rspamd-Queue-Id: 7ABF8180011 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none X-Stat-Signature: fpcoc8xnuus5t6mu6dxbx7kmejtmtbna X-Rspamd-Server: rspam04 X-HE-Tag: 1665107617-46508 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);