- Joined
- Apr 24, 2020
- Messages
- 2,875 (1.54/day)
If the page file is fixed, what happens when it is full? does the OS kill the offender? as before I am intentionally a bit ambiguous about which OS
In the 1970s, a programming language called "C" was invented.
In "C", when you need more memory, you call a function called "malloc(size)" (memory-alloc), and ask the system for "size" more memory. For example, malloc(4) gets you 4 more bytes. malloc(4096) gets you 4kB (1kB == 1024 bytes). Etc. etc.
In the 1980s+, techniques were made for the OS to lie to programs about the location of memory. Its called the "virtual memory" system. The gist is that every program has its own, unique, "virtual memory" that it cannot escape from. This allows the system to isolate programs from each other, increasing security. The OS also can detect when different programs have "the same memory" (such as DLLs), and in these "shared memory" cases, the OS only has one copy of the memory (when the programs all think they have their own copy).
Now consider the case of an "all zero" page of memory (ie: the program hasn't touched the memory yet). Instead of physically using that memory yet, the OS maps "all zero" to... the same memory location. This is both Linux and Windows.
In this case, an "all zero" page of memory takes up... zero bytes. Its fully virtual. When the program reads from it, the OS just returns zero.
--------------
In Linux, malloc always succeeds. It turns out that Linux made the explicit decision that "malloc" doesn't actually allocate memory, it just pretends to. Really, its just a block of "all zero" memory, because it hasn't been touched yet.
The minute a program "touches" the memory, Linux "detects" the write, and splits up the virtual memory to actually point to physical memory.
So you see, the problem is one of history. The 1970s model was "malloc() gets us more memory", but a set of lies / changes made it more convenient for malloc() to just... not do that anymore. malloc() gets more virtual memory, non-existent memory that the OS then fills in later at its leisure.
Virtual memory is also how the OS represents talking to GPUs (Shared Virtual Memory). When you write to some sections of "virtual memory", it doesn't go to DDR4 RAM physically anymore, it might go to Ethernet (!!!) or to the GPU, or even a file on the system.
---------
All "paging" is, is having a pool of bytes on your drive that interacts with the virtual-system. If the OS decides that some bytes are "rarely used", it punts it out of DDR4 RAM and writes it to disk (or SSD), saving the high-speed DDR4 for programs that are actively using RAM. This feature also was invented in the 1980s when Virtual Memory became popular.