Subject: Re: Why doesn't (open ... :if-exists) support :truncate?
From: rpw3@rpw3.org (Rob Warnock)
Date: Fri, 30 Nov 2007 21:42:27 -0600
Newsgroups: comp.lang.lisp
Message-ID: <-KGdnUE5mLW-Rc3anZ2dnUVZ_uOmnZ2d@speakeasy.net>
Richard M Kreuter  <kreuter@progn.net> wrote:
+---------------
| "Steven M. Haflich" <smh@alum.mit.edu> writes:
| > Your "direct I/O" reference doesn't really mean anything.
| > Perhaps you should explain.
| 
| I was trying to come up with a story according to which some Lisp
| could do all the OPEN :IF-EXISTS actions, but be unable to to a
| truncating open.  The entries for :OVERWRITE and :APPEND say "[o]utput
| operations on the stream destructively modify the existing file",
| which I take to mean that the existing file is to be scribbled on, and
| not replaced by a new file.  I can't think of a way to do this without
| at some point doing I/O directly to the existing file.  By contrast,
| :NEW-VERSION, :SUPESEDE, :RENAME, :RENAME-AND-DELETE need not do I/O
| to an existing file (unless a file system requires I/O to a file in
| order to replace the file with another one, I suppose).
+---------------

Don't use the term "Direct I/O" for this -- that term is already
in standard use in the Unix/Linux/POSIX world [following SGI's
original use of the term in the XFS filesystem on Irix] for file
I/O which goes "directly" from (to) the user program's address
space to (from) the I/O device without going through the operating
system's buffer cache. E.g., from "man 2 open" on FreeBSD:

    O_DIRECT may be used to minimize or eliminate the cache effects
    of reading and writing.  The system will attempt to avoid caching
    the data you read or write.  If it cannot avoid caching the data,
    it will minimize the impact the data has on the cache.  Use of this
    flag can drastically reduce performance if not used with care.

and on Linux:

    O_DIRECT
      Try to minimize cache effects of the I/O to and from this  file.
      In  general  this  will degrade performance, but it is useful in
      special situations, such  as  when  applications  do  their  own
      caching.   File I/O is done directly to/from user space buffers.
      The I/O is synchronous, i.e., at the completion of  the  read(2)
      or  write(2) system call, data is guaranteed to have been trans-
      ferred.  Under Linux 2.4 transfer sizes, and  the  alignment  of
      user buffer and file offset must all be multiples of the logical
      block size of the file system.  Under  Linux  2.6  alignment  to
      512-byte boundaries suffices.
      A  semantically similar interface for block devices is described
      in raw(8).

"Direct I/O" usually implies (but does not guarantee) "zero-copy DMA".


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607