Message ID | 20220110042406.499429-13-willy@infradead.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Convert GUP to folios | expand |
On Mon, Jan 10, 2022 at 04:23:50AM +0000, Matthew Wilcox (Oracle) wrote: > This is like folio_put(), but puts N references at once instead of > just one. It's like put_page_refs(), but does one atomic operation > instead of two, and is available to more than just gup.c. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Looks good, Reviewed-by: Christoph Hellwig <hch@lst.de>
On 1/9/22 20:23, Matthew Wilcox (Oracle) wrote: > This is like folio_put(), but puts N references at once instead of > just one. It's like put_page_refs(), but does one atomic operation > instead of two, and is available to more than just gup.c. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> > --- > include/linux/mm.h | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 598be27d4d2e..bf9624ca61c3 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -1234,6 +1234,26 @@ static inline void folio_put(struct folio *folio) > __put_page(&folio->page); > } > > +/** > + * folio_put_refs - Reduce the reference count on a folio. > + * @folio: The folio. > + * @refs: The number of references to reduce. Tiny rewording suggestion, if you end up sending another version: * @refs: The amount to subtract from the folio's reference count. > + * > + * If the folio's reference count reaches zero, the memory will be > + * released back to the page allocator and may be used by another > + * allocation immediately. Do not access the memory or the struct folio > + * after calling folio_put_refs() unless you can be sure that these weren't > + * the last references. > + * > + * Context: May be called in process or interrupt context, but not in NMI > + * context. May be called while holding a spinlock. > + */ > +static inline void folio_put_refs(struct folio *folio, int refs) > +{ > + if (folio_ref_sub_and_test(folio, refs)) > + __put_page(&folio->page); > +} > + > static inline void put_page(struct page *page) > { > struct folio *folio = page_folio(page); Reviewed-by: John Hubbard <jhubbard@nvidia.com> thanks,
diff --git a/include/linux/mm.h b/include/linux/mm.h index 598be27d4d2e..bf9624ca61c3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1234,6 +1234,26 @@ static inline void folio_put(struct folio *folio) __put_page(&folio->page); } +/** + * folio_put_refs - Reduce the reference count on a folio. + * @folio: The folio. + * @refs: The number of references to reduce. + * + * If the folio's reference count reaches zero, the memory will be + * released back to the page allocator and may be used by another + * allocation immediately. Do not access the memory or the struct folio + * after calling folio_put_refs() unless you can be sure that these weren't + * the last references. + * + * Context: May be called in process or interrupt context, but not in NMI + * context. May be called while holding a spinlock. + */ +static inline void folio_put_refs(struct folio *folio, int refs) +{ + if (folio_ref_sub_and_test(folio, refs)) + __put_page(&folio->page); +} + static inline void put_page(struct page *page) { struct folio *folio = page_folio(page);
This is like folio_put(), but puts N references at once instead of just one. It's like put_page_refs(), but does one atomic operation instead of two, and is available to more than just gup.c. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- include/linux/mm.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)