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@xxxxxxxxxx> > Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx> > > --- ... > -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