ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
One major problem with all the OOM handling ideas are they are hostile. They assume the situation is out of control and desperate.
What the programmers need is help to avoid getting the user into such dire straits. Consider two scenarios....
* Nibbled to Death by Ducks. The program is malloc'ing many tiny chunks of memory. Eventually it starts thrashing. A quarter of an hour later it runs out of memory and malloc returns 0 or some friendly OOM killer hits it on the head. Assume the OOM killer doesn't, what can the programmer do? Pop up a friendly dialog box, and shutdown neatly? Nah! Not enough memory to do that!
* Grabbing a large chunk. I was using Ghost View. For various reasons it asked for a huge amount of memory. Malloc didn't return zero, there was enough swap. However, the system turned to sticky mud and stayed that way until I could kill the X server 15 minutes later...
Now assume that these two programs are written by responsible, caring programmers. What could they have done to stop entering this domain? Nothing. The OS hates users.
Now if the OS had a "memory getting low, system getting slow" signal, and could send that signal to all programs. Then in the Nibble to Death by Ducks scenario the programmer could start bailing out in a clean and friendly manner.
If the OS had a "malloc, but not at the cost of the system" malloc, then any programmer knows when he is going to be grabbing a really large chunk. So when he grabs a large chunk he uses the "friendly caring malloc" and checks the return code. If the answer is bad, he pops up a friendly message that tells the user that he really doesn't want to do that and why. The user may at his own choice and peril say "do so anyway".
I'm sure the friendly caring malloc could be written in userland, any hints?
The "memory getting low, system getting slow" signal needs some OS support I think.
I don't know about friendly malloc. But I know before dynamic allocations were not possible people used to grab a large chunk of memory and do a cursor based implimentation of lists which allowed them to handle their memory safely and efficently. Its a pity that we still have such hopeless garbage collection mechanisams even today. Any way, if you use node space implimentation you need to have a good approximate idea of how much memory you need. And it is by all means grossly inefficient. But this will atleast will let you know initially itself that if you have enough memory before you do something that causes the whole system to hang.
Any better ideas anyone.? I am also interested in knowing more.
--Sarin
I've done things similar to what of which sarin is speaking.. but implementing them with malloc as well.. it involves malloc'ing a chunk of memory, enough to handle most stuff, and then using an array of pointers into the malloc'd chunk.. cleanup is necessary to keep the "swap" from fragementing..
My implementation was very simple, but I suppose that it would be possible to also implement a swapfile style access to this block of memory, so that if more memory space was needed, it could save out anything that it could to make room for other stuff. but you're talking about a fairly complex interface.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.