lkml.org 
[lkml]   [2023]   [Feb]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] splice: Clean up direct_splice_read() a bit
    Date
    How about the attached?  I won't fold it down for the moment, but it could be
    pushed along later.

    David
    ---
    splice: Clean up direct_splice_read() a bit

    Do a couple of cleanups to direct_splice_read():

    (1) Cast to struct page **, not void *.

    (2) Simplify the calculation of the number of pages to keep/reclaim in
    direct_splice_read().

    Suggested-by: Christoph Hellwig <hch@infradead.org>
    Signed-off-by: David Howells <dhowells@redhat.com>
    cc: Christoph Hellwig <hch@lst.de>
    cc: Jens Axboe <axboe@kernel.dk>
    cc: Al Viro <viro@zeniv.linux.org.uk>
    cc: David Hildenbrand <david@redhat.com>
    cc: John Hubbard <jhubbard@nvidia.com>
    cc: linux-mm@kvack.org
    cc: linux-block@vger.kernel.org
    cc: linux-fsdevel@vger.kernel.org

    diff --git a/fs/splice.c b/fs/splice.c
    index 9e798c901087..572d3e2a669a 100644
    --- a/fs/splice.c
    +++ b/fs/splice.c
    @@ -295,7 +295,7 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos,
    struct kiocb kiocb;
    struct page **pages;
    ssize_t ret;
    - size_t used, npages, chunk, remain, reclaim;
    + size_t used, npages, chunk, remain, keep = 0;
    int i;

    /* Work out how much data we can actually add into the pipe */
    @@ -332,11 +332,8 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos,
    kiocb.ki_pos = *ppos;
    ret = call_read_iter(in, &kiocb, &to);

    - reclaim = npages * PAGE_SIZE;
    - remain = 0;
    if (ret > 0) {
    - reclaim -= ret;
    - remain = ret;
    + keep = DIV_ROUND_UP(ret, PAGE_SIZE);
    *ppos = kiocb.ki_pos;
    file_accessed(in);
    } else if (ret < 0) {
    @@ -349,14 +346,12 @@ ssize_t direct_splice_read(struct file *in, loff_t *ppos,
    }

    /* Free any pages that didn't get touched at all. */
    - reclaim /= PAGE_SIZE;
    - if (reclaim) {
    - npages -= reclaim;
    - release_pages(pages + npages, reclaim);
    - }
    + if (keep < npages)
    + release_pages(pages + keep, npages - keep);

    /* Push the remaining pages into the pipe. */
    - for (i = 0; i < npages; i++) {
    + remain = ret;
    + for (i = 0; i < keep; i++) {
    struct pipe_buffer *buf = pipe_head_buf(pipe);

    chunk = min_t(size_t, remain, PAGE_SIZE);
    \
     
     \ /
      Last update: 2023-03-27 00:24    [W:4.893 / U:0.552 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site