From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD618C433B4 for ; Fri, 30 Apr 2021 18:17:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5ACDB61476 for ; Fri, 30 Apr 2021 18:17:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5ACDB61476 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E7C5C6B006C; Fri, 30 Apr 2021 14:17:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E529A6B006E; Fri, 30 Apr 2021 14:17:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF33C6B0070; Fri, 30 Apr 2021 14:17:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0049.hostedemail.com [216.40.44.49]) by kanga.kvack.org (Postfix) with ESMTP id B36756B006C for ; Fri, 30 Apr 2021 14:17:33 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6CA328249980 for ; Fri, 30 Apr 2021 18:17:33 +0000 (UTC) X-FDA: 78089841186.04.7AA360A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 388905001522 for ; Fri, 30 Apr 2021 18:17:24 +0000 (UTC) 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=YWuEDkwbkLz3Muwpf0pB7C0Vd/VBMGHhj8TA6oz9+L4=; b=VNzPeE42ytoM4jjjb8tlIc2MCY YuzgoujT3585U0yRKdvL1nBsCt5mLaG1cvN1t+ayeEZeFYBDO2xt6fF3OM2esyAkUL1Xkx0sTo4JB I+JtQeTDgkAD3OPe7aGlogvPrhIN4hPVskDK/eVM1vuYmGv029atP9qTq0IbWzkeNO1syN2aBTZ2N wVoWeTusHEZuwwfYwvDuoTiWDhrxXrolIw2XjyplCnF4jb5+fgEUaD2nu4VZfGI3fLLIuXiGffw4x /kdg0RHU8N++AOrsrPVZdJm83aukIXPXjtrQsDeQ621ki38Comd9fY0KjOaOSzP1GKnCqXZJj0RMv U2G22ROQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lcXfm-00BMnn-Mr; Fri, 30 Apr 2021 18:15:43 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org Cc: "Matthew Wilcox (Oracle)" , Christoph Hellwig , Jeff Layton Subject: [PATCH v8 10/31] mm: Handle per-folio private data Date: Fri, 30 Apr 2021 19:07:19 +0100 Message-Id: <20210430180740.2707166-11-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210430180740.2707166-1-willy@infradead.org> References: <20210430180740.2707166-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VNzPeE42; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 388905001522 X-Stat-Signature: gcgoers1xmdjciefeuod3he87dzq764u Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619806644-468210 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add folio_get_private() and folio_set_private() which mirror page_private= () and set_page_private() -- ie folio private data is the same as page private data. The only difference is that these return a void * instead of an unsigned long, which matches the majority of users. Turn attach_page_private() into folio_attach_private() and reimplement attach_page_private() as a wrapper. No filesystem which uses page privat= e data currently supports compound pages, so we're free to define the rules= . attach_page_private() may only be called on a head page; if you want to add private data to a tail page, you can call set_page_private() directly (and shouldn't increment the page refcount! That should be done when adding private data to the head page / folio). This saves 597 bytes of text with the distro-derived config that I'm testing due to removing the calls to compound_head() in get_page() & put_page(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton --- include/linux/mm_types.h | 11 +++++++++ include/linux/pagemap.h | 48 ++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 276e358c75d3..111c304b7d13 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -302,6 +302,12 @@ static inline atomic_t *compound_pincount_ptr(struct= page *page) #define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK) #define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE) =20 +/* + * page_private can be used on tail pages. However, PagePrivate is only + * checked by the VM on the head page. So page_private on the tail page= s + * should be used for data that's ancillary to the head page (eg attachi= ng + * buffer heads to tail pages after attaching buffer heads to the head p= age) + */ #define page_private(page) ((page)->private) =20 static inline void set_page_private(struct page *page, unsigned long pri= vate) @@ -309,6 +315,11 @@ static inline void set_page_private(struct page *pag= e, unsigned long private) page->private =3D private; } =20 +static inline void *folio_get_private(struct folio *folio) +{ + return (void *)folio->private; +} + struct page_frag_cache { void * va; #if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a4bd41128bf3..c58587225fe5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -260,42 +260,52 @@ static inline int page_cache_add_speculative(struct= page *page, int count) } =20 /** - * attach_page_private - Attach private data to a page. - * @page: Page to attach data to. - * @data: Data to attach to page. + * folio_attach_private - Attach private data to a folio. + * @folio: Folio to attach data to. + * @data: Data to attach to folio. * - * Attaching private data to a page increments the page's reference coun= t. - * The data must be detached before the page will be freed. + * Attaching private data to a folio increments the page's reference cou= nt. + * The data must be detached before the folio will be freed. */ -static inline void attach_page_private(struct page *page, void *data) +static inline void folio_attach_private(struct folio *folio, void *data) { - get_page(page); - set_page_private(page, (unsigned long)data); - SetPagePrivate(page); + folio_get(folio); + folio->private =3D (unsigned long)data; + folio_set_private(folio); } =20 /** - * detach_page_private - Detach private data from a page. - * @page: Page to detach data from. + * folio_detach_private - Detach private data from a folio. + * @folio: Folio to detach data from. * - * Removes the data that was previously attached to the page and decreme= nts + * Removes the data that was previously attached to the folio and decrem= ents * the refcount on the page. * - * Return: Data that was attached to the page. + * Return: Data that was attached to the folio. */ -static inline void *detach_page_private(struct page *page) +static inline void *folio_detach_private(struct folio *folio) { - void *data =3D (void *)page_private(page); + void *data =3D folio_get_private(folio); =20 - if (!PagePrivate(page)) + if (!folio_private(folio)) return NULL; - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); + folio_clear_private(folio); + folio->private =3D 0; + folio_put(folio); =20 return data; } =20 +static inline void attach_page_private(struct page *page, void *data) +{ + folio_attach_private(page_folio(page), data); +} + +static inline void *detach_page_private(struct page *page) +{ + return folio_detach_private(page_folio(page)); +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else --=20 2.30.2