Vector read/write support for NFS (DIO) client
Subsystems (2)
RFC PATCH 1/1 Vector read/write support for NFS (DIO) client
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (O_DIRECT) client.
Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using O_DIRECT). When guest is doing IO on these block devices, they will end up as O_DIRECT writes to NFS (on KVM host).
QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K FILE_SYNC IOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.
readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Here is the patch to add this support. Comments ?
Thanks,
Badari
Special readv/writev support for NFS O_DIRECT. Currently NFS client O_DIRECT read/write iterates over individual elements in the vector and submits the IO and waits for them to finish. If individual IOsize is < r/wsize, each IO will be FILE_SYNC. Server has to finish individual smaller IOs synchronous. This causes serious performance degrade.
This patch is a special case to submit larger IOs from the client only if all the IO buffers are page-aligned and each individual IOs are page-multiple + total IO size is < r/wsize.
This is the common case for QEMU usage.
--- fs/nfs/direct.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 259 insertions(+)
fs/nfs/direct.c +259 -0
@@ -271,6 +271,52 @@ static const struct rpc_call_ops nfs_rea .rpc_release = nfs_direct_read_release, }; +static int nfs_direct_check_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs,int rw) +{ +unsigned long seg; +int pages =0 ; +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +size_t size; + + +/* If its a single vector - use old code */ +if (nr_segs ==1 ) +return pages; +/* +* Check to see if all IO buffers are page-aligned and +* individual IO sizes are page-multiple. +* If so, we can submit them in a single IO. +* Otherwise, use old code +*/ +for (seg =0 ; seg < nr_segs; seg++) { +unsigned long user_addr = (unsigned long )iov[seg].iov_base; + +if ((user_addr & (PAGE_SIZE -1 )) || + (iov[seg].iov_len & (PAGE_SIZE -1 ))) { + pages =0 ; +break ; + } + pages += (iov[seg].iov_len >>PAGE_SHIFT ); + } + +if (rw) + size =NFS_SERVER (inode)->wsize; +else + size =NFS_SERVER (inode)->rsize; + +/* +* If IOsize > wsize/rsize, we need to split IOs into r/wsize anyway +* - fall back to old code. +*/ +if (pages > (size >>PAGE_SHIFT )) + pages =0 ; + +return pages; +} +/* * For each rsize'd chunk of the user's buffer, dispatch an NFS READ * operation. If nfs_readdata_alloc() or get_user_pages() fails,
@@ -385,6 +431,101 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient readv() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < rsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_read_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_read_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_read_data *data; + + result = -ENOMEM ; + data =nfs_readdata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,1 ,0 , &data->pagevec[mapped], +NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_readdata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->res.fattr = &data->fattr; + data->res.eof =0 ; + data->res.count = bytes; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->read_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,
@@ -396,6 +537,16 @@ static ssize_t nfs_direct_read_schedule_get_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,0 ); +if (result) { + result =nfs_direct_read_schedule_single_io (dreq, iov, nr_segs, + result, pos); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result =nfs_direct_read_schedule_segment (dreq, vec, pos);
@@ -416,6 +567,7 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_complete (dreq);return 0 ;
@@ -821,6 +973,102 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient writev() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < wsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_write_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos,int sync) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_write_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_write_data *data; + + result = -ENOMEM ; + data =nfs_writedata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,0 ,0 , &data->pagevec[mapped],NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_writedata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); +list_move_tail (&data->pages, &dreq->rewrite_list); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->args.stable = sync; + data->res.fattr = &data->fattr; + data->res.count = bytes; + data->res.verf = &data->verf; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->write_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,
@@ -832,6 +1080,16 @@ static ssize_t nfs_direct_write_scheduleget_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,1 ); +if (result) { + result =nfs_direct_write_schedule_single_io (dreq, iov, nr_segs, + result, pos, sync); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result = nfs_direct_write_schedule_segment(dreq, vec,
@@ -853,6 +1111,7 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_write_complete (dreq, dreq->inode);return 0 ;
Quoted 30 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.
Quoted 6 lines
readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
If the NFS write path is smart enough not to set FILE_SYNC when there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.
Quoted 340 lines
Thanks,
BadariSpecial readv/writev support for NFS
O_DIRECT. Currently NFS clientO_DIRECTread/write iterates over individual elements in the vector and submits the IO and waits for them to finish. If individual IOsize is < r/wsize, each IO will beFILE_SYNC. Server has to finish individual smaller IOs synchronous. This causes serious performance degrade.This patch is a special case to submit larger IOs from the client only if all the IO buffers are page-aligned and each individual IOs are page-multiple + total IO size is < r/wsize.
This is the common case for QEMU usage.
Signed-off-by Badari Pulavarty <[email protected]>---
fs/nfs/direct.c| 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 259 insertions(+)Index:
linux-2.6.38.2/fs/nfs/direct.c
===================================================================fs/nfs/direct.c +259
-1@@ -271,6 +271,52 @@ static const struct rpc_call_ops nfs_rea .rpc_release = nfs_direct_read_release, }; +static int nfs_direct_check_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs,int rw) +{ +unsigned long seg; +int pages =0 ; +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +size_t size; + + +/* If its a single vector - use old code */ +if (nr_segs ==1 ) +return pages; +/* +* Check to see if all IO buffers are page-aligned and +* individual IO sizes are page-multiple. +* If so, we can submit them in a single IO. +* Otherwise, use old code +*/ +for (seg =0 ; seg < nr_segs; seg++) { +unsigned long user_addr = (unsigned long )iov[seg].iov_base; + +if ((user_addr & (PAGE_SIZE -1 )) || + (iov[seg].iov_len & (PAGE_SIZE -1 ))) { + pages =0 ; +break ; + } + pages += (iov[seg].iov_len >>PAGE_SHIFT ); + } + +if (rw) + size =NFS_SERVER (inode)->wsize; +else + size =NFS_SERVER (inode)->rsize; + +/* +* If IOsize > wsize/rsize, we need to split IOs into r/wsize anyway +* - fall back to old code. +*/ +if (pages > (size >>PAGE_SHIFT )) + pages =0 ; + +return pages; +} +/* * For each rsize'd chunk of the user's buffer, dispatch an NFS READ * operation. If nfs_readdata_alloc() or get_user_pages() fails, @@ -385,6 +431,101 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient readv() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < rsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_read_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_read_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_read_data *data; + + result = -ENOMEM ; + data =nfs_readdata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,1 ,0 , &data->pagevec[mapped], +NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_readdata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->res.fattr = &data->fattr; + data->res.eof =0 ; + data->res.count = bytes; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->read_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -396,6 +537,16 @@ static ssize_t nfs_direct_read_schedule_get_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,0 ); +if (result) { + result =nfs_direct_read_schedule_single_io (dreq, iov, nr_segs, + result, pos); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result =nfs_direct_read_schedule_segment (dreq, vec, pos);@@ -416,6 +567,7 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_complete (dreq);return 0 ;@@ -821,6 +973,102 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient writev() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < wsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_write_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos,int sync) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_write_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_write_data *data; + + result = -ENOMEM ; + data =nfs_writedata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,0 ,0 , &data->pagevec[mapped],NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_writedata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); +list_move_tail (&data->pages, &dreq->rewrite_list); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->args.stable = sync; + data->res.fattr = &data->fattr; + data->res.count = bytes; + data->res.verf = &data->verf; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->write_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -832,6 +1080,16 @@ static ssize_t nfs_direct_write_scheduleget_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,1 ); +if (result) { + result =nfs_direct_write_schedule_single_io (dreq, iov, nr_segs, + result, pos, sync); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result = nfs_direct_write_schedule_segment(dreq, vec,@@ -853,6 +1111,7 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_write_complete (dreq, dreq->inode);return 0 ; --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 32 lines · Chuck Lever
Quoted 30 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.
Quoted 8 lines
Quoted 6 lines
readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Quoted 2 lines
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.
We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
Thanks,
Badari
Quoted 348 lines
Quoted 340 lines
Thanks,
BadariSpecial readv/writev support for NFS
O_DIRECT. Currently NFS clientO_DIRECTread/write iterates over individual elements in the vector and submits the IO and waits for them to finish. If individual IOsize is < r/wsize, each IO will beFILE_SYNC. Server has to finish individual smaller IOs synchronous. This causes serious performance degrade.This patch is a special case to submit larger IOs from the client only if all the IO buffers are page-aligned and each individual IOs are page-multiple + total IO size is < r/wsize.
This is the common case for QEMU usage.
Signed-off-by Badari Pulavarty <[email protected]>---
fs/nfs/direct.c| 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 259 insertions(+)Index:
linux-2.6.38.2/fs/nfs/direct.c
===================================================================fs/nfs/direct.c +259
-1@@ -271,6 +271,52 @@ static const struct rpc_call_ops nfs_rea .rpc_release = nfs_direct_read_release, }; +static int nfs_direct_check_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs,int rw) +{ +unsigned long seg; +int pages =0 ; +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +size_t size; + + +/* If its a single vector - use old code */ +if (nr_segs ==1 ) +return pages; +/* +* Check to see if all IO buffers are page-aligned and +* individual IO sizes are page-multiple. +* If so, we can submit them in a single IO. +* Otherwise, use old code +*/ +for (seg =0 ; seg < nr_segs; seg++) { +unsigned long user_addr = (unsigned long )iov[seg].iov_base; + +if ((user_addr & (PAGE_SIZE -1 )) || + (iov[seg].iov_len & (PAGE_SIZE -1 ))) { + pages =0 ; +break ; + } + pages += (iov[seg].iov_len >>PAGE_SHIFT ); + } + +if (rw) + size =NFS_SERVER (inode)->wsize; +else + size =NFS_SERVER (inode)->rsize; + +/* +* If IOsize > wsize/rsize, we need to split IOs into r/wsize anyway +* - fall back to old code. +*/ +if (pages > (size >>PAGE_SHIFT )) + pages =0 ; + +return pages; +} +/* * For each rsize'd chunk of the user's buffer, dispatch an NFS READ * operation. If nfs_readdata_alloc() or get_user_pages() fails, @@ -385,6 +431,101 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient readv() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < rsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_read_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_read_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_read_data *data; + + result = -ENOMEM ; + data =nfs_readdata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,1 ,0 , &data->pagevec[mapped], +NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_readdata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->res.fattr = &data->fattr; + data->res.eof =0 ; + data->res.count = bytes; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->read_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -396,6 +537,16 @@ static ssize_t nfs_direct_read_schedule_get_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,0 ); +if (result) { + result =nfs_direct_read_schedule_single_io (dreq, iov, nr_segs, + result, pos); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result =nfs_direct_read_schedule_segment (dreq, vec, pos);@@ -416,6 +567,7 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_complete (dreq);return 0 ;@@ -821,6 +973,102 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient writev() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < wsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_write_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos,int sync) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_write_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_write_data *data; + + result = -ENOMEM ; + data =nfs_writedata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,0 ,0 , &data->pagevec[mapped],NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_writedata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); +list_move_tail (&data->pages, &dreq->rewrite_list); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->args.stable = sync; + data->res.fattr = &data->fattr; + data->res.count = bytes; + data->res.verf = &data->verf; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->write_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -832,6 +1080,16 @@ static ssize_t nfs_direct_write_scheduleget_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,1 ); +if (result) { + result =nfs_direct_write_schedule_single_io (dreq, iov, nr_segs, + result, pos, sync); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result = nfs_direct_write_schedule_segment(dreq, vec,@@ -853,6 +1111,7 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_write_complete (dreq, dreq->inode);return 0 ; --To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 38 lines · Badari Pulavarty
Quoted 37 lines · Chuck Lever
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Thanks for the clarification. That means you don't also address the problem of doing multiple small segments with FILE_SYNC writes.
Quoted 7 lines
Quoted 1 line
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
The individual WRITEs should be submitted in parallel. If there is additional performance overhead, it is probably due to the small RPC slot table size. Have you tried increasing it?
Quoted 358 lines
Thanks,
BadariQuoted 336 lines
Quoted 336 lines
Thanks,
BadariSpecial readv/writev support for NFS
O_DIRECT. Currently NFS clientO_DIRECTread/write iterates over individual elements in the vector and submits the IO and waits for them to finish. If individual IOsize is < r/wsize, each IO will beFILE_SYNC. Server has to finish individual smaller IOs synchronous. This causes serious performance degrade.This patch is a special case to submit larger IOs from the client only if all the IO buffers are page-aligned and each individual IOs are page-multiple + total IO size is < r/wsize.
This is the common case for QEMU usage.
Signed-off-by Badari Pulavarty <[email protected]>---
fs/nfs/direct.c| 259 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 259 insertions(+)Index:
linux-2.6.38.2/fs/nfs/direct.c
===================================================================fs/nfs/direct.c +259
-0@@ -271,6 +271,52 @@ static const struct rpc_call_ops nfs_rea .rpc_release = nfs_direct_read_release, }; +static int nfs_direct_check_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs,int rw) +{ +unsigned long seg; +int pages =0 ; +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +size_t size; + + +/* If its a single vector - use old code */ +if (nr_segs ==1 ) +return pages; +/* +* Check to see if all IO buffers are page-aligned and +* individual IO sizes are page-multiple. +* If so, we can submit them in a single IO. +* Otherwise, use old code +*/ +for (seg =0 ; seg < nr_segs; seg++) { +unsigned long user_addr = (unsigned long )iov[seg].iov_base; + +if ((user_addr & (PAGE_SIZE -1 )) || + (iov[seg].iov_len & (PAGE_SIZE -1 ))) { + pages =0 ; +break ; + } + pages += (iov[seg].iov_len >>PAGE_SHIFT ); + } + +if (rw) + size =NFS_SERVER (inode)->wsize; +else + size =NFS_SERVER (inode)->rsize; + +/* +* If IOsize > wsize/rsize, we need to split IOs into r/wsize anyway +* - fall back to old code. +*/ +if (pages > (size >>PAGE_SHIFT )) + pages =0 ; + +return pages; +} +/* * For each rsize'd chunk of the user's buffer, dispatch an NFS READ * operation. If nfs_readdata_alloc() or get_user_pages() fails, @@ -385,6 +431,101 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient readv() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < rsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_read_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_read_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_read_data *data; + + result = -ENOMEM ; + data =nfs_readdata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,1 ,0 , &data->pagevec[mapped], +NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_readdata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->res.fattr = &data->fattr; + data->res.eof =0 ; + data->res.count = bytes; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->read_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -396,6 +537,16 @@ static ssize_t nfs_direct_read_schedule_get_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,0 ); +if (result) { + result =nfs_direct_read_schedule_single_io (dreq, iov, nr_segs, + result, pos); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result =nfs_direct_read_schedule_segment (dreq, vec, pos);@@ -416,6 +567,7 @@ static ssize_t nfs_direct_read_schedule_return result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_complete (dreq);return 0 ;@@ -821,6 +973,102 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? (ssize_t ) result : -EFAULT ; } +/* +* Special Case: Efficient writev() support - only if all the IO buffers +* in the vector are page-aligned and IO sizes are page-multiple +* + total IO size is < wsize. We can map all of the vectors together +* and submit them in a single IO instead of operating on single entry +* in the vector. +*/ +static ssize_t nfs_direct_write_schedule_single_io (struct nfs_direct_req *dreq, +const struct iovec *iov, +unsigned long nr_segs, +int pages, +loff_t pos,int sync) +{ +struct nfs_open_context *ctx = dreq->ctx; +struct inode *inode = ctx->path.dentry->d_inode; +unsigned long user_addr = (unsigned long )iov->iov_base; +size_t bytes = pages <<PAGE_SHIFT ; +struct rpc_task *task; +struct rpc_message msg = { + .rpc_cred = ctx->cred, + }; +struct rpc_task_setup task_setup_data = { + .rpc_client =NFS_CLIENT (inode), + .rpc_message = &msg, + .callback_ops = &nfs_write_direct_ops, + .workqueue = nfsiod_workqueue, + .flags =RPC_TASK_ASYNC , + }; +unsigned int pgbase; +int result; +int seg; +int mapped =0 ; +int nr_pages; +ssize_t started =0 ; +struct nfs_write_data *data; + + result = -ENOMEM ; + data =nfs_writedata_alloc (pages); +if (unlikely (!data)) +return result; + + pgbase = user_addr & ~PAGE_MASK ; + +for (seg =0 ; seg < nr_segs; seg++) { + user_addr = (unsigned long )iov[seg].iov_base; + nr_pages = iov[seg].iov_len >>PAGE_SHIFT ; + +down_read (¤t->mm->mmap_sem); + result =get_user_pages (current, current->mm, user_addr, + nr_pages,0 ,0 , &data->pagevec[mapped],NULL ); +up_read (¤t->mm->mmap_sem); +if (result <0 ) { +/* unmap what is done so far */ +nfs_direct_release_pages (data->pagevec, mapped); +nfs_writedata_free (data); +return result; + } + mapped += result; + } + +get_dreq (dreq); +list_move_tail (&data->pages, &dreq->rewrite_list); + + data->req = (struct nfs_page *) dreq; + data->inode = inode; + data->cred = msg.rpc_cred; + data->args.fh =NFS_FH (inode); + data->args.context = ctx; + data->args.offset = pos; + data->args.pgbase = pgbase; + data->args.pages = data->pagevec; + data->args.count = bytes; + data->args.stable = sync; + data->res.fattr = &data->fattr; + data->res.count = bytes; + data->res.verf = &data->verf; +nfs_fattr_init (&data->fattr); + + task_setup_data.task = &data->task; + task_setup_data.callback_data = data; + msg.rpc_argp = &data->args; + msg.rpc_resp = &data->res; +NFS_PROTO (inode)->write_setup (data, &msg); + + task =rpc_run_task (&task_setup_data); +if (IS_ERR (task)) + goto out; +rpc_put_task (task); + + started += bytes; +out: +if (started) +return started; +return result <0 ? (ssize_t ) result : -EFAULT ; +} + static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, const struct iovec *iov, unsigned long nr_segs,@@ -832,6 +1080,16 @@ static ssize_t nfs_direct_write_scheduleget_dreq (dreq); + result =nfs_direct_check_single_io (dreq, iov, nr_segs,1 ); +if (result) { + result =nfs_direct_write_schedule_single_io (dreq, iov, nr_segs, + result, pos, sync); +if (result <0 ) + goto out; + requested_bytes += result; + pos += result; + goto out; + }for (seg =0 ; seg < nr_segs; seg++) {const struct iovec *vec = &iov[seg]; result = nfs_direct_write_schedule_segment(dreq, vec,@@ -853,6 +1111,7 @@ static ssize_t nfs_direct_write_schedulereturn result <0 ? result : -EIO ; } +out:if (put_dreq (dreq))nfs_direct_write_complete (dreq, dreq->inode);return 0 ;Quoted 12 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 53 lines · Chuck Lever
Quoted 38 lines · Badari Pulavarty
Quoted 37 lines · Chuck Lever
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Thanks for the clarification. That means you don't also address the problem of doing multiple small segments with
FILE_SYNCwrites.Quoted 2 lines
Quoted 1 line
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.
Quoted 7 lines
Quoted 5 lines
We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
The individual WRITEs should be submitted in parallel. If there is additional performance overhead, it is probably due to the small RPC slot table size. Have you tried increasing it?
We haven't tried both fixes together (RPC slot increase, Turn into ASYNC). Each one individually didn't help much. We will try them together.
Thanks,
Badari
Quoted 57 lines · On Tue, 12 Apr 2011 10:46:00 -0700 Badari Pulavarty <[email protected]> wrote:
Quoted 56 lines · Chuck Lever
Quoted 38 lines · Badari Pulavarty
Quoted 37 lines · Chuck Lever
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Thanks for the clarification. That means you don't also address the problem of doing multiple small segments with
FILE_SYNCwrites.Quoted 5 lines
Quoted 1 line
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
The individual WRITEs should be submitted in parallel. If there is additional performance overhead, it is probably due to the small RPC slot table size. Have you tried increasing it?
We haven't tried both fixes together (RPC slot increase, Turn into ASYNC). Each one individually didn't help much. We will try them together.
I must have missed some of these emails, but here's the patch that Chuck mentioned and based on his suggestion. It may be reasonable as a stopgap solution until Trond's overhaul of the DIO code is complete.
With this + a larger slot table size, I would think you'd have a substantial write performance improvement. Probably not as good as if the writes were coalesced, but it should help.
Badari, if you can let us know whether this plus increasing the slot table size helps, then I'll plan to "officially" submit it. This one is against RHEL6 but it should apply to mainline kernels with a small offset.
-----------------[snip]-----------------
BZ#694309: nfs: use unstable writes for bigger groups of DIO writes
Currently, the client uses FILE_SYNC whenever it's writing less than or equal data to the wsize. This is a problem though if we have a bunch of small iovec's batched up in a single writev call. The client will iterate over them and do a single FILE_SYNC WRITE for each.
Instead, change the code to do unstable writes when we'll need to do multiple WRITE RPC's in order to satisfy the request. While we're at it, optimize away the allocation of commit_data when we aren't going to use it anyway.
--- fs/nfs/direct.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
fs/nfs/direct.c +11 -2
@@ -870,9 +870,18 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, dreq =nfs_direct_req_alloc ();if (!dreq) goto out; -nfs_alloc_commit_data (dreq); -if (dreq->commit_data ==NULL || count <= wsize) +if (count > wsize || nr_segs >1 ) +nfs_alloc_commit_data (dreq); +else + dreq->commit_data =NULL ; + +/* +* If we couldn't allocate commit data, or we'll just be doing a +* single write, then make this a NFS_FILE_SYNC write and do away +* with the commit. +*/ +if (dreq->commit_data ==NULL ) sync =NFS_FILE_SYNC ; dreq->inode = inode;
Signature · 1 line
1.7.1
Quoted 98 lines · Jeff Layton
Quoted 62 lines · On Tue, 12 Apr 2011 10:46:00 -0700 Badari Pulavarty<[email protected]> wrote:
Quoted 60 lines · Chuck Lever
Quoted 40 lines · Badari Pulavarty
Quoted 38 lines · Chuck Lever
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO< wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Thanks for the clarification. That means you don't also address the problem of doing multiple small segments with
FILE_SYNCwrites.Quoted 5 lines
Quoted 2 lines
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
The individual WRITEs should be submitted in parallel. If there is additional performance overhead, it is probably due to the small RPC slot table size. Have you tried increasing it?
We haven't tried both fixes together (RPC slot increase, Turn into ASYNC). Each one individually didn't help much. We will try them together.
I must have missed some of these emails, but here's the patch that Chuck mentioned and based on his suggestion. It may be reasonable as a stopgap solution until Trond's overhaul of the DIO code is complete.
With this + a larger slot table size, I would think you'd have a substantial write performance improvement. Probably not as good as if the writes were coalesced, but it should help.
Badari, if you can let us know whether this plus increasing the slot table size helps, then I'll plan to "officially" submit it. This one is against RHEL6 but it should apply to mainline kernels with a small offset.
-----------------[snip]-----------------
BZ#694309: nfs: use unstable writes for bigger groups of DIO writes
Currently, the client uses
FILE_SYNCwhenever it's writing less than or equal data to the wsize. This is a problem though if we have a bunch of small iovec's batched up in a single writev call. The client will iterate over them and do a singleFILE_SYNCWRITE for each.
Quoted 7 lines
Instead, change the code to do unstable writes when we'll need to do multiple WRITE RPC's in order to satisfy the request. While we're at it, optimize away the allocation of
commit_datawhen we aren't going to use it anyway.Signed-off-by Jeff Layton<[email protected]>
Khoa is running tests with this + RPC table change. Single thread performance improved, but multi-thread tests doesn't scale (I guess running out of RPC table entires even with 128 ?). He will share the results shortly.
Thanks,
Badari
Quoted 30 lines
--- fs/nfs/direct.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)fs/nfs/direct.c +11
-2@@ -870,9 +870,18 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, dreq =nfs_direct_req_alloc ();if (!dreq) goto out; -nfs_alloc_commit_data (dreq); -if (dreq->commit_data ==NULL || count<= wsize) +if (count> wsize || nr_segs>1 ) +nfs_alloc_commit_data (dreq); +else + dreq->commit_data =NULL ; + +/* +* If we couldn't allocate commit data, or we'll just be doing a +* single write, then make this a NFS_FILE_SYNC write and do away +* with the commit. +*/ +if (dreq->commit_data ==NULL ) sync =NFS_FILE_SYNC ; dreq->inode = inode;
Quoted 107 lines · On Wed, 13 Apr 2011 06:43:53 -0700 Badari Pulavarty <[email protected]> wrote:
Quoted 98 lines · Jeff Layton
Quoted 62 lines · On Tue, 12 Apr 2011 10:46:00 -0700 Badari Pulavarty<[email protected]> wrote:
Quoted 60 lines · Chuck Lever
Quoted 40 lines · Badari Pulavarty
Quoted 38 lines · Chuck Lever
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO< wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Here is the patch to add this support. Comments ?
Restricting buffer alignment requirements would be an onerous API change, IMO.
I am not suggesting an API change at all. All I am doing is, if all the IOs are aligned - we can do a fast path as we can do in a single IO request. (as if we got a single buffer). Otherwise, we do hard way as today - loop through each one and do them individually.
Thanks for the clarification. That means you don't also address the problem of doing multiple small segments with
FILE_SYNCwrites.Quoted 5 lines
Quoted 2 lines
If the NFS write path is smart enough not to set
FILE_SYNCwhen there are multiple segments to write, then the problem should be mostly fixed. I think Jeff Layton already has a patch that does this.We are trying that patch. It does improve the performance by little, but not anywhere close to doing it as a single vector/buffer.
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines
Khoa, can you share your performance data for all the suggestions/patches you tried so far ?
The individual WRITEs should be submitted in parallel. If there is additional performance overhead, it is probably due to the small RPC slot table size. Have you tried increasing it?
We haven't tried both fixes together (RPC slot increase, Turn into ASYNC). Each one individually didn't help much. We will try them together.
I must have missed some of these emails, but here's the patch that Chuck mentioned and based on his suggestion. It may be reasonable as a stopgap solution until Trond's overhaul of the DIO code is complete.
With this + a larger slot table size, I would think you'd have a substantial write performance improvement. Probably not as good as if the writes were coalesced, but it should help.
Badari, if you can let us know whether this plus increasing the slot table size helps, then I'll plan to "officially" submit it. This one is against RHEL6 but it should apply to mainline kernels with a small offset.
-----------------[snip]-----------------
BZ#694309: nfs: use unstable writes for bigger groups of DIO writes
Currently, the client uses
FILE_SYNCwhenever it's writing less than or equal data to the wsize. This is a problem though if we have a bunch of small iovec's batched up in a single writev call. The client will iterate over them and do a singleFILE_SYNCWRITE for each.Quoted 7 lines
Instead, change the code to do unstable writes when we'll need to do multiple WRITE RPC's in order to satisfy the request. While we're at it, optimize away the allocation of
commit_datawhen we aren't going to use it anyway.Signed-off-by Jeff Layton<[email protected]>
Quoted 9 lines
Khoa is running tests with this + RPC table change. Single thread performance improved,
but multi-thread tests doesn't scale (I guess running out of RPC table entires even with 128 ?).
He will share the results shortly.Thanks,
Badari
Ok, good to know.
I tend to think that the whole slot table concept needs some reconsideration anyway. Off the top of my head...
We could put the rpc_rqst's into a slabcache, and give each rpc_xprt a mempool with a minimum number of slots. Have them all be allocated with GFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.
We have the reserve_xprt stuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.
Maybe I should hack up a patchset for this...
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the SOCK_ASYNC_NOSPACE flag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.
For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
Cheers
Trond
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 11 lines · Trond Myklebust
Quoted 10 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.
Quoted 7 lines
Quoted 1 line
Maybe I should hack up a patchset for this...
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.
I am scoping the dynamic rpc_slot allocation work and plan to prototype.
-->Andy
Quoted 18 lines
For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
Cheers
TrondSignature · 11 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 13 lines · On Wed, 13 Apr 2011 10:22:13 -0400 Trond Myklebust…
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
Quoted 9 lines
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
Possibly naive question, and maybe you or Andy have scoped this out already...
Wouldn't it make more sense to allow the code to allocate rpc_rqst's as needed, and manage congestion control in reserve_xprt ? It appears that that at least is what xprt_reserve_xprt_cong is supposed to do. The TCP variant (xprt_reserve_xprt) doesn't do that currently, but we could do it there and that would seem to make for more parity between the TCP and UDP in this sense.
We could do that similarly for RDMA too. Simply keep track of how many RPCs are in flight and only allow reserving the xprt when that number hasn't crossed the max number of slots...
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 22 lines · Jeff Layton
Quoted 19 lines · On Wed, 13 Apr 2011 10:22:13 -0400 Trond Myklebust…
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.
Quoted 6 lines
Quoted 3 lines
For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
No. I don't see UDP as having much of a future in 10GigE and other high bandwidth environments (or even in 1GigE setups). Let's just leave it as it is...
Quoted 10 lines
Possibly naive question, and maybe you or Andy have scoped this out already...
Wouldn't it make more sense to allow the code to allocate rpc_rqst's as needed, and manage congestion control in
reserve_xprt? It appears that that at least is whatxprt_reserve_xprt_congis supposed to do. The TCP variant (xprt_reserve_xprt) doesn't do that currently, but we could do it there and that would seem to make for more parity between the TCP and UDP in this sense.
Quoted 3 lines
We could do that similarly for RDMA too. Simply keep track of how many RPCs are in flight and only allow reserving the xprt when that number hasn't crossed the max number of slots...
What is the point of allocating a lot of resources when you lack the bandwidth to do anything with them?
The reason for tying this to the TCP window size is to try to queue up as much data as we can possibly transmit, without eating too much out of the same GFP_ATOMIC pool of memory that the networking layer also uses.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 22 lines · Jeff Layton
Quoted 19 lines · On Wed, 13 Apr 2011 10:22:13 -0400 Trond Myklebust…
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.
Quoted 6 lines
Quoted 3 lines
For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
[andros] I look at the rpc_slot table as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate more rpc_rqsts that can fit on the wire.
Quoted 6 lines
Possibly naive question, and maybe you or Andy have scoped this out already...
Wouldn't it make more sense to allow the code to allocate rpc_rqst's as needed, and manage congestion control in
reserve_xprt?
[andros] Congestion control is not what the rpc_slot table is managing. It does need to have a minimum which experience has set at 16. It's the maximum that needs to be dynamic. Congestion control by the lower layers should work unfettered within the # of rpc_slots. Today that is not always the case when 16 slots is not enough to fill the wire, and the administrator has not changed the # of rpc_slots.
Quoted 18 lines
It appears that
that at least is whatxprt_reserve_xprt_congis supposed to do. The TCP variant (xprt_reserve_xprt) doesn't do that currently, but we could do it there and that would seem to make for more parity between the TCP and UDP in this sense.We could do that similarly for RDMA too. Simply keep track of how many RPCs are in flight and only allow reserving the xprt when that number hasn't crossed the max number of slots...
Signature · 5 lines
Jeff Layton <[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Trond Myklebust
Quoted 31 lines · Andy Adamson
Quoted 28 lines · Jeff Layton
Quoted 13 lines · On Wed, 13 Apr 2011 10:22:13 -0400 Trond Myklebust…
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
Quoted 9 lines
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
Quoted 7 lines
Quoted 4 lines
[andros] I look at the
rpc_slottable as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate morerpc_rqststhat can fit on the wire.Agreed, but as I said earlier, there is no reason to even try to use UDP on high bandwidth links, so I suggest we just leave it as-is.
I think Jeff is suggesting that all the transports should use the same logic, but UDP and RDMA should simply have fixed upper limits on their slot table size. UDP would then behave the same as before, but would share code with the others. That might be cleaner than maintaining separate slot allocation mechanisms for each transport.
In other words, share the code, but parametrize it so that UDP and RDMA have effectively fixed slot tables as before, but TCP is allowed to expand.
My two pfennig's worth.
--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
Quoted 40 lines · On Wed, 13 Apr 2011 14:47:05 -0400 Chuck Lever <[email protected]> wrote:
Quoted 37 lines · Trond Myklebust
Quoted 35 lines · Andy Adamson
Quoted 22 lines · Jeff Layton
Quoted 19 lines · On Wed, 13 Apr 2011 10:22:13 -0400 Trond Myklebust…
Quoted 11 lines · Jeff Layton
We could put the rpc_rqst's into a slabcache, and give each
rpc_xprta mempool with a minimum number of slots. Have them all be allocated withGFP_NOWAIT. If it gets a NULL pointer back, then the task can sleep on the waitqueue like it does today. Then, the clients can allocate rpc_rqst's as they need as long as memory holds out for it.We have the
reserve_xprtstuff to handle congestion control anyway so I don't really see the value in the artificial limits that the slot table provides.Maybe I should hack up a patchset for this...
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.Quoted 6 lines
Quoted 3 lines
For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
[andros] I look at the
rpc_slottable as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate morerpc_rqststhat can fit on the wire.
Quoted 7 lines
Quoted 2 lines
Agreed, but as I said earlier, there is no reason to even try to use UDP on high bandwidth links, so I suggest we just leave it as-is.
I think Jeff is suggesting that all the transports should use the same logic, but UDP and RDMA should simply have fixed upper limits on their slot table size. UDP would then behave the same as before, but would share code with the others. That might be cleaner than maintaining separate slot allocation mechanisms for each transport.
In other words, share the code, but parametrize it so that UDP and RDMA have effectively fixed slot tables as before, but TCP is allowed to expand.
That was my initial thought, but Trond has a point that there's no reason to allocate info for a call that we're not able to send.
The idea of hooking up congestion feedback from the networking layer into the slot allocation code sounds intriguing, so for now I'll stop armchair quarterbacking and just wait to see what Andy comes up with :)
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
Quoted 6 lines
Quoted 2 lines
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
[andros] I look at the
rpc_slottable as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate morerpc_rqststhat can fit on the wire.
I agree with checking for space on the link.
The above formula is a good lower bound on the maximum number of slots, but there are many times when a client could use more slots than the above formula. For example, we don't want to punish writes if rsize > wsize. Also, you have to account for the server memory, which can sometimes hold several write requests while waiting for them to be sync'd to disk, leaving the TCP buffers less than full.
Also, I think any solution should allow admins to limit the maximum number of slots. Too many slots can increase request randomness at the server, and sometimes severely reduce performance.
Dean
Quoted 31 lines
Quoted 5 lines
Possibly naive question, and maybe you or Andy have scoped this out already...
Wouldn't it make more sense to allow the code to allocate rpc_rqst's as needed, and manage congestion control in
reserve_xprt?[andros] Congestion control is not what the
rpc_slottable is managing. It does need to have a minimum which experience has set at 16. It's the maximum that needs to be dynamic. Congestion control by the lower layers should work unfettered within the # ofrpc_slots. Today that is not always the case when 16 slots is not enough to fill the wire, and the administrator has not changed the # ofrpc_slots.Quoted 6 lines
It appears that
that at least is whatxprt_reserve_xprt_congis supposed to do. The TCP variant (xprt_reserve_xprt) doesn't do that currently, but we could do it there and that would seem to make for more parity between the TCP and UDP in this sense.Quoted 10 lines
We could do that similarly for RDMA too. Simply keep track of how many RPCs are in flight and only allow reserving the xprt when that number hasn't crossed the max number of slots...
Signature · 5 lines
Jeff Layton<[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Dean
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
Quoted 6 lines
Quoted 2 lines
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
[andros] I look at the
rpc_slottable as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate morerpc_rqststhat can fit on the wire.
Quoted 8 lines
I agree with checking for space on the link.
The above formula is a good lower bound on the maximum number of slots, but there are many times when a client could use more slots than the above formula. For example, we don't want to punish writes if rsize > wsize. Also, you have to account for the server memory, which can sometimes hold several write requests while waiting for them to be sync'd to disk, leaving the TCP buffers less than full.
Err... No... On the contrary, it is a good _upper_ bound on the number of slots. There is no point in allocating a slot for an RPC request which you know you have no ability to transmit. That has nothing to do with rsize or wsize values: if the socket is backed up, it won't take more data.
Trond
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 24 lines · Trond Myklebust
Quoted 15 lines · Dean
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
This issue has come up several times recently. My preference would be to tie the availability of slots to the TCP window size, and basically say that if the
SOCK_ASYNC_NOSPACEflag is set on the socket, then we hold off allocating more slots until we get a ->write_space() callback which clears that flag.For the RDMA case, we can continue to use the current system of a fixed number of preallocated slots.
Quoted 6 lines
Quoted 2 lines
I take it then that we'd want a similar scheme for UDP as well? I guess I'm just not sure what the slot table is supposed to be for.
[andros] I look at the
rpc_slottable as a representation of the amount of data the connection to the server can handle - basically the #slots should = double the bandwidth-delay product divided by the max(rsize/wsize). For TCP, this is the window size. (ping of max MTU packet * interface bandwidth).
There is no reason to allocate morerpc_rqststhat can fit on the wire.Quoted 8 lines
I agree with checking for space on the link.
The above formula is a good lower bound on the maximum number of slots, but there are many times when a client could use more slots than the above formula. For example, we don't want to punish writes if rsize> wsize. Also, you have to account for the server memory, which can sometimes hold several write requests while waiting for them to be sync'd to disk, leaving the TCP buffers less than full.
Quoted 5 lines
Err... No... On the contrary, it is a good _upper_ bound on the number of slots. There is no point in allocating a slot for an RPC request which you know you have no ability to transmit. That has nothing to do with rsize or wsize values: if the socket is backed up, it won't take more data.
Absolutely, I'm just trying to point out that checking the SOCK_ASYNC_NOSPACE flag seems to be the only way to guarantee it won't take more data. Dean
Quoted 2 lines
Trond
Quoted 30 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.
Quoted 6 lines
readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Here is the patch to add this support. Comments ?
Your approach goes in the direction of further special-casing O_DIRECT in the NFS client. I'd like to move away from that and towards integration with the ordinary read/write codepaths so that aside from adding request coalescing, we can also enable pNFS support.
Cheers
Trond
A message that is not in the archive (sent off-list or not yet received): 1302623369.4801.28.camel-SyLVLa/[email protected]
Quoted 36 lines · Trond Myklebust
Quoted 35 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Quoted 7 lines
Quoted 1 line
Here is the patch to add this support. Comments ?
Your approach goes in the direction of further special-casing
O_DIRECTin the NFS client. I'd like to move away from that and towards integration with the ordinary read/write codepaths so that aside from adding request coalescing, we can also enable pNFS support.
I completely agree. But its a major under-taking :(
Thanks,
Badari
Quoted 39 lines · Badari Pulavarty
Quoted 38 lines · Trond Myklebust
Quoted 36 lines · Badari Pulavarty
Hi,
We recently ran into serious performance issue with NFS client. It turned out that its due to lack of readv/write support for NFS (
O_DIRECT) client.Here is our use-case:
In our cloud environment, our storage is over NFS. Files on NFS are passed as a blockdevices to the guest (using
O_DIRECT). When guest is doing IO on these block devices, they will end up asO_DIRECTwrites to NFS (on KVM host).QEMU (on the host) gets a vector from virtio-ring and submits them. Old versions of QEMU, linearized the vector it got from KVM (copied them into a buffer) and submits the buffer. So, NFS client always received a single buffer.
Later versions of QEMU, eliminated this copy and submits a vector directly using preadv/pwritev().
NFS client loops through the vector and submits each vector as separate request for each IO < wsize. In our case (negotiated wsize=1MB), for 256K IO - we get 64 vectors, each 4K. So, we end up submitting 64 4K
FILE_SYNCIOs. Server end up doing each 4K synchronously. This causes serious performance degrade. We are trying to see if the performance improves if we convert IOs to ASYNC - but our initial results doesn't look good.readv/writev support NFS client for all possible cases is hard. Instead, if all vectors are page-aligned and iosizes page-multiple - it fits the current code easily. Luckily, QEMU use-case fits these requirements.
Here is the patch to add this support. Comments ?
Quoted 7 lines
Quoted 5 lines
Your approach goes in the direction of further special-casing
O_DIRECTin the NFS client. I'd like to move away from that and towards integration with the ordinary read/write codepaths so that aside from adding request coalescing, we can also enable pNFS support.I completely agree. But its a major under-taking :(
Sure, but it is one that I'm working on. I'm just explaining why I'd prefer not to include more stop-gap O_DIRECT patches at this point. We can afford to wait for one more release cycle if it means fixing O_DIRECT once and for all.
Cheers,
Trond
Quoted 4 lines · Trond Myklebust
Your approach goes in the direction of further special-casing
O_DIRECTin the NFS client. I'd like to move away from that and towards integration with the ordinary read/write codepaths so that aside from adding request coalescing, we can also enable pNFS support.
What is the exact plan? Split the direct I/O into two passes, one to lock down the user pages and then a second one to send the pages over the wire, which is shared with the writeback code? If that's the case it should naturally allow plugging in a scheme like Badari to send pages from different iovecs in a single on the wire request - after all page cache pages are non-continuous in virtual and physical memory, too.
When do you plan to release your read/write code re-write? If it's not anytime soon how is applying Badari's patch going to hurt? Most of it probably will get reverted with a complete rewrite, but at least the logic to check which direct I/O iovecs can coalesced would stay in the new world order.
Quoted 6 lines · Christoph Hellwig
Quoted 4 lines · Trond Myklebust
Your approach goes in the direction of further special-casing
O_DIRECTin the NFS client. I'd like to move away from that and towards integration with the ordinary read/write codepaths so that aside from adding request coalescing, we can also enable pNFS support.
Quoted 7 lines
What is the exact plan? Split the direct I/O into two passes, one to lock down the user pages and then a second one to send the pages over the wire, which is shared with the writeback code? If that's the case it should naturally allow plugging in a scheme like Badari to send pages from different iovecs in a single on the wire request - after all page cache pages are non-continuous in virtual and physical memory, too.
You can't lock the user pages unfortunately: they may need to be faulted in.
What I was thinking of doing is splitting out the code in the RPC callbacks that plays around with page flags and puts the pages on the inode's dirty list so that they don't get called in the case of O_DIRECT.
I then want to attach the O_DIRECT pages to the nfsi->nfs_page_tree radix tree so that they can be tracked by the NFS layer. I'm assuming that nobody is going to be silly enough to require simultaneous writes via O_DIRECT to the same locations.
Then we can feed the O_DIRECT pages into nfs_page_async_flush() so that they share the existing page cache write coalescing and pnfs code.
The commit code will be easy to reuse too, since the requests are listed in the radix tree and so nfs_scan_list() can find and process them in the usual fashion.
The main problem that I have yet to figure out is what to do if the server flags a reboot and the requests need to be resent. One option I'm looking into is using the aio 'kick handler' to resubmit the writes. Another may be to just resend directly from the nfsiod work queue.
Quoted 5 lines
When do you plan to release your read/write code re-write? If it's not anytime soon how is applying Badari's patch going to hurt? Most of it probably will get reverted with a complete rewrite, but at least the logic to check which direct I/O iovecs can coalesced would stay in the new world order.
I'm hoping that I can do the rewrite fairly quickly once the resend problem is solved. It shouldn't be more than a couple of weeks of coding.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com