On Mon, 16 Dec 2024, Konstantin Belousov wrote:
On Mon, Dec 16, 2024 at 02:08:43PM -0500, John Levine
wrote:
PS: I can believe there are some versions of
linux that screwed up disk cache
coherency, but that just means they don't properly implement the spec, not for
the first time. I mean, it's not *that* hard to make all the maps point to the
same physical page frame, even on a machine like POWER with reverse page maps.
This is not enough. There are (were ?) architectures, typically with the
virtually addressed caches, which require all mappings of the same page
to be suitably aligned, at least. ...
If addresses of different mappings are not aligned, caches were not coherent.
I think we're in "so don't do that" territory. mmap() normally lets
the
system pick the memory address to map so it can pick something suitably
aligned. You can pass the MAP_FIXED flag to tell it to map at a
particular address, but it can return EINVAL if the address doesn't work.
The POSIX description says "The use of MAP_FIXED is discouraged, as it may
prevent an implementation from making the most effective use of
resources."
It's not always trivial to make this work. On systems with reverse maps,
a physical page can only be mapped to one virtual address at a time, so
for shared pages it has to mark all of the aliases nonresident and on a
fault remap the page into the map of the process that is running. But
it's not rocket science, either.
R's,
John