Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1724858pxb; Thu, 4 Mar 2021 20:22:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmHNeo+U61kZS1JATc0TZclIpKl1gks3/KGzK+IKXo2lsFttOAaC+FUVY81SXKbqctSl/t X-Received: by 2002:a05:6e02:20c4:: with SMTP id 4mr6961539ilq.221.1614918155119; Thu, 04 Mar 2021 20:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614918155; cv=none; d=google.com; s=arc-20160816; b=FXUZCYq75vstFwXhqvKxfyzlHhPcSamZ5seO4bEZSV+pSi4Zy70eripME86Qtoj8NJ gDf14lpvU0c2mMx3qgeAYrIeRDy+zG65WIMUPbYJvs2E1bIpdsE/gTKKjvyzdbXhOf1/ lkMZmMkJubFJxgYR0qTs1eZyYfYCRf9F1DXGSH+VxidACyC97j5udF/+ysm0ETyPDYhs vIqXsk69eQyiTlPMrvmgsIl/Th44lDSI+hFMKjAM2ooiRisWFVPpol+V/Cj5UHQUS/Xt VgkTXZtwgaUqSJgXQq2GBhFoop24Ma3qeF3F8rw+AQw1ldGw9rwatEnXRH/L4mOZuoAE +KrQ== 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=VTFfmSh3PtwZWFi9FZ9t/kJrbRPQg2Phw+OnoZy+bTo=; b=DidfkRD+/XaXTUdB54DF0jhgUTIyOWtcn3BlgjlBRDVnaoxKx5mz5YvM3t4ysqOCDH DzFWslLswMc1JqRMyIC54JUqS8cH24x+i/kUu1yZAK0SbF2NdA4qa+NpTiWnCwgVKOqU KPnYGn3nfBqYqMSqByHLPm3CcJ11junr0eWWXeIpLPgtToFa+kTG7as3skufzh8cKh3C 2GUq8wFoIObnpL7ZSqT/pwFE2xh/yCEWtZvuKE6kZygsExcPvUYH51XJ/MNfRTr5Tze1 17mDQrpjRT7VV/BxOO1hoLH54QbqF120Zfz2OBXltaILMMeaWEacCC11NGP/bNY3MP43 bk7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=FeDX+TJ7; 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 a22si1323757jao.25.2021.03.04.20.22.22; Thu, 04 Mar 2021 20:22:35 -0800 (PST) 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=FeDX+TJ7; 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 S229701AbhCEEV3 (ORCPT + 99 others); Thu, 4 Mar 2021 23:21:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbhCEEV2 (ORCPT ); Thu, 4 Mar 2021 23:21:28 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BFD3C061574; Thu, 4 Mar 2021 20:21:28 -0800 (PST) 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=VTFfmSh3PtwZWFi9FZ9t/kJrbRPQg2Phw+OnoZy+bTo=; b=FeDX+TJ7yiCS7D3DPp2FWORI0Z 67MDf1+YHsLWiW14UZeVUfTITA8le6UqpwTPq2/duAAfwTNk97c+S4beIQfjJXCr9E2QE0Qoymwu0 ITKHEC9t7YRRWalsjC6niGbQXqk5rhE4Lk4E7bonvtdOvQNhfoYd1kKsmWogUkZyTdLt3SwBtzdSr tSbY8b2s9vrciwG8zhE1zmJVe/SxGvPbKDoT6yYCLd+a5P64/halNz5uJ0xirA7oMPov8WUBASs40 KQh7agI9n0CTMb+cCkKOstq9SYUxzBaAinloxaLESoyyQXHDyFykyib+DCZdSwfEvHflIzYxv4hCy /q7H9jEQ==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lI1wg-00A3Zj-Tw; Fri, 05 Mar 2021 04:20:22 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 08/25] mm: Handle per-folio private data Date: Fri, 5 Mar 2021 04:18:44 +0000 Message-Id: <20210305041901.2396498-9-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210305041901.2396498-1-willy@infradead.org> References: <20210305041901.2396498-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. 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 886 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) --- 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 a311cb48526f..b650423fcba6 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -258,6 +258,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) @@ -265,6 +271,16 @@ static inline void set_page_private(struct page *page, unsigned long private) page->private = private; } +static inline unsigned long folio_private(struct folio *folio) +{ + return folio->page.private; +} + +static inline void set_folio_private(struct folio *folio, unsigned long v) +{ + folio->page.private = 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 20225b067583..f07c03da83f6 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -245,42 +245,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, (unsigned long)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 = (void *)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, 0); + put_folio(folio); return data; } +static inline void attach_page_private(struct page *page, void *data) +{ + attach_folio_private((struct folio *)page, data); +} + +static inline void *detach_page_private(struct page *page) +{ + return detach_folio_private((struct folio *)page); +} + #ifdef CONFIG_NUMA extern struct page *__page_cache_alloc(gfp_t gfp); #else -- 2.30.0