Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6805pxv; Wed, 14 Jul 2021 21:39:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMYVd+SoRbh7pUWtcECSx7XKcmjdLj3b71u285aiZFWSVT8/vNaHYKg9leDTQ72uAlWtLP X-Received: by 2002:a05:6e02:20e3:: with SMTP id q3mr1262737ilv.214.1626323944000; Wed, 14 Jul 2021 21:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626323943; cv=none; d=google.com; s=arc-20160816; b=ln29l2pJHiNM4Y/O/7zDOdUVYgqadWwN7pqqT8neWCcggqE0X4aWfIWR43F2VNVQFC qP9QGRC7SifJCtqdaOcego1AUhM95WUfAucc+2T+CMAw6b0JffzX/fIJqlvKwLCvW9RD OYMneUYWD1nEinfUSZFdIm+CCmzmwBZMhvSd6WA4ZL27aNd4MD+hzIXBsodVAX6nGoH5 vMjPjfd8bvHoKi7p4p/fkJOLVHbuRD47uKFiuFGhnW9qrFowp9t8T+qr2MEcMukt7oaq eKUEOAkXUQjGtNvmvPdpo0FBXLImahwH6Zn5o50sKtDXAIVpeuuSC+MElcHuH7QnV3LU h+fg== 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=xNlcmWioaEpMTq7wyjGafnxE/o4LDRutv2Vlte/uvYQ=; b=UswYeUQAZy+NCqrDeYGDMSeUDt9QrUEF5xbnE3jwaQ5WNhfCwdJJ0NuuI6JrfeAAQu vYVKKi1mRxmWac6zHR6mICb6ejJuhV3BqSg/bPIJlKRxkJlr38S4jKwAqleawMPbKR2b AT91uFgLFb4vdGIMh2ytdTTgrhVJiTJdcJGBp0pKmx3zB6nDXngIUPMRXslT9u5y2pyq Ehfcz0lpvB9TzupYMV8yZIFd1QNDq3moXEwUQIgVxgYZ7sc+yWBw+S2B2YuGV8zvsv6f ni8gbNPFZ5SmcrE0yiSHVL/3HAcOWkHlqJPangODwVszL7FOOKPleGJazwvWyI7SlALg RTSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=R9D8WQ7o; 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 q20si5969043iow.57.2021.07.14.21.38.52; Wed, 14 Jul 2021 21:39:03 -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=R9D8WQ7o; 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 S233239AbhGODql (ORCPT + 99 others); Wed, 14 Jul 2021 23:46:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbhGODql (ORCPT ); Wed, 14 Jul 2021 23:46:41 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30AE9C06175F; Wed, 14 Jul 2021 20:43:48 -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=xNlcmWioaEpMTq7wyjGafnxE/o4LDRutv2Vlte/uvYQ=; b=R9D8WQ7oQC/xlLCcUsR8xwnl7L yWyQnn6HYAlUgVvXzVwt28RIvBcbZe7OKy8sOe+mZaxSluNIvBqqlxQ4pzmaLImurUn+tHmtexqX9 gtwTZxVWKs990MuiO4w1jWVhn23zX7y4oKap0bvzTJTYjtqtO92TlCuGUvUorIFDedgpo7S/CMGhv 9OrNy8/AzTMGRfNrhTWtHOHuo0GMEUFbXQf8s4HyW4eQFqiWQq3u8FMkd+OMuFCoF+uRUNsid3L76 25dGUpPP4l5kFtj//mSCNFuIRgXI98W7xfrWKCyj2IMbyn9itjHr+TB56FZ4GEuY43l+F5kRUcaVZ OQF08s2A==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3sGU-002ua7-1A; Thu, 15 Jul 2021 03:42:40 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Zi Yan , Christoph Hellwig , Jeff Layton , "Kirill A . Shutemov" , Vlastimil Babka , William Kucharski , David Howells Subject: [PATCH v14 008/138] mm: Add folio_get() Date: Thu, 15 Jul 2021 04:34:54 +0100 Message-Id: <20210715033704.692967-9-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-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_get() instead of get_page() and save the overhead of calling compound_head(). No change to generated code. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Zi Yan Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton Acked-by: Kirill A. Shutemov Acked-by: Vlastimil Babka Reviewed-by: William Kucharski Reviewed-by: David Howells --- 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 9eca5da04dec..788fbc4cde0c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1223,18 +1223,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) + +/** + * folio_get - 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, + * folio_try_get() may be the right interface for you to use. + */ +static inline void folio_get(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); + folio_get(page_folio(page)); } bool __must_check try_grab_page(struct page *page, unsigned int flags); -- 2.30.2