Re: Alignment of disk-I/O from userland.

From: Luigi Rizzo (rizzo_at_icir.org)
Date: 10/06/03

  • Next message: Garrett Wollman: "Re: Alignment of disk-I/O from userland."
    Date: Mon, 6 Oct 2003 05:35:37 -0700
    To: Poul-Henning Kamp <phk@phk.freebsd.dk>
    
    

    On Mon, Oct 06, 2003 at 02:06:09PM +0200, Poul-Henning Kamp wrote:
    ...
    > If a userland program does a read or write on a disk device (/dev/ad0
    > for instance), we do some VM swizzle in physio and the request is
                      ^^^^^
    I don't completely follow -- is this something you plan to do, or
    it is what we do now ? In the latter case then the code you show
    below is already causing trouble, and enforcing (or should we say
    "checking") that the alignment is respected would just make the
    problem evident (which is clearly desirable).

    In any case i guess it is unavoidable to implement some form of
    bounce buffers -- sometimes you just can't modify the binary
    that issues the read/write request.

    And if you can provide some optimization to bypass the bounce buffer after
    checking that the alignment is the correct one, then you are improving
    performance in some cases and not harming in the remaining ones, so
    i would say go for it...

            cheers
            luigi

    > in essence a zero-copy thing directly into the process' pages, and
    > as an sideeffect of this, the pointer passed to the device driver
    > has the same offset into a page as the users request (the lower 12
    > bits on i386).
    >
    > That means that userland programs can send down I/O requests which
    > are not properly aligned.
    >
    > This program, in other words, would be a problem for some of our
    > disk controllers:
    >
    > #include <stdlib.h>
    >
    > int
    > main(int argc, char **argv)
    > {
    > char *p;
    >
    > p = malloc(8192); /* page aligned */
    > read (0, p + 1, 2048); /* not */
    > }
    >
    > Most code which does disk I/O from userland uses malloc'ed buffers for
    > the sectors and the alignment comes for free, but we currently have
    > no requirement that it be so.
    >
    > How much code (apart from newfs(8)!) would we break by enforcing a
    > minimum alignment of for instance 16 bytes on disk-I/O requests
    > from userland ?
    >
    > It would be a trivial matter to do the "bounce-buffering" somewhere
    > along the road, but I am not convinced it is the right thing to do
    > because all of sudden some requests would take a performance hit to
    > do a copy and some would not...
    >
    > Qualified, informed input requested.
    >
    > No Bikesheds please.
    >
    > Poul-Henning
    >
    > --
    > Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
    > phk@FreeBSD.ORG | TCP/IP since RFC 956
    > FreeBSD committer | BSD since 4.3-tahoe
    > Never attribute to malice what can adequately be explained by incompetence.
    > _______________________________________________
    > freebsd-arch@freebsd.org mailing list
    > http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    > To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"
    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Garrett Wollman: "Re: Alignment of disk-I/O from userland."

    Relevant Pages

    • Re: [TOMOYO #5 02/18] Add wrapper functions for VFShelperfunctions.
      ... request and a 'kernel' request, and why is the latter safe from a ... For example, if userland process wants to create a directory, ... In the kernel, mkdiris mapped to sys_mkdir, ... Some kernel code *might* call sys_mkdirtoo. ...
      (Linux-Kernel)
    • Re: Alignment of disk-I/O from userland.
      ... >>alignment of data buffers used to access disk devices directly. ... > of this by copying the request as necessary. ... How are we going to express the alignment requirements to the upper ...
      (freebsd-arch)
    • Re: [PATCH 1/2] block: Modify blk_rq_map_user to support large requests
      ... the block layer blk_rq_map_user code to support large requests so ... The next patch then coverts bsg.c, ... adding more stuff to struct request. ... I think I originally made a mistake with the bounce buffers and thinking ...
      (Linux-Kernel)
    • Re: realloc() implicit free() ?
      ... a zero block size as a request for one byte, and let the alignment mechanisms raise it as they will. ... but the Standard does not require the allocated object to ... The compiler system does. ...
      (comp.lang.c)
    • Re: How does malloc align pointer
      ... A request for two bytes of storage might only be ... >>> that even though the CPU might require 4 or 8 byte alignment ... >>The standard requires a non-null return from malloc() to be appropriately ... Lawrence ...
      (comp.lang.c)