linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Fix MAP_POPULATE and mlock() for DAX
@ 2015-06-16 22:28 Toshi Kani
  2015-06-20 19:46 ` Kirill A. Shutemov
  0 siblings, 1 reply; 5+ messages in thread
From: Toshi Kani @ 2015-06-16 22:28 UTC (permalink / raw)
  To: akpm
  Cc: kirill.shutemov, willy, linux-mm, linux-fsdevel, linux-nvdimm,
	linux-kernel, Toshi Kani

DAX has the following issues in a shared or read-only private
mmap'd file.
 - mmap(MAP_POPULATE) does not pre-fault
 - mlock() fails with -ENOMEM

DAX uses VM_MIXEDMAP for mmap'd files, which do not have struct
page associated with the ranges.  Both MAP_POPULATE and mlock()
call __mm_populate(), which in turn calls __get_user_pages().
Because __get_user_pages() requires a valid page returned from
follow_page_mask(), MAP_POPULATE and mlock(), i.e. FOLL_POPULATE,
fail in the first page.

Change __get_user_pages() to proceed FOLL_POPULATE when the
translation is set but its page does not exist (-EFAULT), and
@pages is not requested.  With that, MAP_POPULATE and mlock()
set translations to the requested range and complete successfully.

MAP_POPULATE still provides a major performance improvement to
DAX as it will avoid page faults during initial access to the
pages.

mlock() continues to set VM_LOCKED to vma and populate the range.
Since there is no struct page, the range is pinned without marking
pages mlocked.

Note, MAP_POPULATE and mlock() already work for a write-able
private mmap'd file on DAX since populate_vma_page_range() breaks
COW, which allocates page caches.

Signed-off-by: Toshi Kani <toshi.kani@hp.com>
---
 mm/gup.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mm/gup.c b/mm/gup.c
index 6297f6b..16d536f 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -490,8 +490,20 @@ retry:
 			}
 			BUG();
 		}
-		if (IS_ERR(page))
+		if (IS_ERR(page)) {
+			/*
+			 * No page may be associated with VM_MIXEDMAP. Proceed
+			 * FOLL_POPULATE when the translation is set but its
+			 * page does not exist (-EFAULT), and @pages is not
+			 * requested by the caller.
+			 */
+			if ((PTR_ERR(page) == -EFAULT) && (!pages) &&
+			    (gup_flags & FOLL_POPULATE) &&
+			    (vma->vm_flags & VM_MIXEDMAP))
+				goto next_page;
+
 			return i ? i : PTR_ERR(page);
+		}
 		if (pages) {
 			pages[i] = page;
 			flush_anon_page(vma, page, start);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-23 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-16 22:28 [PATCH] mm: Fix MAP_POPULATE and mlock() for DAX Toshi Kani
2015-06-20 19:46 ` Kirill A. Shutemov
2015-06-22 20:55   ` Toshi Kani
2015-06-23 11:44     ` Kirill A. Shutemov
2015-06-23 22:10       ` Toshi Kani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).