Jump to content

Got this idea when I created a program that would memory leak. I was testing the program and didn't close it in time, and so the system hung for minutes until returning back, terminating the program for memory resources.

 

So, I was wondering why can't Windows have some pre-allocated pool of memory, or force allocate it when there are low memory resources (so that it doesn't hog memory all the time) so that it can function and actually carry out tasks to handle memory overflow situations?

 

I think the problem is that Windows doesn't differentiate between RAM and page file. It also thinks the page file as usable memory, but of course it's really slow. I don't think it tries to stop the process that is leaking memory even if the system has hung (not really hung, but running really slow at the point of hanging). Because after Windows has terminated the program, I can see that my page file allocation has reached 100%. Which means Windows doesn't declare a mayday, until it is actually running out of "memory" (page file included, but that is obviously slow and results in a system hang.)

 

One thing I might be missing is that the program could have been terminated by encountering an exception of not being able to allocate more memory. Is there an exception like this in C? Or was it force terminated by Windows? And if so, what if the program doesn't endlessly keep taking memory, but takes a lot more memory than physical RAM so page file has to be used, and it is actively reading and writing to all the parts of its memory, including the page file? Doesn't this mean Windows is basically hung for ever until force shutdown? Because if Windows won't try to terminate this program because of poor system performance detection, it will keep pegging the system drive and memory at 100%.

 

Regarding my idea of pre-allocating some memory, Windows already does this regarding the CPU resources. Windows has process priority system, so if the CPU is pegged at 100%, Windows processes which generally have more priority (or actually everyone having the same priority so nobody overtakes each other on CPU resources), Windows doesn't hang even if a process is taking a lot of CPU resources. I don't why they didn't implement something like this for memory.

PLEASE MARK COMMENTS AS SOLUTION IF SATISFIED!!

bigger number better, makes me look cooler.

Link to comment
https://linustechtips.com/topic/1545887-resources-management-idea/
Share on other sites

Link to post
Share on other sites

3 hours ago, Gat Pelsinger said:

One thing I might be missing is that the program could have been terminated by encountering an exception of not being able to allocate more memory. Is there an exception like this in C?

A malloc would return an error if there's no memory available. That'll happen when both the physical RAM and swap are full. 

 

3 hours ago, Gat Pelsinger said:

I think the problem is that Windows doesn't differentiate between RAM and page file. It also thinks the page file as usable memory

That's as designed, and is the whole point of swap. If you don't want it because it's too slow you can disable it, but if enabled it'll be used if needed because slow is always considered better than a program crash/data loss.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×