lkml.org 
[lkml]   [2017]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[HMM 02/16] mm/put_page: move ZONE_DEVICE page reference decrement v2
Date
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@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
---
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 0860a2b..92db0fb 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -813,11 +813,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 6b4505d..0228a01 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
\
 
 \ /
  Last update: 2017-04-05 22:43    [W:0.209 / U:9.180 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site