On 9/13/21 9:15 AM, Alex Sierra wrote:
From: Ralph Campbell <rcampbell@xxxxxxxxxx> ZONE_DEVICE struct pages have an extra reference count that complicates the code for put_page() and several places in the kernel that need to check the reference count to see that a page is not being used (gup, compaction, migration, etc.). Clean up the code so the reference count doesn't need to be treated specially for ZONE_DEVICE. Signed-off-by: Ralph Campbell <rcampbell@xxxxxxxxxx> Signed-off-by: Alex Sierra <alex.sierra@xxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> --- v2: AS: merged this patch in linux 5.11 version v5: AS: add condition at try_grab_page to check for the zone device type, while page ref counter is checked less/equal to zero. In case of device zone, pages ref counter are initialized to zero. v7: AS: fix condition at try_grab_page added at v5, is invalid. It supposed to fix xfstests/generic/413 test, however, there's a known issue on this test where DAX mapped area DIO to non-DAX expect to fail. https://patchwork.kernel.org/project/fstests/patch/1489463960-3579-1-git-send-email-xzhou@xxxxxxxxxx This condition was removed after rebase over patch series https://lore.kernel.org/r/20210813044133.1536842-4-jhubbard@xxxxxxxxxx --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 2 +- fs/dax.c | 4 +- include/linux/dax.h | 2 +- include/linux/memremap.h | 7 +-- include/linux/mm.h | 11 ---- lib/test_hmm.c | 2 +- mm/internal.h | 8 +++ mm/memremap.c | 69 +++++++------------------- mm/migrate.c | 5 -- mm/page_alloc.c | 3 ++ mm/swap.c | 45 ++--------------- 12 files changed, 45 insertions(+), 115 deletions(-)
I don't see mm/memcontrol.c listed here so I think you will need this fragment too: diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 389b5766e74f..0cc9c7c71e79 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5541,11 +5541,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, */ if (is_device_private_entry(ent)) { page = pfn_swap_entry_to_page(ent); - /* - * MEMORY_DEVICE_PRIVATE means ZONE_DEVICE page and which have - * a refcount of 1 when free (unlike normal page) - */ - if (!page_ref_add_unless(page, 1, 1)) + if (!get_page_unless_zero(page)) return NULL; return page; }