From patchwork Wed Aug 11 10:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12430777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BB90C4320A for ; Wed, 11 Aug 2021 10:14:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C927F60F11 for ; Wed, 11 Aug 2021 10:14:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C927F60F11 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0F5CE6B0071; Wed, 11 Aug 2021 06:14:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07E856B0072; Wed, 11 Aug 2021 06:14:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E60AB6B0073; Wed, 11 Aug 2021 06:14:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id C8DBC6B0071 for ; Wed, 11 Aug 2021 06:14:45 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5549C8249980 for ; Wed, 11 Aug 2021 10:14:45 +0000 (UTC) X-FDA: 78462390930.04.B201051 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf08.hostedemail.com (Postfix) with ESMTP id 976313008BE8 for ; Wed, 11 Aug 2021 10:14:44 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id s22-20020a17090a1c16b0290177caeba067so8863728pjs.0 for ; Wed, 11 Aug 2021 03:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WTYHCuEFnDXdB595cBPoi/SpKE+ZbfqYRRPA09fPLBw=; b=jx8AUoTQAOgs9ofWY5K5kxiwPKCVzGGBeoXdoH4akiiVwKI77R0i3HxPQbzo/YR6jI 7X6/CA7cLOifwYEJq6WzFM0QbqUuMCCcEOY4OUpORmKj4aYj/YY1wmo3PRW2G+yLBoUp LWiOmBwXejyksqxHaRJtUVmWJOzdEeQH6EZXDBMSczddBmT26nk/u19+be42Nxvf46Hc OjBSA+EFAu5EyxGpASDFnq8q3CwDPosjc4c/OUGbSNsWrnCVZXMG+BSHb+m2X7dHwnXM LlJs3CyuKeVDHumGce0tbWEAGPMTIefdMWhvRu44uqIIcGMj835j891v7uZshwcMz+1w XPIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WTYHCuEFnDXdB595cBPoi/SpKE+ZbfqYRRPA09fPLBw=; b=F1FPTHTaU26pug02uNNgD8T52uc5VpqbCojpP3EAsOuMuJ3o+aFjV/OosDv1QqgzLL V4FZSe5b9X0Dzmx3qdyBPJjh3K/BcY33Jny+/I+Ds6wpjlv0VwL8y0CXumZgOjDgDH+R XYGXrwNHO+t15xTBvEc0CIdwx5gvyejdxezyXsnZZG+i50FB8/oWzaPhEwK+dE+lGswB BwR2Wk8vAFnBDY/HAzPUH7VaLJnO48E3+MseErqVsFwuKJ8i4KzMrmH6BLARZnnOMj6L 2yiX1lF8sTVMC+OyHX2ogMkR6eVVXms7mkLv3/5QtC2F/w+82kRM23o/Rkotgv4kRSdC pnzw== X-Gm-Message-State: AOAM5324kos4xN5F4KzEdM6tMPD8OwHV7D4ly043PSSMmcoRozoHMOXY aip13NCJs+JW0ea5ohS82TCi2g== X-Google-Smtp-Source: ABdhPJx+cDYF/LEloaMQBMlcUPfXkUTsidMnZGGA13tVHR88Xitp2kznMxEPgg5Hi5y6anpDDS8leQ== X-Received: by 2002:a63:4245:: with SMTP id p66mr269734pga.402.1628676883499; Wed, 11 Aug 2021 03:14:43 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id m6sm14598674pjv.40.2021.08.11.03.14.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Aug 2021 03:14:42 -0700 (PDT) From: Muchun Song To: akpm@linux-foundation.org, willy@infradead.org, william.kucharski@oracle.com, kirill.shutemov@linux.intel.com, dhowells@redhat.com, hannes@cmpxchg.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Muchun Song Subject: [PATCH] mm: remove redundant compound_head() calling Date: Wed, 11 Aug 2021 18:14:31 +0800 Message-Id: <20210811101431.83940-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 976313008BE8 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=jx8AUoTQ; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: fpttjszc537w4kiy1egkyr5tfe8564or X-HE-Tag: 1628676884-305536 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: There is a READ_ONCE() in the macro of compound_head(), which will prevent compiler from optimizing the code when there are more than once calling of it in a function. Remove the redundant calling of compound_head() from page_to_index() and page_add_file_rmap() for better code generation. Signed-off-by: Muchun Song --- include/linux/pagemap.h | 7 +++---- mm/rmap.c | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 79ec90e97e94..03b9a957ef10 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -608,18 +608,17 @@ static inline struct page *read_mapping_page(struct address_space *mapping, */ static inline pgoff_t page_to_index(struct page *page) { - pgoff_t pgoff; + struct page *head; if (likely(!PageTransTail(page))) return page->index; + head = compound_head(page); /* * We don't initialize ->index for tail pages: calculate based on * head page */ - pgoff = compound_head(page)->index; - pgoff += page - compound_head(page); - return pgoff; + return head->index + page - head; } extern pgoff_t hugetlb_basepage_index(struct page *page); diff --git a/mm/rmap.c b/mm/rmap.c index 232494888628..2e216835f07c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1231,11 +1231,13 @@ void page_add_file_rmap(struct page *page, bool compound) nr_pages); } else { if (PageTransCompound(page) && page_mapping(page)) { + struct page *head = compound_head(page); + VM_WARN_ON_ONCE(!PageLocked(page)); - SetPageDoubleMap(compound_head(page)); + SetPageDoubleMap(head); if (PageMlocked(page)) - clear_page_mlock(compound_head(page)); + clear_page_mlock(head); } if (!atomic_inc_and_test(&page->_mapcount)) goto out;