From patchwork Mon Aug 1 17:31:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 12933936 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 A9B5DC00144 for ; Mon, 1 Aug 2022 17:32:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 101548E0001; Mon, 1 Aug 2022 13:32:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1536B0072; Mon, 1 Aug 2022 13:32:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBC078E0001; Mon, 1 Aug 2022 13:32:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DD99C6B0071 for ; Mon, 1 Aug 2022 13:32:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B129CAB333 for ; Mon, 1 Aug 2022 17:32:24 +0000 (UTC) X-FDA: 79751717808.12.E13AB1E Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 5E0711800E2 for ; Mon, 1 Aug 2022 17:32:24 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id b10so11365021pjq.5 for ; Mon, 01 Aug 2022 10:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc; bh=SunuZnU7T4CE2remubz9UBNubgP2sRU6U2kOV3j7OxI=; b=jR0Q5aUO8du9aLHcUQDHwAwJI5wVFt/2RONi9H+OMvd+6a7Z2cFeeBsX1RKXVv7PIn 8bG+egZ4Y5DYlG1e+B/TwOtYt+wb8NOpEz5jwRb4YKtTB1RcJ7U9qjaLDQP4IVNndTgp UEnxminfoj1iujfrDUE677GASaAvWyfUf6bFybTEXPrvaC1JfTaHHVlUAFKVCQrjAkG9 89kZk5YRtP+XegbBxSDRMxJzJBBb09B+/v9Gl3/aUKLfCMaEtrvFjszCXRI8wfgdNNSm ww+vUsbh/V5WNWPBEFKwyFamWfpbqGNvvtEDMxSvXtncPJ+Z+2XDlvu4Dv4c4VVhln2N labQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SunuZnU7T4CE2remubz9UBNubgP2sRU6U2kOV3j7OxI=; b=NV6sObbYturJUhPGFwN5qJBQjdfYc02l9YvVWHQ6nbtLiZJuSjpyogqaj+M2am9hEW fcb/UtlpGdwM4mkJKGhvbAutBMgqCSks1R9xjlXhjZvRaeCzAerYxvjnKPpNO4FCFZ79 kGR+DPkunBGLegDI5Ziff9+qBQBjtFfIslyq6Mq9GqDWAE1SBkFxC/wEyi6vz0GtHESQ Ro+8Rbj+arPj5TrpB+X+1sS9rVGwYWisCTBhN6Xf/zWIu+Zg1RyBo7LGOZRtIUHHpMLJ 1Vqey0Kt5o+47g+FAbyZzEY5uqc2MJd/iEGYgfRV6XteziAlzgxMUkMw7PJ3zuXYAhgb CFOg== X-Gm-Message-State: ACgBeo0Z3IBkElvvFl+iyEIM/3pu/aDkeLsV5/6nEBFaFOyaGi5Nv4l8 wlorZwjmbxnqoRMyC76Dwbz1bqRmJlpSzaymIh4= X-Google-Smtp-Source: AA6agR6RKZHX/DsN5s+EpIqK6F4Fe8VFvCU6UXdmiCHA1tLHK3pbipCkdwWe9KYMp5YkYCCYN8vfJA== X-Received: by 2002:a17:90b:4f91:b0:1cd:3a73:3a5d with SMTP id qe17-20020a17090b4f9100b001cd3a733a5dmr19797299pjb.98.1659375142655; Mon, 01 Aug 2022 10:32:22 -0700 (PDT) Received: from localhost.localdomain ([240e:305:1782:73ba:780e:897a:ec8d:6b79]) by smtp.gmail.com with ESMTPSA id p5-20020a17090b010500b001f325b97913sm8961486pjz.53.2022.08.01.10.32.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 01 Aug 2022 10:32:22 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Matthew Wilcox , Andrew Morton , Kairui Song Subject: [PATCH] mm/util: reduce stack usage of folio_mapcount Date: Tue, 2 Aug 2022 01:31:55 +0800 Message-Id: <20220801173155.92008-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.35.2 Reply-To: Kairui Song MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659375144; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=SunuZnU7T4CE2remubz9UBNubgP2sRU6U2kOV3j7OxI=; b=ABHyQbPGOOieODRuCgyuX+sajIN+kNOjgEnrHEC/pAB98Ozaq9eVYldxUtUr8uq+xinWL5 qjXWNl13UBZuBXoPCQ6UIwe5w6rzhiLP4ef9NBJ8ZhvSi/SZBZazU2FYgD6BinimtjY82y 2/HVD/zsE9AUWuRzym6RG6L9c0fUAjg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jR0Q5aUO; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659375144; a=rsa-sha256; cv=none; b=D37dEunaysvTOSk5NfS4s7H5sO2AmWc3nNI+Cjoa+LstSuYHPOpBh4G5XFyvTKmIqxcQbx TBlKzRH2CU08zbkJHtlcsxvZtc6JByF7saqhSXuIKfe6MVTXn7Bo3hNw7nF/9PUBGO3E6E EO8PVsXVOqOXJyO9Z5N5pRhCd7TPG+w= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jR0Q5aUO; spf=pass (imf06.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5E0711800E2 X-Stat-Signature: 1uupjptja5ikbszzuxg5scyo61b98rqy X-HE-Tag: 1659375144-455457 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kairui Song folio_entire_mapcount will call PageHeadHuge which is a function call, and blocks the compiler from recognizing this redundant load. 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 Signed-off-by: Kairui Song --- mm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index 0837570c9225..98a589bb89c9 100644 --- a/mm/util.c +++ b/mm/util.c @@ -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 */