Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2618337pxv; Sun, 11 Jul 2021 20:17:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCBDcc/8brGei7JI8a69BeguGW0BqeB5bNH/zXZuGAq1mSfStqJgexr1zfL2npUQM6jTYL X-Received: by 2002:a05:6602:10e:: with SMTP id s14mr38630622iot.52.1626059861877; Sun, 11 Jul 2021 20:17:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626059861; cv=none; d=google.com; s=arc-20160816; b=Z5R/Pvx3FOKYeIqWiWEHSb6fUZWcIK5yXzLYq7dCYWEsCsyqafhoFlYUoETibvwX6o 5VIN+2VlMRA58cnjWaGDB6lWsdObTR1LFpB9E8sabD800WGMJEz1MHRhcxsNO1dDDbO4 eDxkATbgSO4gayu3upjCJjyn/MkUcFjvsTmPDR4XdFGpJruxKYtwVCBW4UuMVlNTbyZp 9HABJKxayyWsqEPAccXaZjtjCsMmuKrc7KdHDH6SY3zPYHwL6JwkJK3fC9qoBTQSvpnU B5eYD9/IVZyo1b47yOo1jPxIiugk1iUPUzypWM1VO4DsaHmQImf2s1NCKvDzmnPLA8Dd 4hSA== 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=RSpBqEzRg+SMLcv/y8kgE4FOO3vbcCIE8BAtX0wLrTY=; b=BAkgrksc10+BBcjG+6kzt2S677VfrzFirG3yZj3QfA5LPrC8F0hI7/Ox1Vmbvdvj5x JrrccZ0BikkBPUPCasPre7LdOGNpq1/T9nQCtuFTnZWLf5jecyFB5MZm2g8j1SLjBjAa YVlVfr7nKdL//ssG4SJI33UzwCv2MAPaFlwtH7wTRyUOh/K10ecBIrIOve5X2qz5pwrW 24FfVcVoxZGJZUHczKtlym6w2IOfWFvp7KVFfSIKeP99sWdku6Bik3Cs9M9kIa9DcfDA Bq6ET3AFi7rpfFKspbqWK+QrFB6B3DR8r3n5rn48n9ZzW7RVzC5G7rZFxhdtSTpW2GaE PTRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="RsJ1s/Qb"; 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 m6si15598840iol.83.2021.07.11.20.17.30; Sun, 11 Jul 2021 20:17:41 -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="RsJ1s/Qb"; 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 S232731AbhGLDSf (ORCPT + 99 others); Sun, 11 Jul 2021 23:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232540AbhGLDSe (ORCPT ); Sun, 11 Jul 2021 23:18:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46611C0613DD; Sun, 11 Jul 2021 20:15:47 -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=RSpBqEzRg+SMLcv/y8kgE4FOO3vbcCIE8BAtX0wLrTY=; b=RsJ1s/QbBIkZX1c5bFpc8/pISW ctBZtG+bvqrhIBrDNkzd/Hzk+E7A/jGdr6CJJBokJa3hM9QpW8A/4FgWUNDlJw8cncQJS4KtDAHoI vLibSHvN4LmrxeLFdUlJbVtIZUOtNbXp3PYbdiBhpGxSSytzdbTDgXOlUI/a6xHfTcZeYx9x8mNWQ t5JoQeySIO90gmhP2jLkdYibf913cotObNIKlOsMdjSUNEJzfFkz3afiGSaKTx0SwnEe4sYW9fFmB xs/XbFpnZLT/nygwxs7XgVe43kwMuSPLM8GT7CZB+JmdXIVBjD/5dcpDrglY05417gu/XClTYMKLo ez3+9Oxg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2mOo-00GnD9-L1; Mon, 12 Jul 2021 03:14:48 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , Jeff Layton , "Kirill A . Shutemov" , Vlastimil Babka , William Kucharski , David Howells Subject: [PATCH v13 012/137] mm: Handle per-folio private data Date: Mon, 12 Jul 2021 04:04:56 +0100 Message-Id: <20210712030701.4000097-13-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add folio_get_private() which mirrors 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 private 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 813 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 Acked-by: Kirill A. Shutemov Acked-by: Vlastimil Babka Reviewed-by: William Kucharski Reviewed-by: David Howells --- 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 7a11b25cf50f..c15b4af8ef4d 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -309,6 +309,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) +/* + * 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 pages + * should be used for data that's ancillary to the head page (eg attaching + * buffer heads to tail pages after attaching buffer heads to the head page) + */ #define page_private(page) ((page)->private) static inline void set_page_private(struct page *page, unsigned long private) @@ -316,6 +322,11 @@ static inline void set_page_private(struct page *page, unsigned long private) page->private = private; } +static inline void *folio_get_private(struct folio *folio) +{ + return 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 db1726b1bc1c..df18df0ab01b 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -184,42 +184,52 @@ static inline bool page_cache_get_speculative(struct page *page) } /** - * 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 count. - * The data must be detached before the page will be freed. + * Attaching private data to a folio increments the page's reference count. + * 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 = data; + folio_set_private_flag(folio); } /** - * 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 decrements + * Removes the data that was previously attached to the folio and decrements * 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 = (void *)page_private(page); + void *data = folio_get_private(folio); - if (!PagePrivate(page)) + if (!folio_private(folio)) return NULL; - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); + folio_clear_private_flag(folio); + folio->private = NULL; + folio_put(folio); return data; } +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 -- 2.30.2