Subject: Re: new mremap(2): relax alignment restrictions?
To: der Mouse <mouse@rodents.montreal.qc.ca>
From: Wraukon the Excellent <wraukon@gmail.com>
List: tech-kern
Date: 07/26/2007 17:12:38
> Process A:
>         open 10-byte file
>         mmap 10 bytes
> Process B:
>         extend file to 20 bytes
> Process A:
>         write into the 10-20 byte range of the mapping
>
> Should the data process A writes make it into the file?  I'd say it
> shouldn't in an abstract sense, but that could be very hard to arrange,
> especially if you want modifications to the 0-10 range to be shared.

I saw a couple of things go by; writing past EOF in mmap(), and this.
they both get a bit tricky.

Now, unless I'm missing something, wouldn't writing past EOF in mmap()
yield approximately the same results as appending to the file, or lseek()-
ing to some offset and scribbling a bit, at least with regard to the page
allocated by mmap()?  What happens when you msync() the file?

If you write beyond the page boundary of the buffer given by/passed to
mmap(), I'd expect a segmentation violation to ensue.

In order to enforce a memory-region boundary, we'd have to somehow
keep track somewhere of the actual size of the memory region and
enforce it if mmap() is not to be permitted to extend the size of a
file.

Now, a question:  If you mmap in a writable file, what happens
if someone chmods it read-only before you msync() back any
changes? (if the answer is "the data gets written back regardless",
then keeping tabs via fd.ino is obviously not happening;
a read of the man page seems to indicate that this is the case,
seeing as the memory mapped region can remain in memory
after the fd is closed and requires a process to exit() or to
munmap() the memory...)

I've not tried it; will msync() return EIO in that case?

(it seems to me that to have synchronicity between permissions
on filesystem objects and memory-mapped pages thereto would
be prohibitively expensive.  I'm concluding that as long as one
does not write outside the mmap'd region, it's a legal operation.
To otherwise enforce it would also probably be expensive and
not necessarily what is desired or, currently, expected.)

Okay, kernel gurus, tell me what I missed.

--*greywolf,