[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAASaF6xHTv6iZd5ttHOJ_M=hpjaGZOnUCGSHkbGy_yLbe2G8nw@mail.gmail.com>
Date: Wed, 18 Oct 2023 16:32:19 +0200
From: Jan Stancek <jstancek@...hat.com>
To: Christoph Hellwig <hch@....de>
Cc: djwong@...nel.org, willy@...radead.org, linux-xfs@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
viro@...iv.linux.org.uk
Subject: Re: [PATCH] iomap: fix short copy in iomap_write_iter()
On Wed, Oct 18, 2023 at 2:22 PM Christoph Hellwig <hch@....de> wrote:
>
> On Wed, Oct 18, 2023 at 10:24:20AM +0200, Jan Stancek wrote:
> > Make next iteration retry with amount of bytes we managed to copy.
>
> The observation and logic fix look good. But I wonder if simply
> using a goto instead of the extra variable would be a tad cleaner?
> Something like this?
Looks good to me. Would you be OK if I re-posted it as v2 with your
Signed-off-by added?
>
> ---
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index 061f3d14c12001..2d491590795aa4 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -881,8 +881,10 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
> size_t bytes; /* Bytes to write to folio */
> size_t copied; /* Bytes copied from user */
>
> + bytes = iov_iter_count(i);
> +retry:
> offset = pos & (chunk - 1);
> - bytes = min(chunk - offset, iov_iter_count(i));
> + bytes = min(chunk - offset, bytes);
> status = balance_dirty_pages_ratelimited_flags(mapping,
> bdp_flags);
> if (unlikely(status))
> @@ -933,10 +935,12 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i)
> * halfway through, might be a race with munmap,
> * might be severe memory pressure.
> */
> - if (copied)
> - bytes = copied;
> if (chunk > PAGE_SIZE)
> chunk /= 2;
> + if (copied) {
> + bytes = copied;
> + goto retry;
> + }
> } else {
> pos += status;
> written += status;
>
Powered by blists - more mailing lists