free_devmap_managed_page has nothing to do with the code in swap.c, move it to live with the rest of the code for devmap handling. Link: https://lkml.kernel.org/r/20220210072828.2930359-5-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Logan Gunthorpe <logang@deltatee.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Tested-by: "Sierra Guiza, Alejandro (Alex)" <alex.sierra@amd.com>
Unified · Split
| @@ -1092,7 +1092,6 @@ static inline bool is_zone_movable_page(const struct page *page) · 1091 unmodified lines | ||
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | #ifdef CONFIG_DEV_PAGEMAP_OPS |
| 1095 | −void free_devmap_managed_page(struct page *page); | |
| 1096 | 1095 | DECLARE_STATIC_KEY_FALSE(devmap_managed_key); |
| 1097 | 1096 | |
| 1098 | 1097 | static inline bool page_is_devmap_managed(struct page *page) |
| @@ -501,4 +501,25 @@ void free_devmap_managed_page(struct page *page) · 500 unmodified lines | ||
| 501 | 501 | page->mapping = NULL; |
| 502 | 502 | page->pgmap->ops->page_free(page); |
| 503 | 503 | } |
| 504 | + | |
| 505 | +void put_devmap_managed_page(struct page *page) | |
| 506 | +{ | |
| 507 | + int count; | |
| 508 | + | |
| 509 | + if (WARN_ON_ONCE(!page_is_devmap_managed(page))) | |
| 510 | + return; | |
| 511 | + | |
| 512 | + count = page_ref_dec_return(page); | |
| 513 | + | |
| 514 | + /* | |
| 515 | + * devmap page refcounts are 1-based, rather than 0-based: if | |
| 516 | + * refcount is 1, then the page is free and the refcount is | |
| 517 | + * stable because nobody holds a reference on the page. | |
| 518 | + */ | |
| 519 | + if (count == 1) | |
| 520 | + free_devmap_managed_page(page); | |
| 521 | + else if (!count) | |
| 522 | + __put_page(page); | |
| 523 | +} | |
| 524 | +EXPORT_SYMBOL(put_devmap_managed_page); | |
| 504 | 525 | #endif /* CONFIG_DEV_PAGEMAP_OPS */ |
| @@ -1154,26 +1154,3 @@ void __init swap_setup(void) · 1153 unmodified lines | ||
| 1154 | 1154 | * _really_ don't want to cluster much more |
| 1155 | 1155 | */ |
| 1156 | 1156 | } |
| 1157 | − | |
| 1158 | −#ifdef CONFIG_DEV_PAGEMAP_OPS | |
| 1159 | −void put_devmap_managed_page(struct page *page) | |
| 1160 | −{ | |
| 1161 | − int count; | |
| 1162 | − | |
| 1163 | − if (WARN_ON_ONCE(!page_is_devmap_managed(page))) | |
| 1164 | − return; | |
| 1165 | − | |
| 1166 | − count = page_ref_dec_return(page); | |
| 1167 | − | |
| 1168 | − /* | |
| 1169 | − * devmap page refcounts are 1-based, rather than 0-based: if | |
| 1170 | − * refcount is 1, then the page is free and the refcount is | |
| 1171 | − * stable because nobody holds a reference on the page. | |
| 1172 | − */ | |
| 1173 | − if (count == 1) | |
| 1174 | − free_devmap_managed_page(page); | |
| 1175 | − else if (!count) | |
| 1176 | − __put_page(page); | |
| 1177 | −} | |
| 1178 | −EXPORT_SYMBOL(put_devmap_managed_page); | |
| 1179 | −#endif | |