Comment by doubletwoyou

17 days ago

That comment about how /dev/zero used to be used to allocate anonymous pages, anyone have more info? All I could find was a wikipedia article [0]

[0] https://en.m.wikipedia.org/wiki//dev/zero

That's it, there isn't any more to know. When the ancient unixes first began to support anonymous maps, they were just hacked into existing code with "zero" as the file, because the only through-line in the unix family history is that the API must be as hideous as it needs to be to accommodate lazy system authors.

  • Wait, by "allocating anonymous pages" we just mean memory allocation from the kernel that's used for implementing e.g malloc, right? Did memory mapped files come before memory allocation so that it "made sense" to implement memory allocation as "mapping in /dev/zero"?

    Or was some amount heap memory always just mapped into the process in early UNIX so that the need to map more pages only appeared as programs started to demand more heap memory than whatever the standard amount was?

    • In those days malloc would use sbrk to allocate memory. And yes, mmap was designed to memory map files. Using it to allocate anonymous pages came later.

      1 reply →

  • There is more to know, does the code special case this? Does it use the file name? Major minor number? Or does it actually read zero's from it and place them in memory?

    • it wouldn't be too hard to look at the source for mmap and zero, but since the topic of this article is the removal of the mmap 'virtual function' in the file, that would have been a pretty good place to throw a zero-page allocation