Subject: mmap() and page alignment
To: None <friedl@informatik.uni-kl.de>
From: Gordon W. Ross <gwr@mc.com>
List: tech-kern
Date: 07/06/1995 09:51:38
> From: friedl@informatik.uni-kl.de
> Date: Thu, 6 Jul 95 14:44:26 MET DST
>
> Whem mapping a file, the mmap() systems call requires the offset to be
> page aligned. This is not necessary. Of course performance is better
> if a memory page does not cross a filesystem block. But the vnode pager
> also works if the file offset is not page aligned.
I would recommend against this change. The reason for restricting
the mapping offset is to allow the VM system to (eventually) have a
fully coherent page cache. If you allow one file block to be mapped
at more than one offset within a page, then you can not use a single
physical page to represent that block. That makes it incoherent.
Any fully coherent page cache will require the restriction:
(file_offset % pagsize) == (mapping_offset % pagesize)
OK, actually, you could add a per-file constant to one side of
the above equality, but that is typically not useful.
Note that POSIX 1003.1b specifically allows the above restriction
for the mmap system call. Here is a quote from Sec. 12.2.1.2:
If MAP_FIXED is specified and _addr_ is nonzero, it shall have the
same remainder as the _off_ parameter, modulo the page size. The
implementation may require that _off_ is a multiple of the page
size. If MAP_FIXED is specified, the implemenatation may require
that _addr_ is a multiple of the page size.
> Currently the Linux emulation reads in the exec'd files instead of
> mapping them, because in Linux executables the pages are not aligned.
> But it is better to have files mapped and shared between processes
> than to read them for every process that uses them.
The fact that old linux executables can not be mapped using perfectly
valid POSIX restrictions is an unfortunate mistake in the design of
that executable format. This problem is sort of moot now that Linux
has moved to ELF instead. Hopefully the new format can be mapped
without violatating these restrictions.
Gordon Ross