mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Jens Axboe <axboe@suse.de>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org
Subject: Re: [PATCH][RFC] splice support
Date: Wed, 29 Mar 2006 14:37:58 -0800	[thread overview]
Message-ID: <20060329143758.607c1ccc.akpm@osdl.org> (raw)
In-Reply-To: <20060329122841.GC8186@suse.de>

Jens Axboe <axboe@suse.de> wrote:
>
> Hi,
> 
> Since my initial posting back in December, I've had some private queries
> about the state of splice support. The state was pretty much that it was
> a little broken, if one attempted to do file | file splicing. The
> original patch migrated pages from one file to another in this case,
> which got vm ugly really quickly. And it wasn't always the right thing
> to do, since it would mean that splicing file1 to file2 would move
> file1's page cache to file2. Sometimes this is what you want, sometimes
> it is not.
> 
> So that was removed to make things work fully. It can later be
> reintroduced (and controlled with the splice flags passed in, whether to
> 'loan' or 'gift' source pages to use a McVoy term) if need be.
> 
> Apart from that change, I added splice to socket support. It then
> becomes a full sendfile() replacement (unless I broke something). I'm
> attaching the current patch against 2.6.16-git, and also three test apps
> that you can use as a reference or just to play with this. The apps are:
> 

- splice() take a size_t length.  Should it be taking a 64-bit length?

- splice() doesn't check for (len < 0), like read() and write() do. 
  Should it?

- Please don't call it `len'.  VFS has to deal with "lengths" which can
  be in units of PAGE_CACHE_SIZE, fs blocksize, 512-bytes sectors or bytes,
  and it gets confusing.  Our liking for variable names like `len' and
  `count' just makes it worse.

  If it's in units of pages then call it `npages'.  If it's in bytes then
  call it `nbytes'.

  What _is_ it in units of, anyway?  I guess bytes, since it's size_t.

  I assume all this lenning:

			unsigned int this_len;

			this_len = buf->len;
			if (this_len > len)
				this_len = len;

  is dealing with bytes too.  You'll be wanting a size_t in there.

- why is the `flags' arg to sys_splice() unsigned long?  Can it be `int'?

- what does `flags' do, anyway?  The whole thing is undocumented and
  almost uncommented.

- the tmp_page trick in anon_pipe_buf_release() seems to be unrelated to
  the splice() work.  It should be a separate patch and any peformance
  testing (needed, please) should be decoupled from that change.

- I think the `size_t left' in do_splice_to() can overflow if f_pos is
  sufficiently different from i_size.

- All the operations do foo(in, out, ...).  It's a bit more conventional
  to do foo(out, in, ...).

- The logic in do_splice() hurts my brain.  "if `in' is a pipe then
  splice from `in-as-a-pipe' to `out' else if `out' is a pipe then splice
  from `in' to 'out-as-a-pipe'.  Make sense, I guess, but I do wonder "what
  would happen if those tests were reversed?".  Nothing, I guess.

- In pipe_to_file():

  - Shouldn't it be using GFP_HIGHUSER()?

  - local variable `index' should be unsigned long or, for clarity
    value, pgoff_t.

  - Incoming arg `pos' should be loff_t?

  - It's racy against truncate().  After running ->readpage and
    lock_page(), need to check for page->mapping == NULL.

  - There's a duplicate flush_dcache_page().

  - Why does it run write_one_page()???  (Don't tell me.  I'll work it
    out when I see the commented version ;))

  - I worry a bit about the assumption in one place that a non-zero
    return from commit_write() indicates an error, whereas another place
    assumes that a negative return is an error.  We had problems in the
    past where some a_ops implementations decided to return small positive
    numbers from prepare_write() or commit_write() a_ops, which broke
    stuff.  They shouldn't be doing that now, but it's a thing to watch out
    for.

  - Bug.  If write_one_page() returned an error, it still unlocked the page.

- In pipe_to_sendpage():

  - local variable `offset' is ulong, but elsewhere you've used uint. 
    The latter is better.

  - Again, incoming arg `len' is confusing.  I _think_ it's actually
    "number of bytes to be moved from this page".  A comment which explains
    these things would be nice, and perhaps a better name (bytes_to_send?)

  - Should incoming arg `pos' be loff_t?  That would give it some meaning.

  - Why does it use PAGE_SIZE and PAGE_SHIFT rather than PAGE_CACHE_*?

