Thread (32 messages) 32 messages, 4 authors, 2025-02-17

Re: [PATCH v7 19/20] fs/dax: Properly refcount fs dax pages

flat view

From: Guenter Roeck <linux@roeck-us.net>
Date: 2025-02-06 21:06:32
Also in: linux-arm-kernel, linux-cxl, linux-doc, linux-ext4, linux-fsdevel, linux-mm, linux-xfs, lkml, loongarch, nvdimm

On Wed, Feb 05, 2025 at 09:48:16AM +1100, Alistair Popple wrote:
Currently fs dax pages are considered free when the refcount drops to
one and their refcounts are not increased when mapped via PTEs or
decreased when unmapped. This requires special logic in mm paths to
detect that these pages should not be properly refcounted, and to
detect when the refcount drops to one instead of zero.

On the other hand get_user_pages(), etc. will properly refcount fs dax
pages by taking a reference and dropping it when the page is
unpinned.

Tracking this special behaviour requires extra PTE bits
(eg. pte_devmap) and introduces rules that are potentially confusing
and specific to FS DAX pages. To fix this, and to possibly allow
removal of the special PTE bits in future, convert the fs dax page
refcounts to be zero based and instead take a reference on the page
each time it is mapped as is currently the case for normal pages.

This may also allow a future clean-up to remove the pgmap refcounting
that is currently done in mm/gup.c.

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Reviewed-by: Dan Williams <redacted>

---
...
quoted hunk ↗ jump to hunk
-static inline unsigned long dax_page_share_put(struct page *page)
+static inline unsigned long dax_folio_put(struct folio *folio)
 {
-	WARN_ON_ONCE(!page->share);
-	return --page->share;
+	unsigned long ref;
+
+	if (!dax_folio_is_shared(folio))
+		ref = 0;
+	else
+		ref = --folio->share;
+
+	WARN_ON_ONCE(ref < 0);
Kind of unlikely for an unsigned long to ever be < 0.

[ thanks to coverity for noticing ]

Guenter
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help