iov_iter: Convert iter_xarray to use folios

Take advantage of how kmap_local_folio() works to simplify the loop.
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarWilliam Kucharski <william.kucharski@oracle.com>
parent d9c19d32
...@@ -69,42 +69,40 @@ ...@@ -69,42 +69,40 @@
#define iterate_xarray(i, n, base, len, __off, STEP) { \ #define iterate_xarray(i, n, base, len, __off, STEP) { \
__label__ __out; \ __label__ __out; \
size_t __off = 0; \ size_t __off = 0; \
struct page *head = NULL; \ struct folio *folio; \
loff_t start = i->xarray_start + i->iov_offset; \ loff_t start = i->xarray_start + i->iov_offset; \
unsigned offset = start % PAGE_SIZE; \
pgoff_t index = start / PAGE_SIZE; \ pgoff_t index = start / PAGE_SIZE; \
int j; \
\
XA_STATE(xas, i->xarray, index); \ XA_STATE(xas, i->xarray, index); \
\ \
len = PAGE_SIZE - offset_in_page(start); \
rcu_read_lock(); \ rcu_read_lock(); \
xas_for_each(&xas, head, ULONG_MAX) { \ xas_for_each(&xas, folio, ULONG_MAX) { \
unsigned left; \ unsigned left; \
if (xas_retry(&xas, head)) \ size_t offset; \
if (xas_retry(&xas, folio)) \
continue; \ continue; \
if (WARN_ON(xa_is_value(head))) \ if (WARN_ON(xa_is_value(folio))) \
break; \ break; \
if (WARN_ON(PageHuge(head))) \ if (WARN_ON(folio_test_hugetlb(folio))) \
break; \ break; \
for (j = (head->index < index) ? index - head->index : 0; \ offset = offset_in_folio(folio, start + __off); \
j < thp_nr_pages(head); j++) { \ while (offset < folio_size(folio)) { \
void *kaddr = kmap_local_page(head + j); \ base = kmap_local_folio(folio, offset); \
base = kaddr + offset; \
len = PAGE_SIZE - offset; \
len = min(n, len); \ len = min(n, len); \
left = (STEP); \ left = (STEP); \
kunmap_local(kaddr); \ kunmap_local(base); \
len -= left; \ len -= left; \
__off += len; \ __off += len; \
n -= len; \ n -= len; \
if (left || n == 0) \ if (left || n == 0) \
goto __out; \ goto __out; \
offset = 0; \ offset += len; \
len = PAGE_SIZE; \
} \ } \
} \ } \
__out: \ __out: \
rcu_read_unlock(); \ rcu_read_unlock(); \
i->iov_offset += __off; \ i->iov_offset += __off; \
n = __off; \ n = __off; \
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment