public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jamie Lokier <lk@tantalophile.demon.co.uk>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Andrew Morton <akpm@zip.com.au>, lkml <linux-kernel@vger.kernel.org>
Subject: Re: [patch 6/12] hold atomic kmaps across generic_file_read
Date: Sat, 10 Aug 2002 20:10:27 +0100	[thread overview]
Message-ID: <20020810201027.E306@kushida.apsleyroad.org> (raw)
In-Reply-To: <Pine.LNX.4.44.0208101134510.2197-100000@home.transmeta.com>; from torvalds@transmeta.com on Sat, Aug 10, 2002 at 11:42:44AM -0700

Linus Torvalds wrote:
> Yes, with read() you have to do a brk() or mmap(MAP_ANON) (and brk() is 
> the _much_ faster of the two).

Ouch, that means a typical user-space program/library that wants to use
this technique has to have an intimate relationship with its malloc()
implementation: it's not in general safe to call brk() unless you are
the memory allocator.  (Yes, I know you can call brk() with Glibc's
malloc(), but... dependencies upon dependencies!)  And even when it is
safe to allocate with brk(), there's no safe way to free that memory.

So this would be fine for the stdio built in to Glibc, perhaps.

> But with mmap() you need to do a fstat() and a munmap() (while with read
> you just re-use the area, and we'd do the right thing thanks to the
> COW-ness of the pages).

Granted, you might re-use the area if you're doing block reads like
stdio, compiler, XML parser etc.  But not a few programs want to:

   1. Allocate enough memory to hold whole file.
   2. Load file into memory.

> Also, because of the delayed nature of mmap()/fault, it has some strange
> behaviour if somebody is editing your file in the middle of the compile -
> with read() you might get strange syntax errors if somebody changes the
> file half-way, but with mmap() your preprocessor may get a SIGSEGV in the
> middle just because the file was truncated..

Isn't that SIGBUS :-)
(Not that the architectures are at all consistent on this..)
  
> In general, I think read() tends to be the right (and simpler) interface
> to use if you don't explicitly want to take advantage of the things mmap
> offers (on-demand mappings, no-write-back pageouts, VM coherency etc).

I agree, although I think this particular optimisation requires some
quite unusual preparation by user space - I still think GCC would need
to call open/fstat/mmap/read/munmap/close.

You've rightly pointed out that memcpy() is faster for a page, rather
than VM tweaking.  But this isn't true of large reads, is it?
Then the TLB invalidation cost could, in principle, be amortised over
the whole large read.

-- Jamie

  parent reply	other threads:[~2002-08-10 19:07 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-10  0:57 [patch 6/12] hold atomic kmaps across generic_file_read Andrew Morton
2002-08-10  1:33 ` Linus Torvalds
2002-08-10  3:53   ` Andrew Morton
2002-08-10  3:53     ` Linus Torvalds
2002-08-10  6:12       ` Andrew Morton
2002-08-10  7:25         ` Linus Torvalds
2002-08-10  9:08           ` Andrew Morton
2002-08-10 12:44           ` Daniel Phillips
2002-08-10 17:01             ` Linus Torvalds
2002-08-10 18:16               ` Daniel Phillips
2002-08-10 18:32                 ` Linus Torvalds
2002-08-10 18:46                   ` Daniel Phillips
2002-08-10 14:16           ` Rik van Riel
2002-08-10 17:03             ` Linus Torvalds
2002-08-10 17:36           ` Jamie Lokier
2002-08-10 17:46             ` Linus Torvalds
2002-08-10 17:55               ` Jamie Lokier
2002-08-10 18:42                 ` Linus Torvalds
2002-08-10 18:52                   ` Jeff Garzik
2002-08-10 19:01                     ` Christoph Hellwig
2002-08-10 19:04                       ` Jeff Garzik
2002-08-12 15:20                       ` Ingo Oeser
2002-08-12  0:18                     ` Albert D. Cahalan
2002-08-12 14:11                       ` Jeff Garzik
2002-08-12 14:46                         ` David Woodhouse
2002-08-10 19:10                   ` Jamie Lokier [this message]
2002-08-10 22:42                     ` Linus Torvalds
2002-08-11  3:17                       ` Simon Kirby
2002-08-11  6:07                         ` Andrew Morton
2002-08-11  8:46                           ` Simon Kirby
2002-08-11  9:36                             ` Andrew Morton
2002-08-11  9:49                               ` Andrew Morton
2002-08-11 10:28                             ` Andrew Morton
2002-08-11 18:52                         ` Linus Torvalds
2002-08-12  3:28                           ` Andrew Morton
2002-08-12  3:27                             ` Linus Torvalds
2002-08-12  4:08                               ` Andrew Morton
2002-08-12  6:20                             ` Simon Kirby
2002-08-12  6:44                               ` Andrew Morton
2002-08-12 19:43                                 ` Trond Myklebust
2002-08-12 20:43                                   ` Andrew Morton
2002-08-11  8:00                       ` Daniel Phillips
2002-08-11 19:00                         ` Linus Torvalds
2002-08-11 19:43                           ` Daniel Phillips
2002-08-11  0:34   ` Andrew Morton
2002-08-11  0:56     ` Linus Torvalds
2002-08-11  1:27       ` Andrew Morton
2002-08-12  7:45   ` Rusty Russell
2002-08-12  9:45     ` Daniel Phillips
2002-08-12 20:29       ` Linus Torvalds
2002-08-12 21:21         ` Daniel Phillips
2002-08-12 17:30     ` Linus Torvalds

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=20020810201027.E306@kushida.apsleyroad.org \
    --to=lk@tantalophile.demon.co.uk \
    --cc=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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