public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* _IO_file_underflow_mmap read call for atime
@ 2002-07-30 14:30 Roland McGrath
  2002-07-30 14:50 ` Ulrich Drepper
  0 siblings, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2002-07-30 14:30 UTC (permalink / raw)
  To: GNU libc hackers

The POSIX rules for mmap on files require that mmap'ing and reading a page
set the atime.  I don't see how the rules for stdio affecting atime (via
the "underlying functions" clauses) could be violated by the libio mmap'd
buffer implementation if mmap behaves as specified.  So the read call in
_IO_file_underflow_mmap is unnecessary.  Am I missing something?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-30 14:30 _IO_file_underflow_mmap read call for atime Roland McGrath
@ 2002-07-30 14:50 ` Ulrich Drepper
  2002-07-30 15:29   ` Jakub Jelinek
  2002-07-31 15:16   ` Roland McGrath
  0 siblings, 2 replies; 10+ messages in thread
From: Ulrich Drepper @ 2002-07-30 14:50 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU libc hackers

Roland McGrath wrote:
> The POSIX rules for mmap on files require that mmap'ing and reading a page
> set the atime.  I don't see how the rules for stdio affecting atime (via
> the "underlying functions" clauses) could be violated by the libio mmap'd
> buffer implementation if mmap behaves as specified.  So the read call in
> _IO_file_underflow_mmap is unnecessary.  Am I missing something?

The problem is timing.  mmap affects atime, yes, but at the time the 
mmap happens.  The I/O stream rules require that atime is modified at 
the time of the first read operation.

  from the fgetc spec:

   The st_atime field shall be marked for update by the first successful
   execution of fgetc( ), fgets( ), fgetwc( ), fgetws( ), fread( ),
   fscanf( ), getc( ), getchar( ), gets( ), or scanf( ) using stream that
   returns data not supplied by a prior call to ungetc( ) or ungetwc( ).

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-30 14:50 ` Ulrich Drepper
@ 2002-07-30 15:29   ` Jakub Jelinek
  2002-07-30 16:38     ` Ulrich Drepper
  2002-07-31 15:17     ` Roland McGrath
  2002-07-31 15:16   ` Roland McGrath
  1 sibling, 2 replies; 10+ messages in thread
From: Jakub Jelinek @ 2002-07-30 15:29 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Roland McGrath, GNU libc hackers

On Tue, Jul 30, 2002 at 02:46:41PM -0700, Ulrich Drepper wrote:
> Roland McGrath wrote:
> > The POSIX rules for mmap on files require that mmap'ing and reading a page
> > set the atime.  I don't see how the rules for stdio affecting atime (via
> > the "underlying functions" clauses) could be violated by the libio mmap'd
> > buffer implementation if mmap behaves as specified.  So the read call in
> > _IO_file_underflow_mmap is unnecessary.  Am I missing something?
> 
> The problem is timing.  mmap affects atime, yes, but at the time the 
> mmap happens.  The I/O stream rules require that atime is modified at 
> the time of the first read operation.
> 
>   from the fgetc spec:
> 
>    The st_atime field shall be marked for update by the first successful
>    execution of fgetc( ), fgets( ), fgetwc( ), fgetws( ), fread( ),
>    fscanf( ), getc( ), getchar( ), gets( ), or scanf( ) using stream that
>    returns data not supplied by a prior call to ungetc( ) or ungetwc( ).

Fine, cannot we mmap at the time of the first read then (and if fall back to
non-mmap stdio if that is not possible)?

	Jakub

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-30 15:29   ` Jakub Jelinek
@ 2002-07-30 16:38     ` Ulrich Drepper
  2002-07-31 15:17     ` Roland McGrath
  1 sibling, 0 replies; 10+ messages in thread
From: Ulrich Drepper @ 2002-07-30 16:38 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, GNU libc hackers

Jakub Jelinek wrote:

> Fine, cannot we mmap at the time of the first read then (and if fall back to
> non-mmap stdio if that is not possible)?

The current code decides at startup time whether to use the mmap 
functions or not.  It would be conceivable to delay this but it makes 
things more complicated.  If you want to give it a try feel free.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-30 14:50 ` Ulrich Drepper
  2002-07-30 15:29   ` Jakub Jelinek
@ 2002-07-31 15:16   ` Roland McGrath
  2002-07-31 15:58     ` Ulrich Drepper
  1 sibling, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2002-07-31 15:16 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: GNU libc hackers

> The problem is timing.  mmap affects atime, yes, but at the time the 
> mmap happens.  The I/O stream rules require that atime is modified at 
> the time of the first read operation.

The spec gives wide latitude in how mmap can behave.  It allows st_atime to
be updated at any time between mmap and munmap.  But it only requires that
it be updated by the time of the first successful access to a mapped area.

