libceph: add new iov_iter msg_data type and use it for reads
Subsystems (2)
v3 cover libceph: add new iov_iter msg_data type and use it for reads
v3:
- flesh out kerneldoc header over osd_req_op_extent_osd_data_pages
- remove export of ceph_msg_data_add_iter
v2:
- make _next handler advance the iterator in preparation for coming changes to iov_iter_get_pages
Just a respin to address some minor nits pointed out by Xiubo.
------------------------8<-------------------------
This patchset was inspired by some earlier work that David Howells did to add a similar type.
Currently, we take an iov_iter from the netfs layer, turn that into an array of pages, and then pass that to the messenger which eventually turns that back into an iov_iter before handing it back to the socket.
This patchset adds a new ceph_msg_data_type that uses an iov_iter directly instead of requiring an array of pages or bvecs. This allows us to avoid an extra allocation in the buffered read path, and should make it easier to plumb in write helpers later.
For now, this is still just a slow, stupid implementation that hands the socket layer a page at a time like the existing messenger does. It doesn't yet attempt to pass through the iov_iter directly.
I have some patches that pass the cursor's iov_iter directly to the socket in the receive path, but it requires some infrastructure that's not in mainline yet (iov_iter_scan(), for instance). It should be possible to something similar in the send path as well.
Jeff Layton (2):
libceph: add new iov_iter-based ceph_msg_data_type and
ceph_osd_data_type
ceph: use osd_req_op_extent_osd_iter for netfs reads
fs/ceph/addr.c | 18 +------ include/linux/ceph/messenger.h | 8 ++++ include/linux/ceph/osd_client.h | 4 ++ net/ceph/messenger.c | 84 +++++++++++++++++++++++++++++++++ net/ceph/osd_client.c | 27 +++++++++++ 5 files changed, 124 insertions(+), 17 deletions(-)
Signature · 1 line
2.36.1
PATCH v3 1/2 libceph: add new iov_iter-based ceph_msg_data_type and ceph_osd_data_type
Add an iov_iter to the unions in ceph_msg_data and ceph_msg_data_cursor. Instead of requiring a list of pages or bvecs, we can just use an iov_iter directly, and avoid extra allocations.
We assume that the pages represented by the iter are pinned such that they shouldn't incur page faults, which is the case for the iov_iters created by netfs.
While working on this, Al Viro informed me that he was going to change iov_iter_get_pages to auto-advance the iterator as that pattern is more or less required for ITER_PIPE anyway. We emulate that here for now by advancing in the _next op and tracking that amount in the "lastlen" field.
In the event that _next is called twice without an intervening _advance, we revert the iov_iter by the remaining lastlen before calling iov_iter_get_pages.
--- include/linux/ceph/messenger.h | 8 ++++ include/linux/ceph/osd_client.h | 4 ++ net/ceph/messenger.c | 84 +++++++++++++++++++++++++++++++++ net/ceph/osd_client.c | 27 +++++++++++ 4 files changed, 123 insertions(+)
include/linux/ceph/messenger.h +8 -0
@@ -123,6 +123,7 @@ enum ceph_msg_data_type {CEPH_MSG_DATA_BIO ,/* data source/destination is a bio list */ #endif /* CONFIG_BLOCK */CEPH_MSG_DATA_BVECS ,/* data source/destination is a bio_vec array */ + CEPH_MSG_DATA_ITER, /* data source/destination is an iov_iter */ };#ifdef CONFIG_BLOCK
@@ -224,6 +225,7 @@ struct ceph_msg_data {bool own_pages; };struct ceph_pagelist *pagelist; +struct iov_iter iter; }; };
@@ -248,6 +250,10 @@ struct ceph_msg_data_cursor {struct page *page;/* page from list */ size_t offset;/* bytes from list */ }; +struct { +struct iov_iter iov_iter; +unsigned int lastlen; + }; }; };
@@ -605,6 +611,8 @@ void ceph_msg_data_add_bio(struct ceph_msg *msg, struct ceph_bio_iter *bio_pos,#endif /* CONFIG_BLOCK */ void ceph_msg_data_add_bvecs (struct ceph_msg *msg,struct ceph_bvec_iter *bvec_pos); +void ceph_msg_data_add_iter (struct ceph_msg *msg, +struct iov_iter *iter);struct ceph_msg *ceph_msg_new2 (int type,int front_len,int max_data_items,gfp_t flags,bool can_fail);
include/linux/ceph/osd_client.h +4 -0
@@ -108,6 +108,7 @@ enum ceph_osd_data_type { CEPH_OSD_DATA_TYPE_BIO, #endif /* CONFIG_BLOCK */ CEPH_OSD_DATA_TYPE_BVECS, + CEPH_OSD_DATA_TYPE_ITER, }; struct ceph_osd_data {
@@ -131,6 +132,7 @@ struct ceph_osd_data {struct ceph_bvec_iter bvec_pos;u32 num_bvecs; }; +struct iov_iter iter; }; };
@@ -501,6 +503,8 @@ void osd_req_op_extent_osd_data_bvecs(struct ceph_osd_request *osd_req,void osd_req_op_extent_osd_data_bvec_pos (struct ceph_osd_request *osd_req,unsigned int which,struct ceph_bvec_iter *bvec_pos); +void osd_req_op_extent_osd_iter (struct ceph_osd_request *osd_req, +unsigned int which,struct iov_iter *iter); extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *, unsigned int which,
net/ceph/messenger.c +84 -0
114 lines not on this page · raw message
net/ceph/osd_client.c +27 -0
@@ -171,6 +171,13 @@ static void ceph_osd_data_bvecs_init(struct ceph_osd_data *osd_data, osd_data->num_bvecs = num_bvecs; } +static void ceph_osd_iter_init (struct ceph_osd_data *osd_data, +struct iov_iter *iter) +{ + osd_data->type =CEPH_OSD_DATA_TYPE_ITER ; + osd_data->iter = *iter; +} +static struct ceph_osd_data *osd_req_op_raw_data_in (struct ceph_osd_request *osd_req,unsigned int which) {
@@ -264,6 +271,22 @@ void osd_req_op_extent_osd_data_bvec_pos(struct ceph_osd_request *osd_req, }EXPORT_SYMBOL (osd_req_op_extent_osd_data_bvec_pos); +/** +* osd_req_op_extent_osd_iter - Set up an operation with an iterator buffer +* @osd_req: The request to set up +* @which: Index of the operation in which to set the iter +* @iter: The buffer iterator +*/ +void osd_req_op_extent_osd_iter (struct ceph_osd_request *osd_req, +unsigned int which,struct iov_iter *iter) +{ +struct ceph_osd_data *osd_data; + + osd_data =osd_req_op_data (osd_req, which, extent, osd_data); +ceph_osd_iter_init (osd_data, iter); +} +EXPORT_SYMBOL (osd_req_op_extent_osd_iter); +static void osd_req_op_cls_request_info_pagelist (struct ceph_osd_request *osd_req,unsigned int which,struct ceph_pagelist *pagelist)
@@ -346,6 +369,8 @@ static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data)#endif /* CONFIG_BLOCK */ case CEPH_OSD_DATA_TYPE_BVECS :return osd_data->bvec_pos.iter.bi_size; +case CEPH_OSD_DATA_TYPE_ITER : +return iov_iter_count (&osd_data->iter);default :WARN (true,"unrecognized data type %d\n" , (int )osd_data->type);return 0 ;
@@ -954,6 +979,8 @@ static void ceph_osdc_msg_data_add(struct ceph_msg *msg,#endif }else if (osd_data->type ==CEPH_OSD_DATA_TYPE_BVECS ) {ceph_msg_data_add_bvecs (msg, &osd_data->bvec_pos); + }else if (osd_data->type ==CEPH_OSD_DATA_TYPE_ITER ) { +ceph_msg_data_add_iter (msg, &osd_data->iter); }else {BUG_ON (osd_data->type !=CEPH_OSD_DATA_TYPE_NONE ); }
Signature · 1 line
2.36.1
PATCH v3 2/2 ceph: use osd_req_op_extent_osd_iter for netfs reads
In reply to Jeff LaytonThe netfs layer has already pinned the pages involved before calling issue_op, so we can just pass down the iter directly instead of calling iov_iter_get_pages_alloc.
Instead of having to allocate a page array, use CEPH_MSG_DATA_ITER and pass it the iov_iter directly to clone.
--- fs/ceph/addr.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
fs/ceph/addr.c +1 -17
@@ -220,7 +220,6 @@ static void finish_netfs_read(struct ceph_osd_request *req)struct ceph_osd_data *osd_data =osd_req_op_extent_osd_data (req,0 );struct netfs_io_subrequest *subreq = req->r_priv;struct ceph_osd_req_op *op = &req->r_ops[0 ]; -int num_pages;int err = req->r_result;bool sparse = (op->op ==CEPH_OSD_OP_SPARSE_READ );
@@ -242,9 +241,6 @@ static void finish_netfs_read(struct ceph_osd_request *req)__set_bit (NETFS_SREQ_CLEAR_TAIL , &subreq->flags);netfs_subreq_terminated (subreq, err, false); - - num_pages =calc_pages_for (osd_data->alignment, osd_data->length); -ceph_put_page_vector (osd_data->pages, num_pages, false);iput (req->r_inode); }
@@ -312,8 +308,6 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq)struct ceph_osd_request *req;struct ceph_vino vino =ceph_vino (inode);struct iov_iter iter; -struct page **pages; -size_t page_off;int err =0 ;u64 len = subreq->len;bool sparse =ceph_test_mount_opt (fsc,SPARSEREAD );
@@ -341,17 +335,7 @@ static void ceph_netfs_issue_read(struct netfs_io_subrequest *subreq)dout ("%s: pos=%llu orig_len=%zu len=%llu\n" , __func__, subreq->start, subreq->len, len);iov_iter_xarray (&iter,READ , &rreq->mapping->i_pages, subreq->start, len); - err =iov_iter_get_pages_alloc (&iter, &pages, len, &page_off); -if (err <0 ) { -dout ("%s: iov_ter_get_pages_alloc returned %d\n" , __func__, err); - goto out; - } - -/* should always give us a page-aligned read */ -WARN_ON_ONCE (page_off); - len = err; - -osd_req_op_extent_osd_data_pages (req,0 , pages, len,0 , false, false); +osd_req_op_extent_osd_iter (req,0 , &iter); req->r_callback = finish_netfs_read; req->r_priv = subreq; req->r_inode = inode;
Signature · 1 line
2.36.1
Quoted 38 lines · Jeff Layton
v3:
- flesh out kerneldoc header overosd_req_op_extent_osd_data_pages
- remove export ofceph_msg_data_add_iterv2:
- make_nexthandler advance the iterator in preparation for coming changes toiov_iter_get_pagesJust a respin to address some minor nits pointed out by Xiubo.
------------------------8<-------------------------
This patchset was inspired by some earlier work that David Howells did to add a similar type.
Currently, we take an
iov_iterfrom the netfs layer, turn that into an array of pages, and then pass that to the messenger which eventually turns that back into aniov_iterbefore handing it back to the socket.This patchset adds a new
ceph_msg_data_typethat uses aniov_iterdirectly instead of requiring an array of pages or bvecs. This allows us to avoid an extra allocation in the buffered read path, and should make it easier to plumb in write helpers later.For now, this is still just a slow, stupid implementation that hands the socket layer a page at a time like the existing messenger does. It doesn't yet attempt to pass through the
iov_iterdirectly.I have some patches that pass the cursor's
iov_iterdirectly to the socket in the receive path, but it requires some infrastructure that's not in mainline yet (iov_iter_scan(), for instance). It should be possible to something similar in the send path as well.Jeff Layton (2):
libceph: add new iov_iter-basedceph_msg_data_typeand
ceph_osd_data_type
ceph: useosd_req_op_extent_osd_iterfor netfs reads
Quoted 7 lines
fs/ceph/addr.c | 18 +------ include/linux/ceph/messenger.h | 8 ++++ include/linux/ceph/osd_client.h | 4 ++ net/ceph/messenger.c | 84 +++++++++++++++++++++++++++++++++ net/ceph/osd_client.c | 27 +++++++++++ 5 files changed, 124 insertions(+), 17 deletions(-)
Merged into the testing branch and will run the tests.
Thanks Jeff!
-- Xiubo
Quoted 9 lines · Jeff Layton
Currently, we take an
iov_iterfrom the netfs layer, turn that into an array of pages, and then pass that to the messenger which eventually turns that back into aniov_iterbefore handing it back to the socket.This patchset adds a new
ceph_msg_data_typethat uses aniov_iterdirectly instead of requiring an array of pages or bvecs. This allows us to avoid an extra allocation in the buffered read path, and should make it easier to plumb in write helpers later.
Quoted 8 lines
For now, this is still just a slow, stupid implementation that hands the socket layer a page at a time like the existing messenger does. It doesn't yet attempt to pass through the
iov_iterdirectly.I have some patches that pass the cursor's
iov_iterdirectly to the socket in the receive path, but it requires some infrastructure that's not in mainline yet (iov_iter_scan(), for instance). It should be possible to something similar in the send path as well.
Btw, is there any good reason to not simply replace ceph_msg_data with an iov_iter entirely?
Quoted 14 lines · Christoph Hellwig
Quoted 13 lines · Jeff Layton
Currently, we take an
iov_iterfrom the netfs layer, turn that into an array of pages, and then pass that to the messenger which eventually turns that back into aniov_iterbefore handing it back to the socket.This patchset adds a new
ceph_msg_data_typethat uses aniov_iterdirectly instead of requiring an array of pages or bvecs. This allows us to avoid an extra allocation in the buffered read path, and should make it easier to plumb in write helpers later.For now, this is still just a slow, stupid implementation that hands the socket layer a page at a time like the existing messenger does. It doesn't yet attempt to pass through the
iov_iterdirectly.
Quoted 8 lines
Quoted 4 lines
I have some patches that pass the cursor's
iov_iterdirectly to the socket in the receive path, but it requires some infrastructure that's not in mainline yet (iov_iter_scan(), for instance). It should be possible to something similar in the send path as well.Btw, is there any good reason to not simply replace
ceph_msg_datawith aniov_iterentirely?
Not really, no.
What I'd probably do is change the existing osd_req_op_* callers to use the new iov_iter msg_data type first, and then once they all were you could phase out the use of struct ceph_msg_data altogether.
Signature · 1 line
Jeff Layton <[email protected]>