History

iov_iter: add ITER_BVEC_FLAG_NO_REF flag

For ITER_BVEC, if we're holding on to kernel pages, the caller doesn't need to grab a reference to the bvec pages, and drop that same reference on IO completion. This is essentially safe for any ITER_BVEC, but some use cases end up reusing pages and uncondtionally dropping a page reference on completion. And example of that is sendfile(2), that ends up being a splice_in + splice_out on the pipe pages. Add a flag that tells us it's fine to not grab a page reference to the bvec pages, since that caller knows not to drop a reference when it's done with the pages.

Jens Axboe committed 7 years ago

Commit 875f1d01 parent bf33a762 files · +22 −5Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/uio.h+19−5
@@ -23,14 +23,23 @@ struct kvec { · 22 unmodified lines
2323 };
2424
2525 enum iter_type {
26− ITER_IOVEC = 0,
27− ITER_KVEC = 2,
28− ITER_BVEC = 4,
29− ITER_PIPE = 8,
30− ITER_DISCARD = 16,
26+ /* set if ITER_BVEC doesn't hold a bv_page ref */
27+ ITER_BVEC_FLAG_NO_REF = 2,
28+
29+ /* iter types */
30+ ITER_IOVEC = 4,
31+ ITER_KVEC = 8,
32+ ITER_BVEC = 16,
33+ ITER_PIPE = 32,
34+ ITER_DISCARD = 64,
3135 };
3236
3337 struct iov_iter {
38+ /*
39+ * Bit 0 is the read/write bit, set if we're writing.
40+ * Bit 1 is the BVEC_FLAG_NO_REF bit, set if type is a bvec and
41+ * the caller isn't expecting to drop a page reference when done.
42+ */
3443 unsigned int type;
3544 size_t iov_offset;
3645 size_t count;
@@ -84,6 +93,11 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i) · 47 unmodified lines
8493 return i->type & (READ | WRITE);
8594 }
8695
96+static inline bool iov_iter_bvec_no_ref(const struct iov_iter *i)
97+{
98+ return (i->type & ITER_BVEC_FLAG_NO_REF) != 0;
99+}
100+
87101 /*
88102 * Total number of bytes covered by an iovec.
89103 *

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t