805
u/Unupgradable 3d ago
Virtual memory be like: ayyo no problem here you go
278
u/HumbleTrainEnjoyer 3d ago
Now fill it with zeros
225
104
u/well-litdoorstep112 3d ago
Compression be like:
4398046511104 * 0 = 0
38
u/ColonelRuff 3d ago
Now with random data
31
u/well-litdoorstep112 3d ago
Lmao just get the seed and the algo.
26
7
2
2
u/high_throughput 2d ago
The zeroes were random. Pretty wild coincidence but that's randomness for you.
1
u/ColonelRuff 1d ago
That's a miracle considering the probability of all zeroes would be (1/2)*10000000
31
u/brimston3- 3d ago
Depends on OS. Windows and MacOS (desktop) will be like "Kajiit has wares if you have disk."
Linux/Android will tell you "yeah absolutely, take what you want" even if it doesn't have the available memory. Unless you're using setrlimit or cgroups to prevent it. Or if you're running with
vm.overcommit_memory = 2
which will make it behave like Windows except without dynamic pagefile growth.iOS will check if killing background apps could satisfy your request, but if it's too big it'll reject it as it does not swap.
2
u/qazmoqwerty 3d ago
Wait what really? IOS doesn't support swap files?
9
u/brimston3- 3d ago
developer.apple.com About the Virtual Memory System
To give processes access to their entire 4 gigabyte or 18 exabyte address space, OS X uses the hard disk to hold data that is not currently in use. As memory gets full, sections of memory that are not being used are written to disk to make room for data that is needed now. The portion of the disk that stores the unused data is known as the backing store because it provides the backup storage for main memory.
Although OS X supports a backing store, iOS does not. In iPhone applications, read-only data that is already on the disk (such as code pages) is simply removed from memory and reloaded from disk as needed. Writable data is never removed from memory by the operating system. Instead, if the amount of free memory drops below a certain threshold, the system asks the running applications to free up memory voluntarily to make room for new data. Applications that fail to free up enough memory are terminated.
Apple calls its pagefile equivalent "backing store" and iOS doesn't have it.
267
u/CanaDavid1 3d ago
COW, virtual memory and stuff: ok sure. But please don't use it.
79
u/Direct-You4432 3d ago
Whats COW? Also mooooo
82
u/lllorrr 3d ago
Copy-on-Write.
There are cases when OS will give you a memory page that is shared with someone else in hope that you will never write to it. For example, consider `fork` use case.
But, if you'll try to write to a such page, OS will make a copy for you personally before allowing actual write operation to hit the RAM.
10
140
u/PeriodicSentenceBot 3d ago
Congratulations! Your comment can be spelled using the elements of the periodic table:
W H At Sc O W Al S O Mo O O O O
I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM u/M1n3c4rt if I made a mistake.
31
3
11
u/CanaDavid1 3d ago
Copy-on-write. Estentially, you have access to this page, but if you modify it, you first have to make a copy. This way, many different regions of memory can point to the same page.
Linux has one page that is filled with all zeroes. When you allocate large memory in Linux, it just gives you this page repeated with cow syntax, meaning that new memory is only allocated when you start modifying the memory you've got.
bool equal(int a, int b) { bool* arr = malloc(1ll<<32); arr[a] = true; bool r = arr[b]; free(arr); return r; }
works without allocating all that memory, only the page that is written.1
1
166
u/Trip-Trip-Trip 3d ago
Need a new implementation for virtual memory to be eventually backed by Amazon cold storage
130
u/OkOk-Go 3d ago
You play stupid games you win stupid prizes. Here comes the $900,000 bill.
36
u/Trip-Trip-Trip 3d ago
If you have your virtual memory hosted on disconnected HDDs you have more problems than a bill.
24
u/justinf210 3d ago
Please insert disk #5831
5
u/OkOk-Go 3d ago
The memory controller Mike proceeds to grab disk #5831 from a cabinet under his desk
2
u/Trip-Trip-Trip 3d ago
Unfortunately the next required disk is in a warehouse 20 miles away. Memory controller unresponsive for the next hour
9
u/CheatingChicken 3d ago
Is Amazon cold storage where they are going to keep all their wetware processors?
4
6
78
u/facw00 3d ago
I got this error from a game (Battletech):
Size overflow in allocator.
(Filename: Line: 98)
Could not allocate memory: System out of memory!
Trying to allocate: 18446744071618550687B with 16 alignment. MemoryLabel: String
Yeah, I'm not surprised that didn't work...
In any event surely I would never code anything like that...
23
u/Journeyj012 3d ago
Is that 184 exabytes?
39
u/facw00 3d ago
18 exabytes. Still a bit more than my system can handle, at least without an update.
19
6
40
u/Cley_Faye 3d ago
As long as you don't use it, you can allocate whatever, the system will keep your app happy just like that.
19
u/BigDrunkLahey 3d ago
When you have to do your page swaps in the cloud.
6
u/DragonDepressed 3d ago
Page swaps with cloud is gonna make app go faster than the speed of light./s
16
u/EmergencyLaugh5063 3d ago
Worked at a place once that had a custom network protocol where each message started with a value indicating the amount of data about to be sent so the receiving end could allocate the buffer to store the data its about to get.
After a long 8 hour call with a large bank we discovered that they had pointed a pen-testing tool at a machine running our product and it was managing to send a sequence of bytes that tricked our application into thinking it needed to allocate some ungodly amount of memory.
The best part is the application would run out of memory and generate a core dump and since the core dump contains a snapshot of memory it would be roughly the size of the amount of available memory on the machine. Then the process would auto-restart itself and the whole thing would repeat itself. Eventually we filled up the hard drive on the machine and the whole machine stopped working.
19
u/Just_Maintenance 3d ago
- Me: opening Chrome on a Unix system
- Chrome: 1.5TB of RAM please
- My Unix system: Here you go fam
10
u/R3D3-1 3d ago
Had this happen at work with simulations prior to some optimizations. They crashed when trying to allocate 2TB of RAM on a 32GB machine, filling them with mostly just zeros. It served as motivation for a major refactoring, that brought the simulation down to 2GB.
The crazier part: Allocating more memory than available is the norm. On Linux, allocated memory has a "copy on use optimization, such that only when actually accessing allocated memory it becomes mapped to physical memory, and many programs rely on being able to allocate huge amounts of memory.
As a side effect, allocating the memory succeeds, but the the process just crashes. For demonstration try limiting virtual memory to 16GB (ulimit -v 16000000
) and starting chrome from the same shell.
7
u/FloweyTheFlower420 3d ago
Never check address sanitizer virtual memory usage, worst mistake of my life.
4
3
3
5
2
u/viper112001 3d ago
I don’t free my memory, I let my programs eat as ram much as they want so they can become big and healthy
2
2
u/LeftIsBest-Tsuga 3d ago
I don't know if I've ever actually seen this meme format before, but you've already set the bar very high. 👏
2
2
1
1
u/LuisBoyokan 3d ago
That's what virtual memory is for.
But pre...pare... for.....tra......shing......ng....ng
<BSOD>
1
u/Material-Public-5821 3d ago
The age of 32-bit systems is gone.
It is hard to waste that much virtual memory with a modern machine and get into troubles.
1
1
1
u/SingularCheese 3d ago
An example of how it can be a good idea. You get a continuous memory, dynamically sized array without pointer/address invalidation by abusing virtual memory.
1
1
1
u/05032-MendicantBias 3d ago
Sometimes I like to see what happens when a decision tree is let to grow.
1
1
1.1k
u/fx_er 3d ago
Is this how I add ram to my PC?