Re: [RFC][PATCH] iov_iter: Add ITER_MAPPING
From: David Howells
Date: Fri Jan 24 2020 - 09:59:03 EST
Okay, so this then?
#define iterate_mapping(i, n, __v, skip, STEP) { \
struct page *page; \
size_t wanted = n, seg, offset; \
loff_t start = i->mapping_start + skip; \
pgoff_t index = start >> PAGE_SHIFT; \
\
XA_STATE(xas, &i->mapping->i_pages, index); \
\
rcu_read_lock(); \
for (page = xas_load(&xas); page; page = xas_next(&xas)) { \
if (xas_retry(&xas, page)) \
continue; \
if (WARN_ON(xa_is_value(page))) \
break; \
if (WARN_ON(PageHuge(page))) \
break; \
__v.bv_page = find_subpage(page, xas.xa_index); \
offset = (i->mapping_start + skip) & ~PAGE_MASK; \
seg = PAGE_SIZE - offset; \
__v.bv_offset = offset; \
__v.bv_len = min(n, seg); \
(void)(STEP); \
n -= __v.bv_len; \
skip += __v.bv_len; \
if (n == 0) \
break; \
} \
rcu_read_unlock(); \
n = wanted - n; \
}
> We could also have an ITER_XARRAY which you just pass &mapping->i_pages
> to. I don't think you use any other part of the mapping, so that would
> be a more generic version that is equally efficient.
I could give that a go. Out of interest, are there any other users of xarray
that might use it that don't have a mapping handy?
David