- In generic_file_splice_read():

  - nonatomic modification of f_pos.  Is i_mutex held?  (see
    generic_file_llseek())

  - Darnit, we carried `flags' this far and ended up not using it. 
    (What _does_ flags do, anyway?  Reads on..)

- In __generic_file_splice_read():

  - local variable `index' is ulong, could be pgoff_t (for clarity)

  - local variable `offset' could be uint (it is uint elsewhere, and
    might generate better code).

    A better name might be offset_in_page.

  - local variable `pages' could be uint (but watch out for overflow!!).

    A better name might be nr_pages (matches find_get_pages()).  Then,
    local variable `array' can be renamed to `pages', which is all much
    better.

  - While we're in the spirit, local var `i' would be better named
    `page_nr' or something.

  - Shouldn't it be using GFP_HIGHUSER?

  - whoa.  We move the pages into the pipe while they're still under
    read I/O.  Is that deliberate?  (pls add nice comment).

  - These pages can get truncated at any time they're unlocked.  Does
    the code cope with all that?

  - hm.  What happens if the pages which find_get_pages() returned are
    not contiguous in pagecache?  I think your `pages' array gets all
    jumbled up.

- In move_to_pipe()

  - gargh, another `offset' and `len'.  No idea what they're doing, so
    am unable to determine whether ulong is an appropriate type.  Am keenly
    looking forward to the commented version!

  - Suggest you rename `pages' to `nr_pages', `array' to `pages'.  And
    `i' to `page_nr'.

  - local var `bufs' could be renamed `nrbufs' to align with
    pipe_inode_info and could be made uint.

  - Do we actually need local var `bufs'?  It seems to be caching info->nrbufs.

  - release_pages() might be faster than one-at-a-time page_cache_release()


Anyway, that's all just low-level stuff.

What does the feature do?  How would one use it in an application?  Is it
intended that it be generalised to other kinds of address_spaces?  If so,
which ones, and what implementation problems might we expect?

(And I still don't know what `flags' does!)

  parent reply	other threads:[~2006-03-29 22:35 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-29 12:28 Jens Axboe
2006-03-29 12:30 ` Jens Axboe
2006-03-29 13:15 ` Jeff Garzik
2006-03-29 13:27   ` Jens Axboe
2006-03-29 21:49     ` Nathan Scott
2006-03-29 20:06   ` Linus Torvalds
2006-03-29 20:42     ` Jens Axboe
2006-03-29 20:43       ` Jens Axboe
2006-03-29 21:14         ` Linus Torvalds
2006-03-30  6:17           ` Jens Axboe
2006-03-29 22:37 ` Andrew Morton [this message]
2006-03-30  0:50   ` Linus Torvalds
2006-03-30  1:04     ` Jeff Garzik
2006-03-30  1:20       ` Andrew Morton
2006-03-30  6:18         ` Jens Axboe
2006-03-30  2:08     ` Andrew Morton
2006-03-30  3:44       ` Nick Piggin
2006-03-30  7:21       ` Jens Axboe
2006-03-30  7:30         ` Andrew Morton
2006-03-30  7:33           ` Jens Axboe
2006-03-30  8:02             ` Jan Engelhardt
2006-03-30  3:10     ` Nick Piggin
2006-03-30  7:16     ` Jens Axboe
2006-03-30  8:09     ` Jan Engelhardt
2006-03-30  7:45   ` Jens Axboe
2006-03-30  8:02     ` Andrew Morton
2006-03-30  8:10       ` Jens Axboe
2006-03-30  8:25         ` Nick Piggin
2006-03-30  8:27         ` Andrew Morton
2006-03-30  8:50           ` Nick Piggin
2006-03-30  8:51           ` Jens Axboe
2006-03-30  9:15             ` Jens Axboe
2006-03-30  9:40               ` Andrew Morton
2006-03-30  9:45                 ` Jens Axboe
2006-03-30  9:56                   ` Andrew Morton
2006-03-30 10:01                     ` Jens Axboe
2006-03-30  2:36 ` Nick Piggin
2006-03-30  7:00   ` Jens Axboe
2006-03-30  7:33     ` Nick Piggin
2006-03-30  8:54 ` KAMEZAWA Hiroyuki
2006-03-30 13:53   ` Jens Axboe
2006-03-30 14:05     ` KAMEZAWA Hiroyuki
2006-03-30 14:38       ` Jens Axboe
2006-03-30 14:55         ` KAMEZAWA Hiroyuki
  -- strict thread matches above, loose matches on Subject: below --
2005-12-19  9:16 Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060329143758.607c1ccc.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=axboe@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®