Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1107918rwb; Thu, 11 Aug 2022 16:17:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5bxVlx/rvZq7jJB9FtL1VQsMCU7U79zRiMEHwuX3WDhmPPTGYi1UwlOUEfp0A797OcyzLu X-Received: by 2002:a63:210f:0:b0:41c:650c:aea4 with SMTP id h15-20020a63210f000000b0041c650caea4mr952277pgh.267.1660259876701; Thu, 11 Aug 2022 16:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660259876; cv=none; d=google.com; s=arc-20160816; b=xOVkfxEljUqPgMfgfwd1htVk9zgIc98b4xZJ3RS5FI3X4WhrA2rbkG5fDS1c50uO4+ 3aBvXvDMN5JQFBVJp8KVtpIs8eZzvzi00vpHMSptTZyVXpoeiSsmkes+mAbosf2vUzN0 2OwsCSTR/qmrKACV8JLWZhO4ww5dWndEN6kwUhC8YkcQPgkHH65NmBWU5gfh7n+Y0h/f oSO+Bcf6XUAFXl8Tg8UUwmRwnLSQ7lJKrWbjUN2G7LenCeordu0+BCDCcy5p4GOOboHH 70s2/AwY+8zT6CconIaW1yvtxJtUtfTXFoonc1XbtpG9Cl7fhUI16VKRNxiIoNQp4u5L UVlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=U4cFNaAWOgHulE53szRjtqsALsuyv03D7CpTTAvZA/A=; b=1EPQUlhMahPK8NAJHJewpU/hcgXhgYplYmQByprinaUx7mX8HzFppvq270iCbVH5pM SiOD05RIzk83MQ7Cmq40jQK9OmLRMdo3C7W1La+UIZ+VPO4/c3sNun9OrgVYen5u4QQC uVYaJ5c+uDsx52HfxhjQdwDeZCm1DfJnVgSVw/+2O37HI3qii9ZeYMbRXlkmmKVC1mrc mG33TMZ3Jpyic+hgKUP1eJUbTo5UC0SYVFoMU81oSe//oAs7kvE7fhG5ULlYgDFYhVPO FG97kkvliNRhCGB1agF8O4fPpGCuOb3+GxVurBju+/Wg382epusdNKRto8LbRlJHAs1t EpMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=QdEHM1Ri; 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 x2-20020a170902ea8200b0016c09d0f5d5si581626plb.101.2022.08.11.16.17.40; Thu, 11 Aug 2022 16:17:56 -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=@linux-foundation.org header.s=korg header.b=QdEHM1Ri; 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 S236581AbiHKXHo (ORCPT + 99 others); Thu, 11 Aug 2022 19:07:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236178AbiHKXHm (ORCPT ); Thu, 11 Aug 2022 19:07:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9390B5C9D6 for ; Thu, 11 Aug 2022 16:07:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2F2BD6154D for ; Thu, 11 Aug 2022 23:07:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62743C433C1; Thu, 11 Aug 2022 23:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1660259260; bh=uM4mQsMaPWfe6CzcW2yFRtNpfqcoQtL3+z1lPfRtD5w=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QdEHM1RinZmbemO81xNuEoh7PM0Hi0bocvUh+C+YJhr8TaI46JS5CdILRxXHsfE+G gT7llHfMC7Wkq2+vAjlePIe9ztcJ92n1Ez4Dh0DCO5A97WW/FpUILCVqFhzkN4PIHT /rqxoJA1LfnyKaTNtk6Bsv2Q4NFV+L/virFaSYBk= Date: Thu, 11 Aug 2022 16:07:39 -0700 From: Andrew Morton To: Kairui Song Cc: Kairui Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox Subject: Re: [PATCH] mm/util: reduce stack usage of folio_mapcount Message-Id: <20220811160739.ea6b0f9c2912317c49287cda@linux-foundation.org> In-Reply-To: <20220801173155.92008-1-ryncsn@gmail.com> References: <20220801173155.92008-1-ryncsn@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, 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, 2 Aug 2022 01:31:55 +0800 Kairui Song wrote: > From: Kairui Song > > folio_entire_mapcount will call PageHeadHuge which is a function call, > and blocks the compiler from recognizing this redundant load. Did you mean folio_test_hugetlb() rather than folio_entire_mapcount()? > After rearranging the code, stack usage is dropped from 32 to 24, and > the function size is smaller (tested on GCC 12): > > Before: > Stack usage: > mm/util.c:845:5:folio_mapcount 32 static > Size: > 0000000000000ea0 00000000000000c7 T folio_mapcount > > After: > Stack usage: > mm/util.c:845:5:folio_mapcount 24 static > Size: > 0000000000000ea0 00000000000000b0 T folio_mapcount > > ... > > @@ -850,10 +850,10 @@ int folio_mapcount(struct folio *folio) > return atomic_read(&folio->_mapcount) + 1; > > compound = folio_entire_mapcount(folio); > - nr = folio_nr_pages(folio); > if (folio_test_hugetlb(folio)) > return compound; > ret = compound; > + nr = folio_nr_pages(folio); > for (i = 0; i < nr; i++) > ret += atomic_read(&folio_page(folio, i)->_mapcount) + 1; > /* File pages has compound_mapcount included in _mapcount */ > -- > 2.35.2