Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp355833rwb; Wed, 5 Oct 2022 20:39:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7JPf+dPK2WtkkTsbPkriFWA6+jJq+emVneLB/0tKdBE23Iu3h/1/MiEBeVni7e5jG8+XfM X-Received: by 2002:a17:903:32ca:b0:178:29e4:15b6 with SMTP id i10-20020a17090332ca00b0017829e415b6mr2724378plr.77.1665027551685; Wed, 05 Oct 2022 20:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665027551; cv=none; d=google.com; s=arc-20160816; b=U9Br/T3yjkvajVJSIwK4uKS42qKWLZnnvV8zGdjlhnArlqBOqf4oDcr6xHTyqoUoDp JXZHM3ZeRAQlS7EZfAICkdRrZbEZYMdKD+z+2/cw5dsk7W5PTukJ/t9aMg3U2jptiPP8 0PMEGs/Ih53bupyidGuw9shLV/I8WbL76YFmYPcbGsrcprAyXLaFbDKYMa8V2fjUAx0q Ao71o4VYHvziA3pSr2bjkC98wYQlzvSRgWzVJ7j09FohI8Yum8G368UZz/OR55XeNxEp fprrIyOZSdlHGssBgedcvK3iU94QCZVqnx2NvGyqhE7o0GwF3h4WMk0nQulZKo6+3m2a 1pwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:to:from; bh=WLxUHBXubI6bJrCZ3mQyZGxqo8q4Q9eCafBnxtT4+P8=; b=KzXsAgNsDdcRdi7FKkBxWXiN+rwZkzMkeVLwQACqp6eP8IWFdXpN5YBYUQ8rLvae7V sQFyGgCNQ9uExkoIDkolBGDeyGenxU7mvX+ZJbK0j25XEjRLcFduphmGn3feQhB7rmAr 4ugpxEZFzIr0pzJ5zUOWESPGjtHXlt9zQ4WI9e7rrtZIExNTuqoQA9ICk00L65M9ZP+Y Mquc96u6jOjL01iHBX/rRIZhyyqzZXLhTC0ra+CYaIb5ZGY4BEI7HRsEToz4UAN2gkGf VKrepyu+1Vf17ovP89BAhnafKo/2Lz3rkU/rO7z/8a050VrxeD5BZlPC5CvtC+a1Um11 3tvw== ARC-Authentication-Results: i=1; mx.google.com; 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 o7-20020a170902bcc700b00174fd2df917si16777963pls.101.2022.10.05.20.38.58; Wed, 05 Oct 2022 20:39:11 -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; 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 S230142AbiJFDWL (ORCPT + 99 others); Wed, 5 Oct 2022 23:22:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230203AbiJFDVF (ORCPT ); Wed, 5 Oct 2022 23:21:05 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9C2C88DCB for ; Wed, 5 Oct 2022 20:20:18 -0700 (PDT) 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 Content-Type: text/plain 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 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); -- 1.9.1