2018-12-17 00:08:40

by Long Li

[permalink] [raw]
Subject: [PATCH] CIFS: use the correct length when pinning memory for direct I/O for write

From: Long Li <[email protected]>

The current code attempts to pin memory using the largest possible wsize
based on the currect SMB credits. This doesn't cause kernel oops but this is
not optimal as we may pin more pages then actually needed.

Fix this by only pinning what are needed for doing this write I/O.

Signed-off-by: Long Li <[email protected]>
Cc: [email protected]
---
fs/cifs/file.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 3467351..c23bf9d 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -2617,11 +2617,13 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
if (rc)
break;

+ cur_len = min_t(const size_t, len, wsize);
+
if (ctx->direct_io) {
ssize_t result;

result = iov_iter_get_pages_alloc(
- from, &pagevec, wsize, &start);
+ from, &pagevec, cur_len, &start);
if (result < 0) {
cifs_dbg(VFS,
"direct_writev couldn't get user pages "
--
2.7.4



2018-12-17 01:12:54

by Joey Pabalinas

[permalink] [raw]
Subject: Re: [PATCH] CIFS: use the correct length when pinning memory for direct I/O for write

On Sun, Dec 16, 2018 at 11:17:04PM +0000, Long Li wrote:
> From: Long Li <[email protected]>
>
> The current code attempts to pin memory using the largest possible wsize
> based on the currect SMB credits. This doesn't cause kernel oops but this is
> not optimal as we may pin more pages then actually needed.
>
> Fix this by only pinning what are needed for doing this write I/O.
>
> Signed-off-by: Long Li <[email protected]>
> Cc: [email protected]

Looks sane to me.

Reviewed-by: Joey Pabalinas <[email protected]>

> ---
> fs/cifs/file.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 3467351..c23bf9d 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -2617,11 +2617,13 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
> if (rc)
> break;
>
> + cur_len = min_t(const size_t, len, wsize);
> +
> if (ctx->direct_io) {
> ssize_t result;
>
> result = iov_iter_get_pages_alloc(
> - from, &pagevec, wsize, &start);
> + from, &pagevec, cur_len, &start);
> if (result < 0) {
> cifs_dbg(VFS,
> "direct_writev couldn't get user pages "
> --
> 2.7.4
>

--
Cheers,
Joey Pabalinas


Attachments:
(No filename) (1.26 kB)
signature.asc (849.00 B)
Download all attachments

2018-12-18 05:08:09

by Steve French

[permalink] [raw]
Subject: Re: [PATCH] CIFS: use the correct length when pinning memory for direct I/O for write

merged into cifs-2.6.git for-next

On Sun, Dec 16, 2018 at 5:18 PM Long Li <[email protected]> wrote:
>
> From: Long Li <[email protected]>
>
> The current code attempts to pin memory using the largest possible wsize
> based on the currect SMB credits. This doesn't cause kernel oops but this is
> not optimal as we may pin more pages then actually needed.
>
> Fix this by only pinning what are needed for doing this write I/O.
>
> Signed-off-by: Long Li <[email protected]>
> Cc: [email protected]
> ---
> fs/cifs/file.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index 3467351..c23bf9d 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -2617,11 +2617,13 @@ cifs_write_from_iter(loff_t offset, size_t len, struct iov_iter *from,
> if (rc)
> break;
>
> + cur_len = min_t(const size_t, len, wsize);
> +
> if (ctx->direct_io) {
> ssize_t result;
>
> result = iov_iter_get_pages_alloc(
> - from, &pagevec, wsize, &start);
> + from, &pagevec, cur_len, &start);
> if (result < 0) {
> cifs_dbg(VFS,
> "direct_writev couldn't get user pages "
> --
> 2.7.4
>


--
Thanks,

Steve