i have 32 of them, dont worry! And with how shitty the webapps has been, i dont even have to launch my beautiful program half of the time. I stopped using Instagram on pc cause having it as a tab in Chrome legit eats 9GB of RAM, and thats just the worst i caught it eating
I develop Minecraft modpacks for fun in my free time.
At peak I need IntelliJ (java mod dev) + VSCodium (packside file editing) + 2 parallel Minecraft instances (some stuff requires that) + background music (for the lock-in) + discord (where my dev team is). I wouldn't need your program either, even though it is beautiful.
Correct, this is my personal gaming computer with way too much ram that would be better utilizied in s data center, 20 times better actually (5% vs 100% utilization)
I remember blue-screening my old PC by simply having Chrome opened, listening to music and playing Satisfactory. It was 2021 and i had 8 gigs of DDR3 RAM.... Now i have 32 and i often forget to close one game before opening another and dont notice lol
For me personally, 32GB still isn't enough because I may need 16GB RAM to play with FUSE a little bit (actually a Windows driver allowing FUSE), and I still need to both run the game and open chrominum based browser.
The operating system kernel will not assume intent on behalf of the application
I might be wrong, but my intuition says it would be weird and inefficient for the operating system to wait on allocation until the application commits a page. Without being a kernel expert, this sounds like the user mode application would need to communicate every read and write via the kernel just to check that the pages have actually been allocated, and then do that on-demand
For performance reasons, you don't want to cross the kernel barrier more than strictly necessary. Writing to virtual memory is hardware accelerated (exceptions apply), so as long as you have a valid page, the OS kernel don't need to be involved in normal reads and writes. If you read or write outside of that boundary, the CPU will raise a trap/exception that will be caught by the operating system which immediately terminates your application for being a bad boi indeed
Edit : if it does indeed not get allocated, I would assume that would be the doing of the allocator, rather than the operating system
Some syscalls like mmap in unix like system, you could pass a MAP_POPULATE and MAP_NORESERVE to predict this behavior in a new allocated memory block. malloc from glibc and musl doesn't populate the memory immediately. So we should expect some kernel trick here
Hmm.. Ok, I see.. So, my assumption is that MAP_NORESERVE may introduce a performance penalty, since the next access would necessarily be a syscall. There might be a reason for this trade-off however, I could see that. And, again this is not my area of expertise, there might be some trick that I'm unaware of, like maybe the operating system has some user-mode space to jump to before system calls that keeps track of all virtual memory address as an added copy to the ring 0 configuration.. I have no idea. I'm riding on a hunch
I read some of the other comments, and they mentioned getting page faults which seems unlikely for the given scenario. At least, like a "real" page fault. My gut feeling is that the uninitialized pointer is, by the compiler, set to some predefined address and then the compiler+allocator looks at first access to a memory address by static analysis and then if that memory address asserted to be some predefined zombie-value at that point it would ask the operating system to allocate the memory address when it is needed. I only know this stuff at surface-level so I might be way off, but my thinking is that turning memset(a, 0, sizeof(char)*420) or a = {0} into a syscall would be prohibitively expensive. Experience tells me it's probably implemented in the most obvious and dumbest way possible, rather than some non-obvious trick
Edit : this is a question, though not formatted as such
Hm, some virtual machines or emulators could use this (MAP_NORESERVE) for preallocate a address space at user space, and after, creates mirrors memory with a backing through a file descriptor. Like map the address 0x4000 virtual to 0x1000 physical inside this fd.
Also exists a PROT_NONE for remove any access to the pages, so any read inside this address space could rease a SIGSEGV, of course, if this memory isn't allocated and served by a real backing yet
I remain suspicious... So, let's say I have this code :
auto mydata = malloc(sizeof(size_t) * 4096 * 4096 * 4096 * 4096 * 4096);
dostuff(mydata);
void dostuff(const void* data)
{
auto mptr = data;
while(true)
{
try
{
auto filteredbyte = *mptr++;
gclient::Samsung::collect_byte(filteredbyte);
gclient::LuckyGoldstar::collect_byte(filteredbyte);
}
catch
{
return; // we have it all
}
}
}
My assumption, would be that the compiler would statically assert that dostuff(mydata) attempts to access the memory, and at that point statically injects the allocation, rather than this being up to the operating system. Again, not an expert, I would just assume that lazy initialization would come at a tremendous cost.. There may be a trick here, but my naive assumption is that f.ex a syscall (being an interrupt, after all) would require context switching
Edit : jokes aside, I appreciate your input and knowledge. I'm surprised at how little I actually know about this. It's one of the things I've seem to have taken for granted
`malloc` keeps some heap space to avoid a syscall for small allocations. In this case, because the allocation is large, it won't even consider reusing some space, it will directly `mmap` some memory (a syscall that updates the process's address space in the kernel's records). This doesn't page-in the memory, so it isn't actually used yet. It is allocated page-by-page as needed. When a virtual address is accessed that doesn't have any physical page associated with it, the MMU triggers a page fault. This is an interrupt the operating system handles by checking the memory map of the current process, determining that this address is included in the process's address space (because of the previous `mmap`), and assigning a physical page to that virtual page in the MMU. Further accesses in the same page won't incur a fault, but this must be repeated the first time each page is accessed (or if a page is accessed that has been swapped out).
This is because "committed memory" still gets limited by Windows based on your physical RAM and pagefile limits, even if it never got any actual physical memory backing it.
Yeah pages aren't allocated till you try to interact with them. Interacting would trigger a page fault and then it will actually allocate a little (4KiB usually) if your data is below it.
The standard says that if you don't return anything from main it's like as if you returned 0. Still it's bad practice and you'll go to hell. The reason is that main is a C concept and between non standard variants, old k&r shenanigans and such, there are a bajillion incorrect or nonstandard ways to write it
A system alwys uses the ram for disk cache. Postgresql for example factors the system cache in. So it is not uncommon to have a postgres server with 80% "free" ram.
don't even need something like this on my laptop 11gb used out of 15.3(707mb reserved)
main computer has no ram at the moment, but otherwise would have 32gb with about 15 used on idle(windows is a hog) jumps to about 18 when browsing the web
1.0k
u/Dubmove 24d ago •
Did you reverse engineer chromium's source code?
357
u/elmanoucko 24d ago
-O3 optimizing it away: "I thought we were friends :'( ..."
65
u/Neutraled 24d ago
I'm guessing Sam's house is full of clutter because he needs to use every inch of his house.
155
u/DangyDanger 24d ago
system("pause")makes me irrationally angry61
u/GrandDukeNotaras 24d ago
This meme wave just gets better and better. I'd give you some RAM if I could
29
u/EatingSolidBricks 24d ago
All mapped nothing commited you just got bamboozled by virtual memory
9
u/WeakCelery5000 24d ago
This is a trick, Sam wants you to burn out the ram you currently have, faster.
5
u/unneccry 24d ago
Trust me i use all my 8GB of ram very frequently. Quite honestly i often use more
3
u/Kadabrium 24d ago
Does a ramjet leak ram
5
u/beloncode 24d ago
You aren't touching the ram, so the OS doesn't allocate it yet
8
u/EmperorOfAllCats 24d ago
This won't be actually allocated by OS without, say, memset() on this range. Source: had to write similar utility to test memory pressure.
29
u/farrell_987 24d ago •
I'll sell Sam altman my unused ram as a service for 500/gb/hr
16
u/XVO668 24d ago
I miss the days where you could just simply download more RAM.
9
u/SerDuckOfPNW 24d ago
Fewer memory leaks than a Bethesda game
15
u/sligor 24d ago
Still less memory than any Electron app
1
u/Odd_Confusion_9875 24d ago
Does this work? Unless it's written on, pagefault doesn't trigger so physical ram won't be committed, Also it's just 8 Gigs.
mmap() with MAP_POPULATE might work through
3
u/letmehaveanameyoudum 23d ago
fool, i create a custom OS and fill the entire physical RAM with 1s
1
u/throwawayfu3a5ek 24d ago
Back when I was doing c++ with pencil and paper in college, main had to return an int. I'm not sure if that has changed?
2
u/VonLoewe 24d ago
At least make it return, come on.
1
u/DOOMer_3D 24d ago
for(;;){(char*)malloc(4096)[0] = 'a';}
1
u/[deleted] 24d ago
time to mcp my machine with this as the only tool call
1
u/compiling 24d ago
Since you're on windows, you might be interested in a way to force the memory to stay allocated to your process instead of being paged out.
https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtuallock
1
u/A_72_ 24d ago edited 24d ago
Have lots of ram? Init a ramfs and use it to store temporaries, 1GB ram = 1GB free storage! Leave enough for basic task only.
1
u/Single-Virus4935 24d ago
A system alwys uses the ram for disk cache. Postgresql for example factors the system cache in. So it is not uncommon to have a postgres server with 80% "free" ram.
1
u/Pesoen 23d ago
don't even need something like this on my laptop 11gb used out of 15.3(707mb reserved)
main computer has no ram at the moment, but otherwise would have 32gb with about 15 used on idle(windows is a hog) jumps to about 18 when browsing the web
1
u/YakubReddit 23d ago
you should put it in
while (1)1
u/TheSWATMonkey 23d ago
1
u/whtbrd 21d ago
He hasn't seen how many chrome tabs I have open.
1
u/bruhred 20d ago
linux overcommits memory so uhm this won't actually allocate everything
0
u/alonjit 24d ago
the real horror is launching an executable when perfectly cromulent APIs exist.
-6
u/equinoxtrader 24d ago
Do you remember when this sub was with smart humor for smart people? We do remember.
-1
u/deanominecraft 24d ago
you can improve this by doing
-2
u/1XRobot 24d ago
You can tell a human wrote this, because AI can spell.
Claude, write some code for my joke. Make several mistakes so it seems like a human.