Valix Memory Management
Valix Memory Management
This is how I plan on implementing memory management in my kernel (less=more) for my OS Valix:
Two binary trees make up the kernel heap. One binary tree keeps track of all free memory blocks, sorted by size, so that the smallest one that is just large enough can be selected easily. The other binary tree keeps track of memory that is in use but may be freed later. This second tree is sorted by address instead of size so that the blocks can be easily freed. When a block of memory is allocated, it moves from the first tree to the second. When a block is deallocated, it does just the opposite.
Memory blocks are found by getting the information GRUB provides for us during boot. When a block is allocated, if the block is bigger than needed, it is split up. When there is no block large enough to use, contiguous blocks are joined.
This is done entirely without paging or any sort of virtual memory, it is a physical memory manager. Valix doesn't run userland binaries, so virtual memory is unnecessary: the kernel is the only binary running.
What do you guys think? I've already implemented 90% of this, and it *seems* to work just fine... Is there a way to increase the efficiency? I do plan on using some sort of self-balancing setup later (red-black trees, perhaps?) More importantly, are there any drawbacks?
Two binary trees make up the kernel heap. One binary tree keeps track of all free memory blocks, sorted by size, so that the smallest one that is just large enough can be selected easily. The other binary tree keeps track of memory that is in use but may be freed later. This second tree is sorted by address instead of size so that the blocks can be easily freed. When a block of memory is allocated, it moves from the first tree to the second. When a block is deallocated, it does just the opposite.
Memory blocks are found by getting the information GRUB provides for us during boot. When a block is allocated, if the block is bigger than needed, it is split up. When there is no block large enough to use, contiguous blocks are joined.
This is done entirely without paging or any sort of virtual memory, it is a physical memory manager. Valix doesn't run userland binaries, so virtual memory is unnecessary: the kernel is the only binary running.
What do you guys think? I've already implemented 90% of this, and it *seems* to work just fine... Is there a way to increase the efficiency? I do plan on using some sort of self-balancing setup later (red-black trees, perhaps?) More importantly, are there any drawbacks?
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
Re: Valix Memory Management
At the moment, no, but it should be easy to add that. Is there an instance where I might need that?
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Valix Memory Management
I know you don't have virtual memory and paging yet, but being able to allocate page-aligned blocks might make life easier later. You might also want to note that some things require an aligned address (to 2, 4, 8 bytes, as an example) including devices and SSE (IIRC).
Re: Valix Memory Management
You've got it backwards I used to have paging and virtual memory, and I've gotten rid of it.
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Valix Memory Management
Even so, the remainder of my post is valid.
Re: Valix Memory Management
why?xvedejas wrote:You've got it backwards I used to have paging and virtual memory, and I've gotten rid of it.
Re: Valix Memory Management
Because I don't (think) I need it... that's why I'm asking opinion...
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Valix Memory Management
Then what is the point of the kernel if you don't have anything running? I have a feeling that you will get tired of putting this much effort into a static shell pretty fast. Plus the fact that paging makes a lot of kernel functions easier rather than harder, and is pretty simple to implement (my memory manager is ~80 lines with multiple process support).xvedejas wrote:This is done entirely without paging or any sort of virtual memory, it is a physical memory manager. Valix doesn't run userland binaries, so virtual memory is unnecessary: the kernel is the only binary running.
-
- Member
- Posts: 65
- Joined: Sat Jul 04, 2009 9:39 pm
Re: Valix Memory Management
I think he wants the kernel to "run" programs like some kind of interpreter in a managed environment.NickJohnson wrote:Then what is the point of the kernel if you don't have anything running?
Like what?Plus the fact that paging makes a lot of kernel functions easier rather than harder...
The whole point of a virtual address space is so that two processes can seem to have their own separate memory. In the OP's scenario, he doesn't need any paging. I suspect "Valix" is an attempt to avoid the "dirty work" of a kernel: user-level process switching, paging, system calls, etc.
Last edited by manonthemoon on Mon Aug 03, 2009 7:48 pm, edited 1 time in total.
Re: Valix Memory Management
manonthemoon is quite right.
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net