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 X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 F3D52C4338F for ; Fri, 13 Aug 2021 14:02:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 79AB56023D for ; Fri, 13 Aug 2021 14:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 79AB56023D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 01FC16B006C; Fri, 13 Aug 2021 10:02:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EEA8A6B0071; Fri, 13 Aug 2021 10:02:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8B686B0072; Fri, 13 Aug 2021 10:02:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id C04876B006C for ; Fri, 13 Aug 2021 10:02:36 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 578F01B037 for ; Fri, 13 Aug 2021 14:02:36 +0000 (UTC) X-FDA: 78470222712.40.C01F2E7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf09.hostedemail.com (Postfix) with ESMTP id D7D633002935 for ; Fri, 13 Aug 2021 14:02:35 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 452271FFC3; Fri, 13 Aug 2021 14:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1628863354; h=from:from:reply-to: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; bh=lAPgD0JM9is1QIYISxL/J70/LIGKS2gFj6IbXg8VR4Q=; b=vxSIu2cb0Q7xK6empan4IyTzEzmnohTONKoSMcNQ9GCzJO02Jp2fFv70tkgKzduglAR99E Sajyu12wss/iLoSaWvgxEbUdLr0ZfQ0ctw+VCJRWmfexYGTAmE3y/b6x0MnIO8UGOzn0R2 m5vVNGftHjAsK2ky9kPqH87Uy01hPJo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1628863354; h=from:from:reply-to: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; bh=lAPgD0JM9is1QIYISxL/J70/LIGKS2gFj6IbXg8VR4Q=; b=uv5dnaubtajOMMcvFmnksuQ36wo5QJF65GoXHcrm2fbV0kdvjl6c6rwiiSSjHOSgIRdM6p iuDRXPby24v1lEBw== Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id 1EC91137CB; Fri, 13 Aug 2021 14:02:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id uxzcBnp7FmHjBwAAGKfGzw (envelope-from ); Fri, 13 Aug 2021 14:02:34 +0000 Subject: Re: [PATCH] mm: remove redundant compound_head() calling To: Muchun Song , 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 References: <20210811101431.83940-1-songmuchun@bytedance.com> From: Vlastimil Babka Message-ID: <808194f6-e5d0-59e4-ffd5-2c77a907232c@suse.cz> Date: Fri, 13 Aug 2021 16:02:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210811101431.83940-1-songmuchun@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: D7D633002935 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=vxSIu2cb; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=uv5dnaub; spf=pass (imf09.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam01 X-Stat-Signature: a6iaz37iqbue3wktxkn9kzpbqkd3fezj X-HE-Tag: 1628863355-520940 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 8/11/21 12:14 PM, Muchun Song wrote: > 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 Seems to be compatible with folio/for-next and not made redundant by that (yet? didn't check the branches planned for future versions), so OK. But long-term I'd expect these optimizations to be obsoleted by the folio work. > --- > 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; >