Re: (XFree86) mmap of /proc/XXX/mem

Egbert Eich (eich@hilbert.ikp.physik.tu-darmstadt.de)
Thu, 2 Dec 1999 15:37:44 +0100 (MET)


Jamie Lokier writes:
> Egbert Eich wrote:
> > > 1. Create a file, fill it up to size, mmap() it. You can mmap() parts
> > > of a file to different addresses in the same process, and in that way
> > > you get page aliasing. Only the pages you're thinking of aliasing
> > > need to be mapped. Note that pages need to be flushed somehow on
> > > some non-x86 architectures (the CPU cache is by virtual address), but
> > > on x86 this is not required.
> >
> > I tried something like that, too. However I didn't fill up the file -
> > I used lseek instead, this way I was only able to access the first
> > page. If I tried to access any higher pages it bus-errored.
>
> According to filemap_no_page:
>
> /*
> * Semantics for shared and private memory areas are different
> * past the end of the file. A shared mapping past the last page
> * of the file is an error and results in a SIGBUS, while a
> * private mapping just maps in a zero page.
> */
>
> Of course you're using a shared mapping so that the page alias works, if
> you want write access to both pages, right?

Yes, exactly.
>
> So you have to fill the file. Seek to one byte before the last in your
> range, and write a single byte. Holes should not bus error, but access
> beyond the end of the file does bus error.
OK.
>
> What is odd is that you are able to access even the first page. IMO
> that should bus error too.
yes.
>
> > Maybe filling
> > it up does the trick - however then the process will get a private copy
> > of all pages in this 1Meg - even the ones that are not touched by the BIOS.
> > This will give me a 1Meg footprint for each real mode image.
>
> Create the file and fill it using lseek/write. Then only 1 page is
> actually allocated in the filesystem and process image. (You can play
> with ftruncate() to get 0 pages -- make the file a bit longer, then
> ftruncate it to remove block allocated by the write).

OK, I'll try this.
>
> When you mmap a file, no memory is actually used until someone touches
> the pages. For a file that's all hole, no disk space is used either so
> this is quite efficient.
>
> It would be nice if reading an mmaped hole would map the zero page, but
> I had a quick look at the path through filemap_no_page and
> block_read_full_page, and it doesn't seem to do that. Since the BIOS
> will probably write to every page it touches that's not such a big deal.
>
OK, thanks. I'll try it out.

Regards,
Egbert.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/