Re: mmap and SIGBUS

Pavel Machek wrote:
> > Here is a parts of my and Jamie Lokier <lk tantalophile demon co uk>
> > letters about mmap.  We discussed this at Linux Kernel mailing list,
> > but it seems it is standart behaviour of Unices kernel's.
> Yep, seen that discussion. I did not agree with jamie, IMNSHO SIGBUS
> sometimes is better than not being able to view files > virtual mem.

Sorry Pavel, I think you and I agree!

I like SIGBUS because it can be used for error detection and recovery.
(When it is implemented correctly and returns the address in
siginfo->si_addr; not all the Linux targets do this properly, in fact
i386 was one that did not pass a test of this)

And I like mmap, not just because of the file size thing but because it
should provide the fastest parsers and reduce VM page duplication.  (I
use it for text parsing, and so does GCC these days).  SIGBUS is an
essential ingredient in fast parsers, if they are to recover on
problematic filesystems.  Fortunately, recovery from SIGBUS _is_
possible when it's required.

I disagree say that accepting the occasional program crash is ok though
-- that sort of "unlikely" thinking reminds me too much of the recent
painful realisation that I can't run simple Gnome apps over an
SSH-tunnelled X session (bah!), so I can't access my remote GnomeCal
calendar (double bah, whatever happened to lovely X network transparency?).

What I wrote about dirtying all the pages is something you have to do if
you want to be sure your program sees a snapshot of the file at "load"
time, in the style of an editor that has a "Load File" operation.  To
ensure it works with huge files, I suppose you could copy the edited
file and mmap the copy, instead of touching any pages.

For a file viewer such as GMC, perhaps that behaviour is not important.

Trapping SIGBUS and recovering in a file viewer is important IMO, not
least because it is quite easy to do.  You don't even need
siginfo->si_addr if you know which file is being parsed for the display
at SIGBUS time, and the parsing/display code itself does not need any
special code.

have a nice day,
-- Jamie

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]