Monday, December 19, 2005

Back To The Kernel

It's not that the app_server is ready and polished or anything close - but it's in an acceptable state. For now, my main focus is back in the kernel, although I'll come back to the app_server from time to time in the next days and weeks.

I am currently looking into getting paging support for Haiku. That's the feature you know by the term "virtual memory" or "swapping". Plain and simple it makes Haiku support more memory than you have installed in your computer. When the RAM is full Haiku will utilize the hard disk as an additional backing store.

But why would I start working on this before Haiku even runs stable? One reason is indeed to increase the system stability: currently, it's almost impossible to let the system run out of memory. Am I contradicting myself here? It looks like I do, granted, but let me try to explain what I mean. No, you don't have to know. If you like, you can just skip to the next paragraph. Yeah, you don't have to read that one either if you don't like :-))

Anyway, when an area of memory is allocated, the memory is not really taken from the system memory - it's just reserved. Only the memory you are really using is actually taken from the system page pool (where one page is an architecture dependent amount of memory, usually it's 4096 bytes), we call this "committing memory". Especially with binaries, the areas created for them are usually much larger than what finally makes its way into the memory, certain functionality that you don't use of your web browser or debug info aren't loaded into memory to safe space and time.
So theoretically, we could always promise more memory than we can actually deliver. Just think about the main stack area in BeOS: it's a 16 MB area per application. You don't need that many fingers to figure out how many applications you could run if the system would be entirely honest with you (well, at least a few years ago you would have been successful doing so). So yes, it's lying. If every application would actually need its whole stack, the system would need to stop them before memory becomes really tight. This technique is known as "overcommitting" - the system pretends to have what you might need, because it assumes that you won't need it.
Therefore, it shouldn't lie to you that often, it should choose these occasions wisely. Haiku only uses this for stacks. For everything else it makes sure it can deliver the memory it had previously promised to you. This can result in "out of memory" situations even though there are plenty of free pages left - the problem with those pages is that they are promised to someone else. They may still get used for system caches and the like, but they are unavailable to applications.

And that's where the swap file comes in: having some extra space in there, the system can promise much more memory, and thus, can actually use up those pages for real, it can really have no free pages left. In other words, to run out of memory (to be able to test the kernel in these situations) it needs to at least think it has a swap file.

The Haiku swap file implementation will be anything but spectacular, but it'll hopefully work good enough for our target audience - the usual desktop user don't have that heavy requirements there. On the other hand, it will probably work better than the one in BeOS - at least I can hardly imagine how it could run that badly :-)

11 Comments:

At 11:18 AM, drac said...

Eine Frage hätte ich an Axel D.
Wenn du bereits an dem Kernel arbeitest, wird eingentlich Multi-User Fähigkeit jetzt schon implementiert oder zumindest berücksichtigt?

 
At 9:39 PM, reallyjoel said...

While I don't really know what you are writing about half the time, I still want to write something here. Not to ask technical details, but to let you know there are lots of people following your work. I've been hyped up about Haiku since day 1, and I long for it's first releases. Have a merry christmas and keep up the great work.

 
At 3:04 AM, timezero said...

Merry x-mas!
Keep up the good work!

 
At 10:09 AM, wkornew said...

Hey Axel!
Will we still have the VirtualMemory preflet or can this be managed by the kernel in a much better way, so that we don't have to bother the user with such system details?

Hau wieder rein in die Tasten! ;)

Fröhliche Weihnachten und nen guten Rutsch wünsch ich dir!

Gruß,
Waldemar

 
At 2:58 PM, Axel Dörfler said...

Merry christmas everyone! :-)

To drac: multi-user will only be implemented partially for R1, similar to what is possible with R5. It won't be really secure, though.

To wkornew: this is likely to stay. The size of virtual memory is still something of interest for the user. It's not for everyone, that's for sure, but I wouldn't feel too well removing it.
Heavy virtual memory usage is causing a big impact on system performance. IMO we should always try to communicate system concepts like these to the user. I don't want to have dumb users, I'd like to have users that are able to understand what the system is doing at any given time if they so wish. And not because they are über-geeks, but because the system is so transparent and easy to understand.

 
At 4:35 PM, wkornew said...

To axeld: I agree that we should not try to have dumb users, but some just don't want to care. Me included. I only know that the amount of virtual memory should be twice the amount of RAM, most of the time. But with 2GB of RAM it can probably be turned off, completely. How can one know which value is the best for me without searching the internet? Haiku should be able to do this for me if I don't care. But if we keep it configurable then we must at least provide a one page guide to quickly configure important system settings and introduce things we do differently compared to other OSes (and get a slight clue of their meaning).

 
At 8:53 PM, Axel Dörfler said...

To wkornew: I thought I've explained in this very blog post why turning off virtual memory is never a good idea, regardless of how much real memory you have. Maybe I didn't manage to communicate this idea too well, though :-)

Anyway, the "twice as RAM" rule stems from ancient Unix systems and shouldn't be true anymore for today's operating systems. For Haiku, the size of the swap file directly impacts the size of memory the system has - if you add 10 MB, you have 10 MB more memory. So if you have an application that says "out of memory" you might want to increase that value, if you don't have one, you don't have to care :-)

Haiku will also try to have good and useful default values for everything - the preferences applications should only matter to you if you actually want to change something, and that includes virtual memory as well. More complex settings like having more than one swap file and on different volumes are not likely to be exposed to the user via the preferences apps, though.

 
At 12:59 AM, reallyjoel said...

"More complex settings like having more than one swap file and on different volumes are not likely to be exposed to the user via the preferences apps, though." I don't understand why not? Users who don't care won't open the prefs, users who only want to change basic stuff go the first tab of the VM Prefs window, users who are looking for even more detail will go to the advanced tab.. hiding settings is bad, IMO.. Maybe the way to go is to make an advanced prefs app that can change in greater detail, and with more admin-friendly layout.

 
At 9:58 PM, Axel Dörfler said...

To reallyjoel: In principle I agree with you: *useful* settings should be accessible via the GUI. But writing such a GUI takes time, and I am not sure someone finds the time to extend our VM preferences app for R1. It's definitely not a very important setting for most users, IMO.

Maybe we'll just add a "let the system manage the swap file automatically" and make this setting good enough to make use of more than one hard drive.

 
At 11:14 AM, wkornew said...

Which of the following features planning for multi-user support?
* user groups
* simple file access rights
* apps running as different users

 
At 3:58 PM, Axel Dörfler said...

To wkornew: For R1, this will be all of the list, I guess. At least that's what R5 supports AFAICT.
R1 multi-user won't be secure at all, though, even though basic user management will be there.

 

Post a Comment

<< Home