Page 1 of 1

A bit, on average

Posted: Wed Jul 05, 2017 11:31 pm UTC
by tms
What can be said about the average value of bits that are refreshed - or stored as it may - in RAM and in the CPU cache and registers? How far from even can you expect to see and what typically affects it?

Re: A bit, on average

Posted: Thu Jul 06, 2017 1:49 pm UTC
by Tub
It depends on the data that is stored. Compressed or encrypted data should appear uniformly random, i.e. have roughly equal parts 0 and 1. Other data often favors 0: in ASCII-text, the leading bit of each character is always 0 (but most small letters have the second bit as 1, so it almost evens out). Programmers may use 64-bit integers to store values as low as 100, thus having >50 leading zeros. Depending on the address space layout, pointers may favor either 0 or 1.
Unused memory is initialized to 0 by the operating system, so anything reserved but not used (like padding bytes for alignment) is usually 0.

I just took a core dump of my running firefox, which has 91.8% zero, 8.2% one - but that's a dump of its address space, including many unused memory regions filled with 0. If you were to dump physical memory, that ratio would be a lot closer to 50/50.

Re: A bit, on average

Posted: Wed Aug 30, 2017 10:07 pm UTC
by Jplus
Addition to what Tub wrote: virtual memory may be compressed in RAM. This increases the entropy of the data, so you expect a ratio closer to 50:50 in the compressed pages. However, such compression is never applied to all of the memory at the same time, because a process can't use a page while it is in the compressed state. Recent macs do this as a way to postpone swapping. Perhaps Windows 10 is doing it too.