If we assume that the mmap implementations we are using in fact also meet
the stricter criterion of updating st_atime on each read fault, then it is
safe to just use mmap and st_atime will meet the POSIX stdio rules.  I
haven't experimented on Linux, but this is certainly how mmap behaves on
GNU/Hurd.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-30 15:29   ` Jakub Jelinek
  2002-07-30 16:38     ` Ulrich Drepper
@ 2002-07-31 15:17     ` Roland McGrath
  2002-07-31 16:00       ` Ulrich Drepper
  1 sibling, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2002-07-31 15:17 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, GNU libc hackers

> Fine, cannot we mmap at the time of the first read then (and if fall back to
> non-mmap stdio if that is not possible)?

That seems more desireable to me anyway.  As it stands, a program that just
calls fopen and then fileno and does not io, or just uses fopen+fclose to
test existence (I have seen such things) will map in the contents of the
file when that's never required at all. 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-31 15:16   ` Roland McGrath
@ 2002-07-31 15:58     ` Ulrich Drepper
  2002-07-31 16:10       ` Roland McGrath
  0 siblings, 1 reply; 10+ messages in thread
From: Ulrich Drepper @ 2002-07-31 15:58 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU libc hackers

Roland McGrath wrote:

> If we assume that the mmap implementations we are using in fact also meet
> the stricter criterion of updating st_atime on each read fault, then it is
> safe to just use mmap and st_atime will meet the POSIX stdio rules.  I
> haven't experimented on Linux, but this is certainly how mmap behaves on
> GNU/Hurd.

The Linux code modifies atime when it's mapped.  So we'd need a symbol 
MMAP_ATIME_AT_ACCESS which is defined for Hurd but not for Linux.  The 
read call is only performed when the symbol is not defined.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-31 15:17     ` Roland McGrath
@ 2002-07-31 16:00       ` Ulrich Drepper
  0 siblings, 0 replies; 10+ messages in thread
From: Ulrich Drepper @ 2002-07-31 16:00 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Jakub Jelinek, GNU libc hackers

Roland McGrath wrote:

> That seems more desireable to me anyway.  As it stands, a program that just
> calls fopen and then fileno and does not io, or just uses fopen+fclose to
> test existence (I have seen such things) will map in the contents of the
> file when that's never required at all. 

If somebody sends a patch I've no problems with this either.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-31 15:58     ` Ulrich Drepper
@ 2002-07-31 16:10       ` Roland McGrath
  2002-07-31 16:57         ` Ulrich Drepper
  0 siblings, 1 reply; 10+ messages in thread
From: Roland McGrath @ 2002-07-31 16:10 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: GNU libc hackers

> The Linux code modifies atime when it's mapped.

And it doesn't update atime on read faults as well?  That is permissible
behavior, but not very helpful.  It makes atime pretty useless if it's
possible there are mmap readers.  There could be a process that opened the
file and mmap'd it a year ago, and then later something does a write so
mtime > atime; then if the first process reads the new data, atime remains
unchanged and sometime contemplating mtime vs atime would conclude that the
new data has not been read by anyone.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: _IO_file_underflow_mmap read call for atime
  2002-07-31 16:10       ` Roland McGrath
@ 2002-07-31 16:57         ` Ulrich Drepper
  0 siblings, 0 replies; 10+ messages in thread
From: Ulrich Drepper @ 2002-07-31 16:57 UTC (permalink / raw)
  To: Roland McGrath; +Cc: GNU libc hackers

Roland McGrath wrote:

> And it doesn't update atime on read faults as well?  That is permissible
> behavior, but not very helpful.  It makes atime pretty useless if it's
> possible there are mmap readers.  There could be a process that opened the
> file and mmap'd it a year ago, and then later something does a write so
> mtime > atime; then if the first process reads the new data, atime remains
> unchanged and sometime contemplating mtime vs atime would conclude that the
> new data has not been read by anyone.

I don't know enough about the implementation.  I only know that the read 
is needed if mmap happened at fopen time.  You can talk to the kernel 
people.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-07-31 23:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-30 14:30 _IO_file_underflow_mmap read call for atime Roland McGrath
2002-07-30 14:50 ` Ulrich Drepper
2002-07-30 15:29   ` Jakub Jelinek
2002-07-30 16:38     ` Ulrich Drepper
2002-07-31 15:17     ` Roland McGrath
2002-07-31 16:00       ` Ulrich Drepper
2002-07-31 15:16   ` Roland McGrath
2002-07-31 15:58     ` Ulrich Drepper
2002-07-31 16:10       ` Roland McGrath
2002-07-31 16:57         ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).