Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp630360pxf; Wed, 31 Mar 2021 11:53:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3xV91bIT7zzUt0l9l/gx7p6IVJuoGFE7DewTYuQEEzR4YLVhMvQjqrgOBTs4dgL3A08Ow X-Received: by 2002:a05:6402:4405:: with SMTP id y5mr5708760eda.32.1617216819594; Wed, 31 Mar 2021 11:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617216819; cv=none; d=google.com; s=arc-20160816; b=rSML2Bk9cYKvNz/Puo2sp8FPtj19BllBRKtFBnhfPDuSWmc8v0PahrpIvGf/hPUAyK WNnQaNN3/IgvJnouF5DTHywH+s3Ud74s2H0pCgbG5jH76qG59I3HP5ZVUS8DKnWO65Im 4A3Gd7ojGWIp5/CC4AP5KsBeq0ZKQzOz/gS269y89A/4DYGOuQBN+1ikp6UYtELOfINh mMHvzUQqHrn3FJXtz0wLQJXskHHodbTuZlZmgo7o1IsyGU8fAOAyspV8UvmeUASLQhsI 9aigZFPBYz3x+SulDMLash3UiMKDuIwp/UWrd0j8yX2BPJ6QcQ04qnV68+9vQWm7GE0/ Zmaw== 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:date:subject:cc:to:from :dkim-signature; bh=XZ6ElKwOiBr0Bj94W4VHIoXqA2ESXrY1zQxsFMQPfVU=; b=HrlE1MIGJCZRRC+uoJTqh1UvEfSZWikOw49oHfNCuqPCtGEhCHNqbjZKmXaX5uqK0g 5ERfw7jh3fj7WkzENf3KECiVEtinMQVeNpQSAOTV/KhhK+bcpvGr/sxHbMW7ss62p6Pl mTvUZ5gD0kCTBSrLtnTK1DBquwQodCH+F42Yy23ogiflWen/JieVtJ8EyBOVPAifJQ9h 2ySCwAxYFd/8GWP5iGHi9+qxLpjBOOKvzVoIXviCBEvr7iiwsSWDO14TyfzCRon1ijju nbrpQaJuLUa9HwizuSges01QSuWgbsasVIA1R94jlgienJqsq+a7PZY1T7gzhTDItJu5 lIJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=U9FFNrYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j22si2474119edq.584.2021.03.31.11.53.17; Wed, 31 Mar 2021 11:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=U9FFNrYA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235549AbhCaSuB (ORCPT + 99 others); Wed, 31 Mar 2021 14:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235503AbhCaSt1 (ORCPT ); Wed, 31 Mar 2021 14:49:27 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF07FC061574; Wed, 31 Mar 2021 11:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=XZ6ElKwOiBr0Bj94W4VHIoXqA2ESXrY1zQxsFMQPfVU=; b=U9FFNrYA6bk1Y+pvFy35qKLRVi Fqh0tlCbjsb6v9KSqmVeQIT7pXM/9H5zM4h7HYnkBGOEg3XggLruHDHVdFlXNFfriTggSIuKHgdvm 6nACPAJULlduOSoBMKSrLq0bEmyw5m24l5OIqv5VM3pwbao3KGn+I8PCq43bFFxVRcrU6VOK68Npf IOeyetVGfueRbWSh4DadYODn6xXOXcygOqzbm1MVVgIrPV3iQCJCJqysQ2x0EAedqMz9UUon+K+eW LIWytUTmDfdAj2UUZ/I9O6MjSI2f4AhHN5mhDpR+ARseeKdrtKpWOURwb8UCf+5CXr5bJeP55VeLU 6v9y2B9A==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lRftp-004zE2-J4; Wed, 31 Mar 2021 18:49:07 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, Zi Yan Subject: [PATCH v6 06/27] mm: Add put_folio Date: Wed, 31 Mar 2021 19:47:07 +0100 Message-Id: <20210331184728.1188084-7-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210331184728.1188084-1-willy@infradead.org> References: <20210331184728.1188084-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we know we have a folio, we can call put_folio() instead of put_page() and save the overhead of calling compound_head(). Also skips the devmap checks. This commit looks like it should be a no-op, but actually saves 1312 bytes of text with the distro-derived config that I'm testing. Some functions grow a little while others shrink. I presume the compiler is making different inlining decisions. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Zi Yan --- include/linux/mm.h | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 195c4740522d..824acedc1253 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -737,6 +737,11 @@ static inline int put_page_testzero(struct page *page) return page_ref_dec_and_test(page); } +static inline int put_folio_testzero(struct folio *folio) +{ + return put_page_testzero(&folio->page); +} + /* * Try to grab a ref unless the page has a refcount of zero, return false if * that is the case. @@ -1228,9 +1233,28 @@ static inline __must_check bool try_get_page(struct page *page) return true; } +/** + * put_folio - Decrement the reference count on a folio. + * @folio: The folio. + * + * If the folio's reference count reaches zero, the memory will be + * released back to the page allocator and may be used by another + * allocation immediately. Do not access the memory or the struct folio + * after calling put_folio() unless you can be sure that it wasn't the + * last reference. + * + * Context: May be called in process or interrupt context, but not in NMI + * context. May be called while holding a spinlock. + */ +static inline void put_folio(struct folio *folio) +{ + if (put_folio_testzero(folio)) + __put_page(&folio->page); +} + static inline void put_page(struct page *page) { - page = compound_head(page); + struct folio *folio = page_folio(page); /* * For devmap managed pages we need to catch refcount transition from @@ -1238,13 +1262,12 @@ static inline void put_page(struct page *page) * need to inform the device driver through callback. See * include/linux/memremap.h and HMM for details. */ - if (page_is_devmap_managed(page)) { - put_devmap_managed_page(page); + if (page_is_devmap_managed(&folio->page)) { + put_devmap_managed_page(&folio->page); return; } - if (put_page_testzero(page)) - __put_page(page); + put_folio(folio); } /* -- 2.30.2