top | item 29711987

(no title)

smlckz | 4 years ago

> In C, a read from an uninitialized variable is an unspecified value and is allowed to be any value each time it is read. This is important, because it allows behavior such as lazy recycling of pages: for example, on FreeBSD the malloc implementation informs the operating system that pages are currently unused, and the operating system uses the first write to a page as the hint that this is no longer true. A read to newly malloced memory may initially read the old value; then the operating system may reuse theunderlying physical page; and then on the next write to a different location in the page replace it with a newly zeroed page. The second read from the same location will then give a zero value.

What? What is the benifit of such behaviour?

What does other OSes do in this regard?

discuss

order

bodhiandphysics|4 years ago

Lots of programs malloc a lot of memory, and do nothing with it for a while. This allows the os to wait for a low load time to handle memory allocation.

pm215|4 years ago

Is there much benefit from delaying the zeroing to first-write rather than first-read (which I think is effectively where Linux does it)?