Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3910740pxj; Tue, 11 May 2021 14:56:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFgjR2tRBLsdlUZfQMMZLUKvME7Vo/4HpKDHBrT7pYpC62Ov+ReSh1mOwFCpt+BZwM/R4S X-Received: by 2002:a17:906:2bd3:: with SMTP id n19mr33818715ejg.210.1620770179221; Tue, 11 May 2021 14:56:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620770179; cv=none; d=google.com; s=arc-20160816; b=tdje83ykkmF07jhMDWMh01CckLFYAc7Scw/3N8H553NcjPYpI54bkxDOKj7cNgvyIG v3C3bJrnsx3iZEP0wn0P9WInxca2WrSBcmddpDNfT3ABaY2pONP6IYZ91jRDbZadMwYO IhexVIMM8/QSEg6g0lCS1HB3xWVAp+ssDw0Q9UMzoU5Ae80ANk9bRr3/hLRWjLudAgjJ LmBdcSMqqYdpP2ZYNZZ4lX7AhHpbZMPsbQ1tjfjf68DJvAZKOS5pHboUcwq65fqDfTYQ a3iJbq9d0h5FLPQmYdnaDKSzW6IOKLgbKdlDF0Y4fHUQkhTl2MhwXDGmK/YL9e7i4Scs Q9tg== 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=db+PTL9EAtXLFkws4aJ1HfijoiuB9GF9rbs4PdOnE3Q=; b=XJB+I462+1GM/Hjj10zUl+7FzOkpr9m8LugTw+YEgAxYPkTkd1uXyAcmV2MEdYrJ3u ydVyJ0zV+MQEQrwVJ+9HQF2T6yvPrq9ehiAQVjDsDqaHFM/xcdsweH6eSKtg9hUqLvax ++YKoo40DPZv1aRyabUBELpMAD9apWO7RSvCtv/pQWksgwnguvw3P22P+9FmTo0WnUxP 1tXRQ68lsoBUujc4590jxxg0SRV3yzA9UtJCFbWnpAzWrq4NuIBQwqF8Qggn075rrh/p 45JqyfX0riwmsLYAV04ui9ztu+2VAONHUSOZ5qzGzjMuTqmnSIK8JBXLjTkWr3D2tCil wQSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=MFqKZGuX; 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 y15si16832052ede.450.2021.05.11.14.55.55; Tue, 11 May 2021 14:56:19 -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=MFqKZGuX; 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 S229996AbhEKVxw (ORCPT + 99 others); Tue, 11 May 2021 17:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbhEKVxw (ORCPT ); Tue, 11 May 2021 17:53:52 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66E26C061574; Tue, 11 May 2021 14:52:45 -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=db+PTL9EAtXLFkws4aJ1HfijoiuB9GF9rbs4PdOnE3Q=; b=MFqKZGuXtzdHVX/Tyqm9ExcJds O1nylkqDmXL0xMkmNVKjh2EdkSnkgghLSfK6s/GuPd1ZQXNr177C2eZxgQVx4auMK+exPAcdvdoRD yJamOWJ6U0cJC+X7szP1l0/cS9BP3rh3WJKYcLF8Fq27jt7NoYNCc5YVgqHZ651s8pVW1alwkiNPC 6Wkvn+pnrB1yjctVo152quYQ8HTTOGw/Se1vURPwCTi3dKH5L4TlldHfwXmeCRua1O37+O7nSuail yCDCWYhDaqmclOAvQrmAi7Yi4p/wryMwIzqc0tT79eDqAW6oKMTEiObO/MfLECUI5TyUwh453VduR blxiv8hQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lgaHC-007hoG-Iq; Tue, 11 May 2021 21:51:09 +0000 From: "Matthew Wilcox (Oracle)" To: akpm@linux-foundation.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan , Christoph Hellwig , Jeff Layton Subject: [PATCH v10 06/33] mm: Add folio_put Date: Tue, 11 May 2021 22:47:08 +0100 Message-Id: <20210511214735.1836149-7-willy@infradead.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511214735.1836149-1-willy@infradead.org> References: <20210511214735.1836149-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 folio_put() 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 Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton --- 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 a55c2c0628b6..610948f0cb43 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -751,6 +751,11 @@ static inline int put_page_testzero(struct page *page) return page_ref_dec_and_test(page); } +static inline int folio_put_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. @@ -1242,9 +1247,28 @@ static inline __must_check bool try_get_page(struct page *page) return true; } +/** + * folio_put - 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 folio_put() 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 folio_put(struct folio *folio) +{ + if (folio_put_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 @@ -1252,13 +1276,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); + folio_put(folio); } /* -- 2.30.2