Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1582562pxf; Fri, 9 Apr 2021 12:02:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX9vh08skMrkrBzo84P98DyWQWWNrVgPUVtJVYSSmNqkD8i4BUFt/PgAmR49dE21T7KlMr X-Received: by 2002:a17:90a:1b42:: with SMTP id q60mr354954pjq.230.1617994938621; Fri, 09 Apr 2021 12:02:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617994938; cv=none; d=google.com; s=arc-20160816; b=AC9NrWjIVQPBVj6mOooqxnA0UwZBtkLPOPq5cAt8Yfv9PyhVyizMhJo5bHbcQRnhDf MU843npRQroWorwap3DF7dBSw+IBJOsTbBJsy/4jpg2u3e5A/aVmAz3fG88NL545E25Z tH5ucW5MNKvqT8iequlS/run4wvejwltDgenrxXIALMCSzDJ81gCaen8LzS6HeanVTQh 9Wg6y2epOD065I2dDgTl1muEUxzPa1XwWtOFnv4RwSdwy3nwMpebpFk7dYgkAVueyr3Q PLNyH98ddToYRzE8JsKqrOkpMqvboxd8EhJtL4ez77/qYt2A1aXsG5DCnr5FEOOX6yb+ GawQ== 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=QfTdX7btIzSBu+uZk8WeZY7TujjLVUUgOScgfZDzAAQ=; b=Zncy5BSF+frz0cwpHKk6fW8+GdolkBsPgLq6kItmzTBRoQGtPH8yUwjPhogmdRjpuI mYmCZYje1XJY6EDCKilLjXb8aPUTWqWwoQbsLBbIMg3ZIutAMh7LTu9QILjY2841vfkS 5bcePQXkPOxFMyG3yvIj0A0tDoXmxcIZPL1qOQePlp80Z0BwNhm8pducfvPY8lWTkCcd aqqPullRc6nRrwV2CK+Sar0YDVgzEs75rM/NAF2CR2A0M9hNpr/HfbpUcBArmGczIbCB 9bZOb2F9m2uu9KuRRPpQ510nZmQAigSpg+0/hLR3Mccou1Gw8uQT8/PXsN7N5A6MRtRq 98ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jlxWle95; 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 g16si3850122pfi.92.2021.04.09.12.02.05; Fri, 09 Apr 2021 12:02:18 -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=jlxWle95; 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 S234840AbhDITAG (ORCPT + 99 others); Fri, 9 Apr 2021 15:00:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234735AbhDITAG (ORCPT ); Fri, 9 Apr 2021 15:00:06 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80CB6C061762; Fri, 9 Apr 2021 11:59:52 -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=QfTdX7btIzSBu+uZk8WeZY7TujjLVUUgOScgfZDzAAQ=; b=jlxWle958k0boYddVDAWKdZAYz ZeDkjJhqs2zvl1fQ49sC5Mdt3Q9u/Oc+mbf4BqgRK01LtRl4CjnR/JiPPKE/pNrSOX9FKyAYdA31f O7MB2i4bYHTvEh+2eGHeexIN0ceNYvlZl72GMAFAlnJ1nGT9sfR7aFf4LvrMpu+UdRe/LNL5Htrj5 JXZ08DG5BnXk6riw9lrAQFePUA2/dv+7CW6grDfUqn7GzEAhOp+MR1WSCphCUBfR5/eFvKBeNlW5h z0Uxgb3N6I+lFHtsE9bluiIMGHXGElZy4zba71s7OXu2wAPlxq9nrFDFbkULMM+C4SGetjoVw6QIp gzrR3aqg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lUwKQ-000ng3-Ad; Fri, 09 Apr 2021 18:58:14 +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, Christoph Hellwig , Jeff Layton Subject: [PATCH v7 10/28] mm: Handle per-folio private data Date: Fri, 9 Apr 2021 19:50:47 +0100 Message-Id: <20210409185105.188284-11-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 Add folio_private() and set_folio_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 attach_folio_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 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 | 16 ++++++++++++++ include/linux/pagemap.h | 48 ++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index d65050851037..1210a8e41fad 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -322,6 +322,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) @@ -329,6 +335,16 @@ static inline void set_page_private(struct page *page, unsigned long private) page->private = private; } +static inline void *folio_private(struct folio *folio) +{ + return (void *)folio->private; +} + +static inline void set_folio_private(struct folio *folio, void *v) +{ + folio->private = (unsigned long)v; +} + 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 350e1c9726f2..f2fd0b811c1b 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) } /** - * attach_page_private - Attach private data to a page. - * @page: Page to attach data to. - * @data: Data to attach to page. + * attach_folio_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 attach_folio_private(struct folio *folio, void *data) { - get_page(page); - set_page_private(page, (unsigned long)data); - SetPagePrivate(page); + get_folio(folio); + set_folio_private(folio, data); + SetFolioPrivate(folio); } /** - * detach_page_private - Detach private data from a page. - * @page: Page to detach data from. + * detach_folio_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 *detach_folio_private(struct folio *folio) { - void *data = (void *)page_private(page); + void *data = folio_private(folio); - if (!PagePrivate(page)) + if (!FolioPrivate(folio)) return NULL; - ClearPagePrivate(page); - set_page_private(page, 0); - put_page(page); + ClearFolioPrivate(folio); + set_folio_private(folio, NULL); + put_folio(folio); return data; } +static inline void attach_page_private(struct page *page, void *data) +{ + attach_folio_private(page_folio(page), data); +} + +static inline void *detach_page_private(struct page *page) +{ + return detach_folio_private(page_folio(page)); +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else -- 2.30.2