Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1220441iol; Sun, 12 Jun 2022 09:21:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi/yAX8lMaJBAkyQY4oAykGqKgtcxoGfKE/A709T8SzSBxvcOZeH0UU1OxQE6stcvg8Xbl X-Received: by 2002:a17:90b:3a87:b0:1e8:8079:b7e6 with SMTP id om7-20020a17090b3a8700b001e88079b7e6mr11097941pjb.139.1655050888336; Sun, 12 Jun 2022 09:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655050888; cv=none; d=google.com; s=arc-20160816; b=ooD6u7ahrdVpd/isd9UUAllzC5Csv28n/XQHkXoI0NRrsJnuNSdNPMjsrSLDjTyDya YKB9QRbO8NIon38YNX0JUi2z42CUcpjZtQ8v5lY6vsQo8eyUilMkhiTIWPulba7ZmNNE FD9FsZ9cYuK4Kt1JkqsQs+PKLUfDK2xepiRYVJL/0RM3ZyrgKCDdvanPE6t1xQEFt7Yc DGvf4rkOFRFS41qA59Sdo44hKh7JmEy6ug87s5kKhiAfwVrpFRC0aOweyqujWOm64bjC ISoxoilZoviytnaO4RPZMoMTZw74MDpCXOgb/Zl7m8fXsJmYxtlEPXHB+Fhj2Uto2NW+ Fxtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sDXoUvF9HvlqoQcYGACYQ/XDUHt968ekXwv/rzATOLg=; b=y4bRZvYfpceDVvTMFruzTzveTq1X032RyxO9Z25mznt5FzQEV++fEgedsNuDxVfLGQ VXeIuTw3MCTFCAWFVRTqyVodypts/j6w7CxqYr8AhqlJu/c2ngpa8JkmeLRz4wFV2svv Qfd0kkZgk6KUo8b6iD005guCeNeXd8asdO+abvy2IpRlB/NJ8ThCduYOUF7seaxYjoW9 xZfEMFfWQCLZ60piIXWyII2rTFljRPivzjNsLO18EjNHb4Rj6uu7aZKSEHBJfeuJyEFG 6TUo6SJw8lTgF4/Zujq+N8CHd8bxvoEGb8mGnDdkNt24HEP1nnZ6HehIzn20iXHU0s2S 6rww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=uYODikCP; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y18-20020a17090322d200b00168af344903si7587957plg.583.2022.06.12.09.21.17; Sun, 12 Jun 2022 09:21:28 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=uYODikCP; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237045AbiFLPoz (ORCPT + 99 others); Sun, 12 Jun 2022 11:44:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbiFLPoy (ORCPT ); Sun, 12 Jun 2022 11:44:54 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30EE2ED63 for ; Sun, 12 Jun 2022 08:44:53 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id j7so3545401pjn.4 for ; Sun, 12 Jun 2022 08:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=sDXoUvF9HvlqoQcYGACYQ/XDUHt968ekXwv/rzATOLg=; b=uYODikCP+VbMeXAeEkPfiA0/WPN47Gy8epeNTvX4VPR2T9patprusHUG4n0DD+88S6 L4MLSE8fLQzbNjPb9FApack4csETvvbZVFtpVI3fBAOCn/99ahV56lZTzPJMucV4FuFg gcktDO51ig0rLKU3JSEm5n0t7X9UI/me+uvROdyhblDRomOf1j+RhVDOvUqZCQnVnqpO ntNAJhRg89EH/2TpoZcnaStdB8ybLLvVDrr/IYhyyGUsME99RFklvLvFKIOcYgHDA63G cabmuMvQjNfRSQsRA4JR15IgLuAGPIABm54VfNnayT7FT+CLWZJWiTwnHA5WzVVzwQPa dVdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sDXoUvF9HvlqoQcYGACYQ/XDUHt968ekXwv/rzATOLg=; b=kTqaQlSDPUADEZFHljen7BpBoZJ7ytMhTs+ZLfCi8JitwZdTp1N659LMA/OUsjN+dY 9G83p7NOHrmHWTBl7/z3lkeykqwAl51gQcOrVFrJ9LzNvRe0mmV9m+5WvPBNr3pLAuxr SwteBtL+QqAQfGoH4UAoB93X+hIlAWBvMF0Mf98UKB0/ZRL1BqJxwREdXIl56GSyRRbi lys5hmuy8zeEGODEececYIJnrT8XeiDJWtHvvul1Y8XdFoX9KGB6Tm0fibkvoqz7J5vf 6a25EsqS0DTMOXpJrCNXnlFE+Nr9XtHS+BRh5YNHyM3vXldfRoeIJ4NBm3ZWPd8vhDqF Q1GQ== X-Gm-Message-State: AOAM5336nKEmRCWLXPqohXSXUqsx5LYzehXJiJ6E4hFPjZ18UE4phfE4 xAP9QKzYtaWTQPHXXoBxytVM33992bViiA== X-Received: by 2002:a17:902:ac8f:b0:163:fbb7:b057 with SMTP id h15-20020a170902ac8f00b00163fbb7b057mr55066011plr.67.1655048693203; Sun, 12 Jun 2022 08:44:53 -0700 (PDT) Received: from localhost ([2408:8207:18da:2310:f58b:e20:6b56:4b57]) by smtp.gmail.com with ESMTPSA id d10-20020a170903208a00b001689e31ff9dsm3243826plc.9.2022.06.12.08.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 08:44:52 -0700 (PDT) Date: Sun, 12 Jun 2022 23:44:47 +0800 From: Muchun Song To: Miaohe Lin Cc: akpm@linux-foundation.org, joao.m.martins@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/page_alloc: minor clean up for memmap_init_compound() Message-ID: References: <20220611021352.13529-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220611021352.13529-1-linmiaohe@huawei.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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 Sat, Jun 11, 2022 at 10:13:52AM +0800, Miaohe Lin wrote: > Since commit 5232c63f46fd ("mm: Make compound_pincount always available"), > compound_pincount_ptr is stored at first tail page now. So we should call > prep_compound_head() after the first tail page is initialized to take > advantage of the likelihood of that tail struct page being cached given > that we will read them right after in prep_compound_head(). > > Signed-off-by: Miaohe Lin > Cc: Joao Martins > --- > v2: > Don't move prep_compound_head() outside loop per Joao. > --- > mm/page_alloc.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 4c7d99ee58b4..048df5d78add 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6771,13 +6771,18 @@ static void __ref memmap_init_compound(struct page *head, > set_page_count(page, 0); > > /* > - * The first tail page stores compound_mapcount_ptr() and > - * compound_order() and the second tail page stores > - * compound_pincount_ptr(). Call prep_compound_head() after > - * the first and second tail pages have been initialized to > - * not have the data overwritten. > + * The first tail page stores compound_mapcount_ptr(), > + * compound_order() and compound_pincount_ptr(). Call > + * prep_compound_head() after the first tail page have > + * been initialized to not have the data overwritten. > + * > + * Note the idea to make this right after we initialize > + * the offending tail pages is trying to take advantage > + * of the likelihood of those tail struct pages being > + * cached given that we will read them right after in > + * prep_compound_head(). > */ > - if (pfn == head_pfn + 2) > + if (unlikely(pfn == head_pfn + 1)) > prep_compound_head(head, order); For me it is weird not to put this out of the loop. I saw the reason is because of the caching suggested by Joao. But I think this is not a hot path and putting it out of the loop may be more intuitive at least for me. Maybe this optimization is unnecessary (maybe I am wrong). And it will be consistent with prep_compound_page() (at least it does not do the similar optimization) if we drop this optimization. Hi Joao, I am wondering is it a significant optimization for zone device memory? I found this code existed from the 1st version you introduced. So I suspect maybe you have some numbers, would you like to share with us? Thanks.