[HMM 02/15] mm/put_page: move ZONE_DEVICE page reference decrement v2
From: JÃrÃme Glisse
Date: Mon Apr 24 2017 - 14:14:53 EST
Move page reference decrement of ZONE_DEVICE from put_page()
to put_zone_device_page() this does not affect non ZONE_DEVICE
page.
Doing this allow to catch when a ZONE_DEVICE page refcount reach
1 which means the device is no longer reference by any one (unlike
page from other zone, ZONE_DEVICE page refcount never reach 0).
This patch is just a preparatory patch for HMM.
Changes since v1:
- commit message
Signed-off-by: JÃrÃme Glisse <jglisse@xxxxxxxxxx>
Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx>
Cc: Ross Zwisler <ross.zwisler@xxxxxxxxxxxxxxx>
---
include/linux/mm.h | 14 +++++++++++---
kernel/memremap.c | 6 ++++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/include/linux/mm.h b/include/linux/mm.h
index c82e8db..022423c 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -821,11 +821,19 @@ static inline void put_page(struct page *page)
{
page = compound_head(page);
+ /*
+ * ZONE_DEVICE pages should never have their refcount reach 0 (this
+ * would be a bug), so call page_ref_dec() in put_zone_device_page()
+ * to decrement page refcount and skip __put_page() here, as this
+ * would worsen things if a ZONE_DEVICE had a refcount bug.
+ */
+ if (unlikely(is_zone_device_page(page))) {
+ put_zone_device_page(page);
+ return;
+ }
+
if (put_page_testzero(page))
__put_page(page);
-
- if (unlikely(is_zone_device_page(page)))
- put_zone_device_page(page);
}
#if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
diff --git a/kernel/memremap.c b/kernel/memremap.c
index ea714ee..97ef676 100644
--- a/kernel/memremap.c
+++ b/kernel/memremap.c
@@ -190,6 +190,12 @@ EXPORT_SYMBOL(get_zone_device_page);
void put_zone_device_page(struct page *page)
{
+ /*
+ * ZONE_DEVICE page refcount should never reach 0 and never be freed
+ * to kernel memory allocator.
+ */
+ page_ref_dec(page);
+
put_dev_pagemap(page->pgmap);
}
EXPORT_SYMBOL(put_zone_device_page);
--
2.9.3