ceph/libceph: add support for sparse reads to msgr2 crc codepath
Subsystems (2)
v4 cover ceph/libceph: add support for sparse reads to msgr2 crc codepath
This is a revised version of the sparse read code I posted a week or so ago. Sparse read support is required for fscrypt integration work, but may be useful on its own.
The main differences from the v3 set are a couple of small bugfixes, and the addition of a new "sparseread" mount option to force the cephfs client to use sparse reads. I also renamed the sparse_ext_len field to be sparse_ext_cnt (as suggested by Xiubo).
Ilya, at this point I'm mostly looking for feedback from you. Does this approach seem sound? If so, I'll plan to work on implementing the v2-secure and v1 codepaths next.
These patches are currently available in the 'ceph-sparse-read-v4' tag in my kernel tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git/
Jeff Layton (5):
libceph: add spinlock around osd->o_requests
libceph: define struct ceph_sparse_extent and add some helpers
libceph: add sparse read support to msgr2 crc state machine
libceph: add sparse read support to OSD client
ceph: add new mount option to enable sparse reads
fs/ceph/addr.c | 18 ++- fs/ceph/file.c | 51 ++++++- fs/ceph/super.c | 16 +- fs/ceph/super.h | 8 + include/linux/ceph/messenger.h | 29 ++++ include/linux/ceph/osd_client.h | 71 ++++++++- net/ceph/messenger.c | 1 + net/ceph/messenger_v2.c | 170 +++++++++++++++++++-- net/ceph/osd_client.c | 255 +++++++++++++++++++++++++++++++- 9 files changed, 593 insertions(+), 26 deletions(-)
Signature · 1 line
2.35.1
PATCH v4 1/5 libceph: add spinlock around osd->o_requests
In a later patch, we're going to need to search for a request in the rbtree, but taking the o_mutex is inconvenient as we already hold the con mutex at the point where we need it.
Add a new spinlock that we take when inserting and erasing entries from the o_requests tree. Search of the rbtree can be done with either the mutex or the spinlock, but insertion and removal requires both.
--- include/linux/ceph/osd_client.h | 8 +++++++- net/ceph/osd_client.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-)
include/linux/ceph/osd_client.h +7 -1
@@ -29,7 +29,12 @@ typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);#define CEPH_HOMELESS_OSD -1 -/* a given osd we're communicating with */ +/* +* A given osd we're communicating with. +* +* Note that the o_requests tree can be searched while holding the "lock" mutex +* or the "o_requests_lock" spinlock. Insertion or removal requires both! +*/ struct ceph_osd {refcount_t o_ref;struct ceph_osd_client *o_osdc;
@@ -37,6 +42,7 @@ struct ceph_osd {int o_incarnation;struct rb_node o_node;struct ceph_connection o_con; +spinlock_t o_requests_lock;struct rb_root o_requests;struct rb_root o_linger_requests;struct rb_root o_backoff_mappings;
net/ceph/osd_client.c +5 -0
@@ -1198,6 +1198,7 @@ static void osd_init(struct ceph_osd *osd) {refcount_set (&osd->o_ref,1 );RB_CLEAR_NODE (&osd->o_node); +spin_lock_init (&osd->o_requests_lock); osd->o_requests =RB_ROOT ; osd->o_linger_requests =RB_ROOT ; osd->o_backoff_mappings =RB_ROOT ;
@@ -1427,7 +1428,9 @@ static void link_request(struct ceph_osd *osd, struct ceph_osd_request *req)atomic_inc (&osd->o_osdc->num_homeless);get_osd (osd); +spin_lock (&osd->o_requests_lock);insert_request (&osd->o_requests, req); +spin_unlock (&osd->o_requests_lock); req->r_osd = osd; }
@@ -1439,7 +1442,9 @@ static void unlink_request(struct ceph_osd *osd, struct ceph_osd_request *req) req, req->r_tid); req->r_osd =NULL ; +spin_lock (&osd->o_requests_lock);erase_request (&osd->o_requests, req); +spin_unlock (&osd->o_requests_lock);put_osd (osd);if (!osd_homeless (osd))
Signature · 1 line
2.35.1
PATCH v4 2/5 libceph: define struct ceph_sparse_extent and add some helpers
In reply to Jeff LaytonWhen the OSD sends back a sparse read reply, it contains an array of these structures. Define the structure and add a couple of helpers for dealing with them.
Also add a place in struct ceph_osd_req_op to store the extent buffer, and code to free it if it's populated when the req is torn down.
--- include/linux/ceph/osd_client.h | 31 ++++++++++++++++++++++++++++++- net/ceph/osd_client.c | 13 +++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
include/linux/ceph/osd_client.h +30 -1
@@ -29,6 +29,17 @@ typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);#define CEPH_HOMELESS_OSD -1 +/* +* A single extent in a SPARSE_READ reply. +* +* Note that these come from the OSD as little-endian values. On BE arches, +* we convert them in-place after receipt. +*/ +struct ceph_sparse_extent { +u64 off; +u64 len; +} __packed; +/* * A given osd we're communicating with. *
@@ -104,6 +115,8 @@ struct ceph_osd_req_op {u64 offset, length;u64 truncate_size;u32 truncate_seq; +int sparse_ext_cnt; +struct ceph_sparse_extent *sparse_ext;struct ceph_osd_data osd_data; } extent;struct {
@@ -507,6 +520,8 @@ extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *, u32 truncate_seq, u64 truncate_size, bool use_mempool); +int ceph_alloc_sparse_ext_map (struct ceph_osd_req_op *op,int cnt); +extern void ceph_osdc_get_request (struct ceph_osd_request *req);extern void ceph_osdc_put_request (struct ceph_osd_request *req);
@@ -562,5 +577,19 @@ int ceph_osdc_list_watchers(struct ceph_osd_client *osdc,struct ceph_object_locator *oloc, struct ceph_watch_item **watchers, u32 *num_watchers); -#endif +/* Find offset into the buffer of the end of the extent map */ +static inline u64 ceph_sparse_ext_map_end (struct ceph_osd_req_op *op) +{ +struct ceph_sparse_extent *ext; + +/* No extents? No data */ +if (op->extent.sparse_ext_cnt ==0 ) +return 0 ; + + ext = &op->extent.sparse_ext[op->extent.sparse_ext_cnt -1 ]; + +return ext->off + ext->len - op->extent.offset; +} + +#endif
net/ceph/osd_client.c +13 -0
@@ -378,6 +378,7 @@ static void osd_req_op_data_release(struct ceph_osd_request *osd_req,case CEPH_OSD_OP_READ :case CEPH_OSD_OP_WRITE :case CEPH_OSD_OP_WRITEFULL : +kfree (op->extent.sparse_ext);ceph_osd_data_release (&op->extent.osd_data);break ;case CEPH_OSD_OP_CALL :
@@ -1141,6 +1142,18 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc, }EXPORT_SYMBOL (ceph_osdc_new_request); +int ceph_alloc_sparse_ext_map (struct ceph_osd_req_op *op,int cnt) +{ + op->extent.sparse_ext_cnt = cnt; + op->extent.sparse_ext =kmalloc_array (cnt, +sizeof (*op->extent.sparse_ext), +GFP_NOFS ); +if (!op->extent.sparse_ext) +return -ENOMEM ; +return 0 ; +} +EXPORT_SYMBOL (ceph_alloc_sparse_ext_map); +/* * We keep osd requests in an rbtree, sorted by ->r_tid. */
Signature · 1 line
2.35.1
PATCH v4 3/5 libceph: add sparse read support to msgr2 crc state machine
In reply to Jeff LaytonAdd support for a new sparse_read ceph_connection operation. The idea is that the client driver can define this operation use it to do special handling for incoming reads.
The alloc_msg routine will look at the request and determine whether the reply is expected to be sparse. If it is, then we'll dispatch to a different set of state machine states that will repeatedly call the driver's sparse_read op to get length and placement info for reading the extent map, and the extents themselves.
This necessitates adding some new field to some other structs:
- The msg gets a new bool to track whether it's a sparse_read request.
- A new field is added to the cursor to track the amount remaining in the current extent. This is used to cap the read from the socket into the msg_data
- Handing a revoke with all of this is particularly difficult, so I've added a new data_len_remain field to the v2 connection info, and then use that to skip that much on a revoke. We may want to expand the use of that to the normal read path as well, just for consistency's sake.
--- include/linux/ceph/messenger.h | 29 ++++++ net/ceph/messenger.c | 1 + net/ceph/messenger_v2.c | 170 +++++++++++++++++++++++++++++++-- 3 files changed, 191 insertions(+), 9 deletions(-)
include/linux/ceph/messenger.h +29 -0
@@ -17,6 +17,7 @@struct ceph_msg ;struct ceph_connection ; +struct ceph_msg_data_cursor ;/* * Ceph defines these callbacks for handling connection events.
@@ -70,6 +71,31 @@ struct ceph_connection_operations { int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt); + +/** +* sparse_read: read sparse data +* @con: connection we're reading from +* @cursor: data cursor for reading extents +* @len: len of the data that msgr should read +* @buf: optional buffer to read into +* +* This should be called more than once, each time setting up to +* receive an extent into the current cursor position, and zeroing +* the holes between them. +* +* Returns 1 if there is more data to be read, 0 if reading is +* complete, or -errno if there was an error. +* +* If @buf is set on a 1 return, then the data should be read into +* the provided buffer. Otherwise, it should be read into the cursor. +* +* The sparse read operation is expected to initialize the cursor +* with a length covering up to the end of the last extent. +*/ +int (*sparse_read)(struct ceph_connection *con, +struct ceph_msg_data_cursor *cursor, +u64 *len,char **buf); + };/* use format string %s%lld */
@@ -207,6 +233,7 @@ struct ceph_msg_data_cursor {struct ceph_msg_data *data;/* current data item */ size_t resid;/* bytes not yet consumed */ +int sr_resid;/* residual sparse_read len */ bool last_piece;/* current is last piece */ bool need_crc;/* crc update needed */ union {
@@ -252,6 +279,7 @@ struct ceph_msg {struct kref kref;bool more_to_follow;bool needs_out_seq; +bool sparse_read;int front_alloc_len;struct ceph_msgpool *pool;
@@ -396,6 +424,7 @@ struct ceph_connection_v2_info {void *conn_bufs[16 ];int conn_buf_cnt; +int data_len_remain;struct kvec in_sign_kvecs[8 ];struct kvec out_sign_kvecs[8 ];
net/ceph/messenger.c +1 -0
@@ -1034,6 +1034,7 @@ void ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor, cursor->total_resid = length; cursor->data = msg->data; + cursor->sr_resid =0 ;__ceph_msg_data_cursor_init (cursor); }
net/ceph/messenger_v2.c +161 -9
212 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v4 4/5 libceph: add sparse read support to OSD client
In reply to Jeff LaytonHave get_reply check for the presence of sparse read ops in the request and set the sparse_read boolean in the msg. That will queue the messenger layer to use the sparse read codepath instead of the normal data receive.
Add a new sparse_read operation for the OSD client, driven by its own state machine. The messenger will repeatedly call the sparse_read operation, and it will pass back the necessary info to set up to read the next extent of data, while zero-filling the sparse regions.
The state machine will stop at the end of the last extent, and will attach the extent map buffer to the ceph_osd_req_op so that the caller can use it.
--- include/linux/ceph/osd_client.h | 32 +++++ net/ceph/osd_client.c | 237 +++++++++++++++++++++++++++++++- 2 files changed, 265 insertions(+), 4 deletions(-)
include/linux/ceph/osd_client.h +32 -0
@@ -40,6 +40,36 @@ struct ceph_sparse_extent {u64 len; } __packed; +/* Sparse read state machine state values */ +enum ceph_sparse_read_state { +CEPH_SPARSE_READ_HDR =0 , +CEPH_SPARSE_READ_EXTENTS , +CEPH_SPARSE_READ_DATA_LEN , +CEPH_SPARSE_READ_DATA , +}; + +/* +* A SPARSE_READ reply is a 32-bit count of extents, followed by an array of +* 64-bit offset/length pairs, and then all of the actual file data +* concatenated after it (sans holes). +* +* Unfortunately, we don't know how long the extent array is until we've +* started reading the data section of the reply. The caller should send down +* a destination buffer for the array, but we'll alloc one if it's too small +* or if the caller doesn't. +*/ +struct ceph_sparse_read { +enum ceph_sparse_read_state sr_state;/* state machine state */ +u64 sr_req_off;/* orig request offset */ +u64 sr_req_len;/* orig request length */ +u64 sr_pos;/* current pos in buffer */ +int sr_index;/* current extent index */ +__le32 sr_datalen;/* length of actual data */ +u32 sr_count;/* extent count in reply */ +int sr_ext_len;/* length of extent array */ +struct ceph_sparse_extent *sr_extent;/* extent array */ +}; +/* * A given osd we're communicating with. *
@@ -48,6 +78,7 @@ struct ceph_sparse_extent {*/ struct ceph_osd {refcount_t o_ref; +int o_sparse_op_idx;struct ceph_osd_client *o_osdc;int o_osd;int o_incarnation;
@@ -63,6 +94,7 @@ struct ceph_osd {unsigned long lru_ttl;struct list_head o_keepalive_item;struct mutex lock; +struct ceph_sparse_read o_sparse_read; };#define CEPH_OSD_SLAB_OPS 2
net/ceph/osd_client.c +233 -4
331 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v4 5/5 ceph: add new mount option to enable sparse reads
In reply to Jeff LaytonAdd a new mount option that has the client issue sparse reads instead of normal ones. The callers now preallocate an sparse extent buffer that the libceph receive code can populate and hand back after the operation completes.
After a successful sparse read, we can't use the req->r_result value to determine the amount of data "read", so instead we set the received length to be from the end of the last extent in the buffer. Any interstitial holes will have been filled by the receive code.
--- fs/ceph/addr.c | 18 +++++++++++++++-- fs/ceph/file.c | 51 +++++++++++++++++++++++++++++++++++++++++-------- fs/ceph/super.c | 16 +++++++++++++++- fs/ceph/super.h | 8 ++++++++ 4 files changed, 82 insertions(+), 11 deletions(-)
fs/ceph/addr.c +16 -2
@@ -220,8 +220,10 @@ static void finish_netfs_read(struct ceph_osd_request *req)struct ceph_fs_client *fsc =ceph_inode_to_client (req->r_inode);struct ceph_osd_data *osd_data =osd_req_op_extent_osd_data (req,0 );struct netfs_read_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 );ceph_update_read_metrics (&fsc->mdsc->metric, req->r_start_latency, req->r_end_latency, osd_data->length, err);
@@ -230,7 +232,9 @@ static void finish_netfs_read(struct ceph_osd_request *req) subreq->len, i_size_read(req->r_inode));/* no object means success but no data */ -if (err == -ENOENT ) +if (sparse && err >=0 ) + err =ceph_sparse_ext_map_end (op); +else if (err == -ENOENT ) err =0 ;else if (err == -EBLOCKLISTED ) fsc->blocklisted = true;
@@ -311,13 +315,14 @@ static void ceph_netfs_issue_op(struct netfs_read_subrequest *subreq)size_t page_off;int err =0 ;u64 len = subreq->len; +bool sparse =ceph_test_mount_opt (fsc,SPARSEREAD );if (ci->i_inline_version !=CEPH_INLINE_NONE &&ceph_netfs_issue_op_inline (subreq))return ; req =ceph_osdc_new_request (&fsc->client->osdc, &ci->i_layout, vino, subreq->start, &len, -0 ,1 ,CEPH_OSD_OP_READ , +0 ,1 , sparse ?CEPH_OSD_OP_SPARSE_READ :CEPH_OSD_OP_READ ,CEPH_OSD_FLAG_READ | fsc->client->osdc.client->options->read_from_replica,NULL , ci->i_truncate_seq, ci->i_truncate_size, false);if (IS_ERR (req)) {
@@ -326,6 +331,15 @@ static void ceph_netfs_issue_op(struct netfs_read_subrequest *subreq) goto out; } +if (sparse) { + err =ceph_alloc_sparse_ext_map (&req->r_ops[0 ], +CEPH_SPARSE_EXT_ARRAY_INITIAL ); +if (err) { +ceph_osdc_put_request (req); + goto out; + } + } +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);
fs/ceph/file.c +43 -8
132 lines not on this page · raw message
fs/ceph/super.c +15 -1
@@ -163,6 +163,7 @@ enum { Opt_copyfrom, Opt_wsync, Opt_pagecache, + Opt_sparseread, }; enum ceph_recover_session_mode {
@@ -205,6 +206,7 @@ static const struct fs_parameter_spec ceph_mount_parameters[] = {fsparam_u32 ("wsize" , Opt_wsize),fsparam_flag_no ("wsync" , Opt_wsync),fsparam_flag_no ("pagecache" , Opt_pagecache), + fsparam_flag_no ("sparseread", Opt_sparseread), {} };
@@ -574,6 +576,12 @@ static int ceph_parse_mount_param(struct fs_context *fc,else fsopt->flags &= ~CEPH_MOUNT_OPT_NOPAGECACHE ;break ; +case Opt_sparseread: +if (result.negated) + fsopt->flags &= ~CEPH_MOUNT_OPT_SPARSEREAD ; +else + fsopt->flags |=CEPH_MOUNT_OPT_SPARSEREAD ; +break ;default :BUG (); }
@@ -708,9 +716,10 @@ static int ceph_show_options(struct seq_file *m, struct dentry *root)if (!(fsopt->flags &CEPH_MOUNT_OPT_ASYNC_DIROPS ))seq_puts (m,",wsync" ); -if (fsopt->flags &CEPH_MOUNT_OPT_NOPAGECACHE )seq_puts (m,",nopagecache" ); +if (fsopt->flags &CEPH_MOUNT_OPT_SPARSEREAD ) +seq_puts (m,",sparseread" );if (fsopt->wsize !=CEPH_MAX_WRITE_SIZE )seq_printf (m,",wsize=%u" , fsopt->wsize);
@@ -1289,6 +1298,11 @@ static int ceph_reconfigure_fc(struct fs_context *fc)else ceph_clear_mount_opt (fsc,ASYNC_DIROPS ); +if (fsopt->flags &CEPH_MOUNT_OPT_SPARSEREAD ) +ceph_set_mount_opt (fsc,SPARSEREAD ); +else +ceph_clear_mount_opt (fsc,SPARSEREAD ); +if (strcmp_null (fsc->mount_options->mon_addr, fsopt->mon_addr)) {kfree (fsc->mount_options->mon_addr); fsc->mount_options->mon_addr = fsopt->mon_addr;
fs/ceph/super.h +8 -0
@@ -43,6 +43,7 @@#define CEPH_MOUNT_OPT_NOCOPYFROM (1<<14)/* don't use RADOS 'copy-from' op */ #define CEPH_MOUNT_OPT_ASYNC_DIROPS (1<<15)/* allow async directory ops */ #define CEPH_MOUNT_OPT_NOPAGECACHE (1<<16)/* bypass pagecache altogether */ +#define CEPH_MOUNT_OPT_SPARSEREAD (1<<17)/* always do sparse reads */ #define CEPH_MOUNT_OPT_DEFAULT \ (CEPH_MOUNT_OPT_DCACHE | \
@@ -75,6 +76,13 @@#define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5/* cap release delay */ #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60/* cap release delay */ +/* +* How big an extent array should we preallocate for a sparse read? This is +* just a starting value. If we get more than this back from the OSD, the +* receiver will reallocate. +*/ +#define CEPH_SPARSE_EXT_ARRAY_INITIAL 16 +struct ceph_mount_options {unsigned int flags;
Signature · 1 line
2.35.1
Quoted 25 lines · Jeff Layton
This is a revised version of the sparse read code I posted a week or so ago. Sparse read support is required for fscrypt integration work, but may be useful on its own.
The main differences from the v3 set are a couple of small bugfixes, and the addition of a new "sparseread" mount option to force the cephfs client to use sparse reads. I also renamed the
sparse_ext_lenfield to besparse_ext_cnt(as suggested by Xiubo).Ilya, at this point I'm mostly looking for feedback from you. Does this approach seem sound? If so, I'll plan to work on implementing the v2-secure and v1 codepaths next.
These patches are currently available in the 'ceph-sparse-read-v4' tag in my kernel tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git/
Jeff Layton (5):
libceph: add spinlock aroundosd->o_requests
libceph: define structceph_sparse_extentand add some helpers
libceph: add sparse read support to msgr2 crc state machine
libceph: add sparse read support to OSD client
ceph: add new mount option to enable sparse reads
Quoted 11 lines
fs/ceph/addr.c | 18 ++- fs/ceph/file.c | 51 ++++++- fs/ceph/super.c | 16 +- fs/ceph/super.h | 8 + include/linux/ceph/messenger.h | 29 ++++ include/linux/ceph/osd_client.h | 71 ++++++++- net/ceph/messenger.c | 1 + net/ceph/messenger_v2.c | 170 +++++++++++++++++++-- net/ceph/osd_client.c | 255 +++++++++++++++++++++++++++++++- 9 files changed, 593 insertions(+), 26 deletions(-)
This patch series looks good to me.
Quoted 25 lines · Jeff Layton
This is a revised version of the sparse read code I posted a week or so ago. Sparse read support is required for fscrypt integration work, but may be useful on its own.
The main differences from the v3 set are a couple of small bugfixes, and the addition of a new "sparseread" mount option to force the cephfs client to use sparse reads. I also renamed the
sparse_ext_lenfield to besparse_ext_cnt(as suggested by Xiubo).Ilya, at this point I'm mostly looking for feedback from you. Does this approach seem sound? If so, I'll plan to work on implementing the v2-secure and v1 codepaths next.
These patches are currently available in the 'ceph-sparse-read-v4' tag in my kernel tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git/
Jeff Layton (5):
libceph: add spinlock aroundosd->o_requests
libceph: define structceph_sparse_extentand add some helpers
libceph: add sparse read support to msgr2 crc state machine
libceph: add sparse read support to OSD client
ceph: add new mount option to enable sparse reads
Quoted 11 lines
fs/ceph/addr.c | 18 ++- fs/ceph/file.c | 51 ++++++- fs/ceph/super.c | 16 +- fs/ceph/super.h | 8 + include/linux/ceph/messenger.h | 29 ++++ include/linux/ceph/osd_client.h | 71 ++++++++- net/ceph/messenger.c | 1 + net/ceph/messenger_v2.c | 170 +++++++++++++++++++-- net/ceph/osd_client.c | 255 +++++++++++++++++++++++++++++++- 9 files changed, 593 insertions(+), 26 deletions(-)
I've pushed this series into a new branch in the ceph tree called "wip-sparseread", if anyone wants to test it. Note that ms_mode=secure and ms_mode=legacy settings do not work properly with sparse reads yet.
Signature · 1 line
Jeff Layton <[email protected]>