Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3992677rwe; Tue, 30 Aug 2022 02:38:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4hM60FJfBRAEt1KTmQKPqAxRiyKVx7X0P9R8nr0pI822D2Tu7VA6nKtccz/Lfrxwsl+tiG X-Received: by 2002:a17:906:5a61:b0:741:78ac:851f with SMTP id my33-20020a1709065a6100b0074178ac851fmr7200840ejc.431.1661852284015; Tue, 30 Aug 2022 02:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661852284; cv=none; d=google.com; s=arc-20160816; b=tq/Pp8RlmDnqO0T1Nm5H5MFC+DuwD0G4BVCbxvTpIQqHLSYi2VrEehi/CK65uWaxf4 Czv6FKBeoyDR5vML1F9pEL6OE3aTsOmrq7twL+PsjTms7xd7u09D+DDyY19DXLbFB6DP UdxXt/3H26MK/5AHoOFt5cHkAN/iaNLlUEZKhmbZ1eYXM4/iX6xHW6klIjy65x8pIpaD PYYrkWc11/21DVYIL3Nvc2gSnkyUkwTOdVVpGdaw4D+Z9BlvXk3FbuRPj+Bx57m3meDV +Tqhe+kp5ZANYs2fbUpUsXt6AW20zre5C6+Hqb2rMHiHyPHMYLVQCciwpUvmQtQWg3U2 7r4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kguPy3wkAys/EGwS8Nyv4zZp1jqQK2hNEkzoKqRl47o=; b=MZtqvrLn6pit9pFO5jGUPtEbdCmIir1jTidFCpL0x/g/aLLNonuIrtj0dYW/VGLx3e OiQdSSuwf0xDZm35JWw/NiCdkgJ6wBoWx1tl1qNBcZPmUI8jXtJzoSLzscLNpsaNC1Zs f26ELWGLRwgWO8rzGJ4p1tOmBNBWXExMTZbRQEyLL6UjhQ3iY8QJBO/w9A8wqLf3OZ3N X80GRaOu6kxtiMm9pNTNrY6RkNsPJLS3q/9j+E9GfEP+iGPzzF5QD+EJv31IO3JfztUc TKrgZXBGFus3PclOR7p9bgGH/trNMxAs45NzLmzYfYqkx8qm4b4M8NljlA4mNgUc+FW3 jncg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TPRi+Mgk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg12-20020a170907970c00b007316ac034a1si3927531ejc.831.2022.08.30.02.37.38; Tue, 30 Aug 2022 02:38:04 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TPRi+Mgk; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231217AbiH3IxD (ORCPT + 99 others); Tue, 30 Aug 2022 04:53:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231354AbiH3Iwn (ORCPT ); Tue, 30 Aug 2022 04:52:43 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBC0863F0F for ; Tue, 30 Aug 2022 01:52:39 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id z25so14578016lfr.2 for ; Tue, 30 Aug 2022 01:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=kguPy3wkAys/EGwS8Nyv4zZp1jqQK2hNEkzoKqRl47o=; b=TPRi+MgkWEfe3wDbg7GpgpypRM62/orWgjZwhLwTwvxq1Q6qUQULhI+lr/OfIiCbig mVS9Wz9Z21/SKULBKaJmLRRZh1XMTJYc1nAdH1LRy8AWmR6QG0ORxf7wdw5IEunn3BhX lXrtUE8LW9tLPtehwHw6hyXxCkOFUgMDEmApEJ9rqt8W1LfE9pMO0vDJ5I/3GYX8vJNL GgXWZF55qFA4EUV4v3X1vfhDnRqw4gDDQUNQAMeqzsDwi6PNbVch6UVPrmQys4PTeDrA mfuLEm59fejkvqK8Bzu0nP3yayb2AKOK7GADH2GWhhkEsQ+0lfoCmAXDuWjig3ttKePR Ty2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=kguPy3wkAys/EGwS8Nyv4zZp1jqQK2hNEkzoKqRl47o=; b=wbLMjFXxZN4kap/cv9rWWutBesLVBvrF26ReVsAh9ngVb/J4KIjpe8I4xoE2YFiE4F ZkbcJu0rM7zXhXWRxxxg9+7Zvgt4li3EubtGWTL70wE3QnVI/LWW409+GLsudWaGw1En HCERx8K/C5Q8uWXSuDLgAeHbLhpiKeZaKQqm/QJMHSezm1ynYDuJo/IG4FHhg3QdSpWw NMZULMO1pyQchkVhA4rG4WAS2ZR9LNzptmw3hB8ih6gZOrevaIe6i/UjfiiVv0EjHt3c GdjlSxJSHEZImkQp803DFh7gXNN1q76dNpNvXzHkhvugcYdXxJvqEFMZwHYNIMhPkW1B 2tig== X-Gm-Message-State: ACgBeo2XhrCaZt+KfmQpCTpYNeESAoCMEAZyEijNGD8B+8810SpGzyBg x6A03M1j895s+OhXfqT95BpiTaDQulMclA9/6E0WU3uL X-Received: by 2002:a05:6512:12c5:b0:48c:df54:a41a with SMTP id p5-20020a05651212c500b0048cdf54a41amr7049124lfg.464.1661849557114; Tue, 30 Aug 2022 01:52:37 -0700 (PDT) MIME-Version: 1.0 References: <1661483530-11308-1-git-send-email-zhaoyang.huang@unisoc.com> <12759ac7-4a6c-89fa-5fd0-914728f6415e@redhat.com> <29503bc0-441e-359e-29d0-37ac3c5dff04@redhat.com> In-Reply-To: <29503bc0-441e-359e-29d0-37ac3c5dff04@redhat.com> From: Zhaoyang Huang Date: Tue, 30 Aug 2022 16:52:09 +0800 Message-ID: Subject: Re: [PATCH] mm: skip reserved page for kmem leak scanning To: David Hildenbrand Cc: "zhaoyang.huang" , Andrew Morton , Catalin Marinas , "open list:MEMORY MANAGEMENT" , LKML , Ke Wang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Tue, Aug 30, 2022 at 4:03 PM David Hildenbrand wrote: > > On 30.08.22 04:41, Zhaoyang Huang wrote: > > On Mon, Aug 29, 2022 at 8:19 PM David Hildenbrand wrote: > >> > >> On 26.08.22 05:23, Zhaoyang Huang wrote: > >>> On Fri, Aug 26, 2022 at 11:13 AM zhaoyang.huang > >>> wrote: > >>>> > >>>> From: Zhaoyang Huang > >>>> > >>>> It is no need to scan reserved page, skip it. > >>>> > >>>> Signed-off-by: Zhaoyang Huang > >>>> --- > >>>> mm/kmemleak.c | 2 +- > >>>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>>> > >>>> diff --git a/mm/kmemleak.c b/mm/kmemleak.c > >>>> index a182f5d..c546250 100644 > >>>> --- a/mm/kmemleak.c > >>>> +++ b/mm/kmemleak.c > >>>> @@ -1471,7 +1471,7 @@ static void kmemleak_scan(void) > >>>> if (page_zone(page) != zone) > >>>> continue; > >>>> /* only scan if page is in use */ > >>>> - if (page_count(page) == 0) > >>>> + if (page_count(page) == 0 || PageReserved(page)) > >>> Sorry for previous stupid code by my faint, correct it here > >> > >> Did you even test the initial patch? > >> > >> I wonder why we should consider this change > >> > >> (a) I doubt it's a performance issue. If it is, please provide numbers > >> before/after. > > For Android-like SOC systems where AP(cpu runs linux) are one of the > > memory consumers which are composed of other processors such as modem, > > isp,wcn etc. The reserved memory occupies a certain number of > > memory(could be 30% of MemTotal) which makes scan reserved pages > > pointless. > > But we only scan the memmap (struct page) here and not the actual > memory. Do you have any performance numbers showing that there is even > an observable change? > > >> (b) We'll stop scanning early allocations. As the memmap is usually > >> allocated early during boot ... we'll stop scanning essentially the > >> whole mmap and that whole loop would be dead code? What am i > >> missing? > > memmap refers to pages here? If we can surpass these as it exist > > permanently during life period. Besides, I wonder if PageLRU should > > also be skipped? > > - if (page_count(page) == 0) > > + if (page_count(page) == 0 || > > PageReserved(page) || PageLRU(page)) > > I think we need a really good justification to start poking holes into > the memmap scanner. I'm no expert on this code (and under which > circumstances we actually might find referenced objects in a memmap), > though. > > But we should be careful with that. Agree. It may be helpless as kmemleak is for debugging purposes. Nack this patch by myself. Sorry for interrupt. > > -- > Thanks, > > David / dhildenb >