Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp629529pxf; Wed, 31 Mar 2021 11:52:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMEs3vsSMnvKCnPnd3QD6K8/+YdSYrbbfPG+FeeVJWX4lyKMQbtthR2eKcihA88kalxmYL X-Received: by 2002:a50:e702:: with SMTP id a2mr5631824edn.3.1617216724893; Wed, 31 Mar 2021 11:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617216724; cv=none; d=google.com; s=arc-20160816; b=i5Rk3wegKym9rI5zfKr8WFsIbHnhpF3+bKarWmY1OOmNMf+4aQPdJyK8LqdBorxNwq xNuKxJdsJ7+/nDVrH72bPc/1gwbqzOOW/hL2s3GGZ0TnMaZBTzQB0WMxNOZo1CNdV7ir /qx2WJ8g1DORveKeVwPW2jvB15y/bu23ZCD6HYR6bPReLEIShkEk169TM/o49w0XAgln 9AsOog7++g26eLmRXmpvpl3iuJPpK+F7efXt6uV4gVwyuS/6N8cc1vN2NQ7GqOOcgfRI XWjbmEEXCQfUl8g+Gl0iUcO/f/O7qcExVTyV6uTaDbn5oulwga3dTV17glDt+uTrfFYs PR8g== 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=NRhqeoCoYorlNSPG0N+pti1euHQChgqgzhBAKtD+lGw=; b=Vu7p8olZQr297ZwVshK2dDaB8N2pZAWJK+mKfgh5GpMJfVWjSjArNz9nLxDpIJUiyY n1iJJrzfGOdiA8iXZG4bLLwoW0+qUjp+/Hifvz+tjz3MQJ8GDkI/bmetVokUSK/TI5I3 c8q9kFO3wE57xoLIBCnDqdZa2RkMmtdU3C7EGVEiHaouCPNwt+7lA3dBCRocgocPn2I0 6JQZRfHQHxToMuWZqztUC3tZ1AhAaFX9LVtWB/MONQPx0qqwaJsO3onkcqbovzXcry2G 0JFvd4dNWgMyOivuHjzRnjXtlySiQZkF5RUjvT8YSplr1ItsKLvVZXCXOOrja8mgocb+ IHsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qFujYRbd; 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 p25si2617331ejc.571.2021.03.31.11.51.42; Wed, 31 Mar 2021 11:52:04 -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=qFujYRbd; 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 S235472AbhCaSuV (ORCPT + 99 others); Wed, 31 Mar 2021 14:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235563AbhCaSuG (ORCPT ); Wed, 31 Mar 2021 14:50:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B92C061574; Wed, 31 Mar 2021 11:50:05 -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=NRhqeoCoYorlNSPG0N+pti1euHQChgqgzhBAKtD+lGw=; b=qFujYRbdn8eqS9ULraOEPorrtH eXXN0qIaFqlNVwTQgyxNnH1ZphOCeS41ccbdJGiUNLdPBIEI+4P1ZtWq/EO/6rJsMn4ss7ZcSBIss SRnH9W0DsUAWdUVvOP7p+In9NBpc1XJffc1Ttfa/xiy6BY6GR/k4eE4M2ez+feY2TYXGGe8fv6LZo VLTMQVcArA2qxXXqMYC0ZQfkMhPLHi68ImuonYkwJ4WvNrIVTqeIDHLALbwnIJkBtN/TJezc4Wnb1 r3wA+c2Be2DyQzZuJoxli9s2EEdW80V0Yer4UHxWsOmhLQPm2mbxKpiEZPJexIcfOmS/K4ZfXUHZM 3CHEDOfg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lRfty-004zF2-Hb; Wed, 31 Mar 2021 18:49:16 +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 07/27] mm: Add get_folio Date: Wed, 31 Mar 2021 19:47:08 +0100 Message-Id: <20210331184728.1188084-8-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 get_folio() instead of get_page() and save the overhead of calling compound_head(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Zi Yan --- include/linux/mm.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 824acedc1253..818010a6b4c9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1205,18 +1205,26 @@ static inline bool is_pci_p2pdma_page(const struct page *page) } /* 127: arbitrary random number, small enough to assemble well */ -#define page_ref_zero_or_close_to_overflow(page) \ - ((unsigned int) page_ref_count(page) + 127u <= 127u) +#define folio_ref_zero_or_close_to_overflow(folio) \ + ((unsigned int) folio_ref_count(folio) + 127u <= 127u) + +/** + * get_folio - Increment the reference count on a folio. + * @folio: The folio. + * + * Context: May be called in any context, as long as you know that + * you have a refcount on the folio. If you do not already have one, + * try_grab_page() may be the right interface for you to use. + */ +static inline void get_folio(struct folio *folio) +{ + VM_BUG_ON_FOLIO(folio_ref_zero_or_close_to_overflow(folio), folio); + folio_ref_inc(folio); +} static inline void get_page(struct page *page) { - page = compound_head(page); - /* - * Getting a normal page or the head of a compound page - * requires to already have an elevated page->_refcount. - */ - VM_BUG_ON_PAGE(page_ref_zero_or_close_to_overflow(page), page); - page_ref_inc(page); + get_folio(page_folio(page)); } bool __must_check try_grab_page(struct page *page, unsigned int flags); -- 2.30.2