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 027B9ECAAD5 for ; Fri, 2 Sep 2022 19:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48F42800E4; Fri, 2 Sep 2022 15:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43ECA800DD; Fri, 2 Sep 2022 15:09:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32CFE800E4; Fri, 2 Sep 2022 15:09:05 -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 24312800DD for ; Fri, 2 Sep 2022 15:09:05 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F0E03808D0 for ; Fri, 2 Sep 2022 19:09:04 +0000 (UTC) X-FDA: 79868083008.21.C25F7AC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id C07E4120086 for ; Fri, 2 Sep 2022 19:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rt1IDSAN9BZj4OEF4fsbjLaelycXAqdJZzz/2U/Ag+w=; b=ESSENRcRRT17uYUWzdUXATM1ct L9Y6WhP9Yro8ie1M8YOVqJBE59nZSquxxxGMIvTCAy3zq8OWTZAiBOOY3ZYR5zoi6y1SXRD3aFk3e tlpdeQgK1xWwkXVogHH863mExAoCL12QWyb89/ytRuHPUBQdcG/qw2izLl73Kx7e0kmNMA/DpmXtm 2il6oiVaXffbeF8WEWfIvOBhSX7QAPD64dUsXlbwCM54e0mSpw9/rBmpEtiHX+nW0l3fRViUwR0iH /NYD5IxuDOno0d33/Cz7xlBS8v6qVLIkYWvDCJROj7RvmTNjGAkOm1/21XASJ88hN8gDCPot5a/Vq crbazAvg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oUC28-007HGB-Ak; Fri, 02 Sep 2022 19:08:52 +0000 Date: Fri, 2 Sep 2022 20:08:52 +0100 From: Matthew Wilcox To: Andrew Morton Cc: "zhaoyang.huang" , Catalin Marinas , Zhaoyang Huang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ke.wang@unisoc.com Subject: Re: [Resend RFC PATCH] mm: introduce __GFP_TRACKLEAK to track in-kernel allocation Message-ID: References: <1662116347-17649-1-git-send-email-zhaoyang.huang@unisoc.com> <20220902115839.1e3fafd159e42d4e7dae90af@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220902115839.1e3fafd159e42d4e7dae90af@linux-foundation.org> ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662145744; 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=rt1IDSAN9BZj4OEF4fsbjLaelycXAqdJZzz/2U/Ag+w=; b=s8IeEmCiGZoUxtSxMrZFvhVlfwMVq1fsAl4S9rePUVNrP23yY98VlpOEUXQx9I8JSyXNeE 6BturozWDT7/FzlLLG3Qk+Fu7Gs9w+j8bUcJzw+kteEmI4Wl61wT9GnS0Hh9ft6xboVRfF 6+X79zyMdgd5VOz4wd+PsnWE/oJzKAs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ESSENRcR; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662145744; a=rsa-sha256; cv=none; b=K1Qt+Sf/w63UTyng1bljxhC/kD6IDGf7VcE8JbpZB9ZCGRD6v/f1Hm5HyXe6gYXg0zpO7P MIX4HYuXzCtSsszJ3CXFiqQjer00u3u1rldSp8SR/7RkrXOD1XnNdVd3HogqPvds7h6ZkC djPgf2BTwGAiCeTLgUzcHQQonnkTFzc= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C07E4120086 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ESSENRcR; dmarc=none; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Rspam-User: X-Stat-Signature: ijpwqsomuy46684p9xc4xy758xjquh37 X-HE-Tag: 1662145743-665540 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, Sep 02, 2022 at 11:58:39AM -0700, Andrew Morton wrote: > Cc willy for page-flags changes. Thanks. This is probably OK. The biggest problem is that it won't work for drivers which allocate memory and then map it to userspace. If they try, they'll get a nice splat, but it may limit the usefulness of this option. We should probably document that limitation in this patch. > On Fri, 2 Sep 2022 18:59:07 +0800 "zhaoyang.huang" wrote: > > +++ b/mm/page_alloc.c > > @@ -1361,6 +1361,8 @@ static __always_inline bool free_pages_prepare(struct page *page, > > page->mapping = NULL; > > if (memcg_kmem_enabled() && PageMemcgKmem(page)) > > __memcg_kmem_uncharge_page(page, order); > > + if (PageTrackleak(page)) > > + kmemleak_free(page); Don't we also need to __ClearPageTrackleak()? > > + if (gfp & __GFP_TRACKLEAK) { > > And we'd want __GFP_TRACKLEAK to evaluate to zero at compile time if > CONFIG_HAVE_DEBUG_KMEMLEAK=n. > > > + kmemleak_alloc(page_address(page), PAGE_SIZE << order, 1, gfp & ~__GFP_TRACKLEAK); > > + __SetPageTrackleak(page); > > + } We only set this on the first page we allocate. I think there's a problem for multi-page, non-compound allocations, no? Particularly when you consider the problem fixed in e320d3012d25. I'm not opposed to this tracking, it just needs a bit more thought and awareness of some of the corner cases of the VM. A few test cases would be nice; they could demonstrate that this works for both compound and non-compound high-order allocations.