Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1580427pxf; Fri, 9 Apr 2021 11:59:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL3GRgXblUir7Bc9bg71Kwkh8HD1kLfb3bUuLMazyiMoAHtGPcH7G7DrIdGl0MTH9Sdn+G X-Received: by 2002:a17:90b:3783:: with SMTP id mz3mr203221pjb.176.1617994748262; Fri, 09 Apr 2021 11:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617994748; cv=none; d=google.com; s=arc-20160816; b=QuYvUWRQnPibCz+yb/NiQ/bSsFENMy9TeHa7m7ce71kcm0ozkZK+V9kauZaHMAEnmg BPSm7zwcTC4cyJ8iY2mJ4B+UOLoaDeUk5teTEpLbdoXxmJatD0rauw8Jbli02xeUmze7 sgRtFemnhcprSc4R/ys5rdl6e0b+I1Q8r38Em7uG9K4cjTmWG8y4D0ELo0UAzObAP6qC IeQjnSV8u91AZaeBrfEdvwfyVBnnQRnomSLaZYcALR0U1XrZugtJGel3+y4/zy2uAXDQ KyYACopkpwIL/zzBmeyW8Upza1N8hK3dALAUpp5emvwa2PBJMOOrR3h1nVm6rJxxsQsp FMZQ== 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=yiZtKKoqkRI3gZZhFYuXMkcbvraC4YjINsQdfKzNzag=; b=aNctZYLK09PR/8bxrGzOGVEqilm8VR49T7uJFnw0L+FtNLdynPHqEAm438iBfDHB58 09JFBfNGc+fiCjyVV+/4cU/EqUixItdq8BnlZijLN5y9O5+XuT8l5aILtYZBNKcXWhmy 1ZeMR1WIPy0w8Au9josmwyaQKxc7Pb+0/XN9ZiJqJ1HmJFrGwlDMjHuloyrc/iFh36N5 3kPrDN3OmEmSv/NDohk3sxT2NUNVMJWDlwI3zIgQoYs5DyoYgNIdTQ0LaejtqMc8kPLZ T6709qRTGQzcKo33hmITu6TogMyKIuyKbfEXE9Imu0egZqmoEyuRgO34ybbQpgBLNNFr qtyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=OYYJQ++Z; 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 w2si3898197plq.36.2021.04.09.11.58.56; Fri, 09 Apr 2021 11:59:08 -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=OYYJQ++Z; 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 S234760AbhDIS5v (ORCPT + 99 others); Fri, 9 Apr 2021 14:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234679AbhDIS5v (ORCPT ); Fri, 9 Apr 2021 14:57:51 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09E06C061762; Fri, 9 Apr 2021 11:57:38 -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=yiZtKKoqkRI3gZZhFYuXMkcbvraC4YjINsQdfKzNzag=; b=OYYJQ++Z9BGuizodyzOFqEofq7 ADpXyQa8Dq/MVnymVRgf1QYCxfTnoC+6em1KG+bWC6qkCdfhPz3PcpFdzJUEB5pcYesxlUIj3491U 5Zow+0ExjUg6QUWAKUDokf+bklhnwgGaRyIuV5xXkZY7P+I6XZFth0pygjhlXX25lfBHQBdlqf6LB lwRinNRMU+fpvj93AlYI8gp/xlGtIUH7NSyLzY+B9t4FxT3haIoSJTWYfMFRBawxfnCxM1vtNqSGt 4wVrb2MAqIex8y3JkL8Btjc5r7qNgQO8bYwixeUPknVFKyVNzS29tfjsprONDs9bIP63i3W30HPcT Tee9rakw==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lUwIQ-000nQQ-AE; Fri, 09 Apr 2021 18:56:03 +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 , Christoph Hellwig , Jeff Layton Subject: [PATCH v7 07/28] mm: Add put_folio Date: Fri, 9 Apr 2021 19:50:44 +0100 Message-Id: <20210409185105.188284-8-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210409185105.188284-1-willy@infradead.org> References: <20210409185105.188284-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 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 4c98b52613b7..747c6f47aef6 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 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. @@ -1242,9 +1247,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 @@ -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); + put_folio(folio); } /* -- 2.30.2