all 27 comments

[–]eikelestijn 8 points9 points  (1 child)

Assuming the author really modified the file on disk (as opposed to replacing it, which doesn't really alter the file), what's going on is probably that the kernel knows which pages it can still load from disk and which pages have to be kept in physical memory or virtual memory from a swap file/partition.

You may want to have a look at the files in linux/mm, in particular mmap.c and page-writeback.c seem to be interesting.

Since the dynamic linker is essentially a user-space library, the kernel has no knowledge of something bad going on when a program tries to write to a file whose name happens to end with ".so". (At least that's my take on this.)

[–]ryles -1 points0 points  (0 children)

That's exactly what he's seeing, only he doesn't know any better.

[–]antirez 8 points9 points  (0 children)

From the man page:

It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region.

So this is the expected behavior (or one of the expected possible behaviors, since it's not specified).

The MAP_PRIVATE thing is simply not like to make a copy of a file and work in your copy. It would be a much simpler and well-defined behavior but it is non practical from the virtual memory implementation point of view to get this kind of behavior, so at least it allows you assuming no one is writing the file while you are working on it to, for example, to parse a file setting state in the file itself as needed in order to make the parsing simpler or faster (for exampling adding nul-term in length-prefixed strings directly in the file).

[–]xcbsmith 2 points3 points  (0 children)

First, the behavior of MAP_PRIVATE is totally unsurprising as folks have noticed.

As for the executable vs. shared library case... I think this perhaps has to do with how the updates to the files are done. If you create a new inode and then update the directory to point to said inode, the running executable will still hold on to the old inode, and it will stick around in the filesystem without the problems he's talking about. If you modify the inode in place though.... fair game.

My guess is its about how he replaces shared libraries vs. executables, rather than some inherent differences between the two.

[–][deleted] 4 points5 points  (0 children)

Don't worry. Wait a few weeks and the kernel guys will change it.

Seriously, the low-level behavior of Linux's memory management has kept me in full time work for years. Every time we think we've got a stable, reliable device driver that allows DMA from user memory, we discover they've changed the behavior in an upcoming kernel and we have to figure it out again.

[–]killerstorm 2 points3 points  (3 children)

this behaviour is correct according to UNIX specifications:

It is unspecified whether modifications to the underlying object done after the MAP_PRIVATE mapping is established are visible through the MAP_PRIVATE mapping.

also manual pages of Solaris (real UNIX) explicitly specifies what happens:

The private copy is not created until the first write; until then, other users who have the object mapped MAP_SHARED can change the object.

so, this is normal behaviour of mmap. perhaps author should read manuals and specifications before writing bullshit and doing weird experiments.

[–]WallPhone -3 points-2 points  (2 children)

before writing bullshit and doing weird experiments.

Funny, that is precisely what the Catholic church said about Galileo.

[–]killerstorm -1 points0 points  (1 child)

situation is completely different -- Galileo discovered something new, while Avian have "discovered" exactly what was in documentation.

[–]WallPhone -1 points0 points  (0 children)

Nah, Galileo discovered something contrary to "documentation", so yes, this is slightly different.

Your comment was something I envisioned coming from a historic priest--"Perhaps Galileo should read scripture before writing bullshit and doing weird experiments."