Skip to contentSkip to conversation

use a nocache copy for bvecs in copy_from_iter_nocache()

PATCH Superseded Brian Boylston 3 participants 4 messages Oct 7, 2016 – Oct 11, 2016

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use a nocache copy for bvecs in copy_from_iter_nocache()

copy_from_iter_nocache() is only "nocache" for iovecs. Enhance it to also use a nocache copy for bvecs. This improves performance by 2-3X when splice()ing to a file in a DAX-mounted, pmem-backed file system.

Cc Ross Zwisler <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Al Viro <[email protected]>
Cc Dan Williams <[email protected]>
---
 arch/x86/include/asm/pmem.h |  6 +++---
 lib/iov_iter.c              | 11 +++++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)
arch/x86/include/asm/pmem.h +3 -3
index 643eba4..d071f45c 100644
@@ -73,12 +73,12 @@ static inline void arch_wb_cache_pmem(void *addr, size_t size)
 }
 
 /*
- * copy_from_iter_nocache() on x86 only uses non-temporal stores for iovec
- * iterators, so for other types (bvec & kvec) we must do a cache write-back.
+ * copy_from_iter_nocache() on x86 uses non-temporal stores for iovec and
+ * bvec iterators, but for kvec we must do a cache write-back.
  */
 static inline bool __iter_needs_pmem_wb(struct iov_iter *i)
 {
-	return iter_is_iovec(i) == false;
+	return (i->type & ITER_KVEC) == ITER_KVEC;
 }
 
 /**
lib/iov_iter.c +9 -2
index 7e3138c..df4cb00 100644
@@ -342,6 +342,13 @@ static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t
 	kunmap_atomic(from);
 }
 
+static void memcpy_from_page_nocache(char *to, struct page *page, size_t offset, size_t len)
+{
+	char *from = kmap_atomic(page);
+	__copy_from_user_inatomic_nocache(to, from, len);
+	kunmap_atomic(from);
+}
+
 static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len)
 {
 	char *to = kmap_atomic(page);
@@ -392,8 +399,8 @@ size_t copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i)
 	iterate_and_advance(i, bytes, v,
 		__copy_from_user_nocache((to += v.iov_len) - v.iov_len,
 					 v.iov_base, v.iov_len),
-		memcpy_from_page((to += v.bv_len) - v.bv_len, v.bv_page,
-				 v.bv_offset, v.bv_len),
+		memcpy_from_page_nocache((to += v.bv_len) - v.bv_len,
+					 v.bv_page, v.bv_offset, v.bv_len),
 		memcpy((to += v.iov_len) - v.iov_len, v.iov_base, v.iov_len)
 	)
 
Signature · 6 lines
1.8.3.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
maintainer
#1 lore raw

lib/iov_iter.c static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t · line 350

Quoted 10 lines · Brian Boylston

copy_from_iter_nocache() is only "nocache" for iovecs. Enhance it to also use a nocache copy for bvecs. This improves performance by 2-3X when splice()ing to a file in a DAX-mounted, pmem-backed file system.

lib/iov_iter.c +6 -0
+static void memcpy_from_page_nocache(char *to, struct page *page, size_t offset, size_t len)
+{
+	char *from = kmap_atomic(page);
+	__copy_from_user_inatomic_nocache(to, from, len);
+	kunmap_atomic(from);
+}

At the very least, it will blow up on any architecture with split userland and kernel MMU contexts. You *can't* feed a kernel pointer to things like that and expect it to work. At the very least, you need to add memcpy_nocache() and have it default to memcpy(), with non-dummy version on x86. And use _that_, rather than messing with __copy_from_user_inatomic_nocache()
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 8 lines · Al Viro
Quoted 7 lines · Brian Boylston

copy_from_iter_nocache() is only "nocache" for iovecs.  Enhance it to also use a nocache copy for bvecs.  This improves performance by 2-3X when splice()ing to a file in a DAX-mounted, pmem-backed file system.

Quoted 14 lines

lib/iov_iter.c static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t · line 350

Quoted 7 lines

+static void memcpy_from_page_nocache(char *to, struct page *page, size_t offset, size_t len)

lib/iov_iter.c +5 -0
+{
+	char *from = kmap_atomic(page);
+	__copy_from_user_inatomic_nocache(to, from, len);
+	kunmap_atomic(from);
+}

At the very least, it will blow up on any architecture with split userland and kernel MMU contexts.  You *can't* feed a kernel pointer to things like that and expect it to work.  At the very least, you need to add memcpy_nocache() and have it default to memcpy(), with non-dummy version on x86.  And use _that_, rather than messing with __copy_from_user_inatomic_nocache()

Good point.  I think we can add memcpy_nocache() which calls __copy_from_user_inatomic_nocache() on x86 and defauts to memcpy() on other architectures.

Thanks,
-Toshi
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw

Kani, Toshimitsu wrote on 2016-10-10:

Quoted 24 lines · Al Viro
Quoted 8 lines · Brian Boylston
Quoted 7 lines

copy_from_iter_nocache() is only "nocache" for iovecs.  Enhance it to also use a nocache copy for bvecs.  This improves performance by 2-3X when splice()ing to a file in a DAX-mounted, pmem-backed file system.

Quoted 14 lines

lib/iov_iter.c static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t · line 350

Quoted 7 lines

+static void memcpy_from_page_nocache(char *to, struct page *page, size_t offset, size_t len)

lib/iov_iter.c +5 -0
+{
+	char *from = kmap_atomic(page);
+	__copy_from_user_inatomic_nocache(to, from, len);
+	kunmap_atomic(from);
+}

At the very least, it will blow up on any architecture with split userland and kernel MMU contexts.  You *can't* feed a kernel pointer to things like that and expect it to work.  At the very least, you need to add memcpy_nocache() and have it default to memcpy(), with non-dummy version on x86.  And use _that_, rather than messing with __copy_from_user_inatomic_nocache()

Quoted 3 lines

Good point.  I think we can add memcpy_nocache() which calls __copy_from_user_inatomic_nocache() on x86 and defauts to memcpy() on other architectures.

Thanks, Al and Toshi, for the feedback. I'll re-work and come back.

Brian

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm