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 3E043C25B06 for ; Thu, 11 Aug 2022 23:07:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4CD18E0001; Thu, 11 Aug 2022 19:07:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFC1A6B0075; Thu, 11 Aug 2022 19:07:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EBCC8E0001; Thu, 11 Aug 2022 19:07:44 -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 900916B0073 for ; Thu, 11 Aug 2022 19:07:44 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ACFD31C6EB7 for ; Thu, 11 Aug 2022 23:07:43 +0000 (UTC) X-FDA: 79788850806.07.E367E88 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf27.hostedemail.com (Postfix) with ESMTP id 3678340195 for ; Thu, 11 Aug 2022 23:07:43 +0000 (UTC) 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 ams.source.kernel.org (Postfix) with ESMTPS id C6131B822F6; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660259263; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=U4cFNaAWOgHulE53szRjtqsALsuyv03D7CpTTAvZA/A=; b=jRFwbw8B1NGp0Cdj1lc/OewoXrkV+3agPfWeXp4KtkXLxiTUd74JcN2ZASy/E0PhqLj7UL rZRUA6X1/WQ1JCAS/CVGFeccJqsbXZIbYXiCbDK/zTM3xXZGOPaj24/+ZqftCB4PUPUJel vWVsuPnZMDjHx8+ukpRoi6VD9V+b+vs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=QdEHM1Ri; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660259263; a=rsa-sha256; cv=none; b=PsntTvk6SJgccHaom1MBbGSq8IPyeD5m3m+miTz1bsD8dERDkqfM8d7TE5/dhycsGKBzRi 0cTCIy5QDqOhH9tC8ZTJqK15s74jUmUwvx1PZPzm/lpygZq9kFnlZ17fSch5+CMt7pdOzu YNt/HO7x3w5XOy5LHzJbM+eHWopdkVE= X-Stat-Signature: ohyhzkuadwd498o734ccgb6yxin5yknz X-Rspamd-Queue-Id: 3678340195 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=QdEHM1Ri; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1660259263-314816 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 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