recommended kernel allocation methods?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Gizmo
Member
Member
Posts: 41
Joined: Fri Aug 03, 2007 3:41 am

recommended kernel allocation methods?

Post by Gizmo »

I am making my first pmode kernel and I probably have a ways to go before worrying about page allocation just yet.

I am considering a word map where each word is a process id but the top 3 bits are flags.

Under normal situations the word is a process ID that belongs to the process who allocated this allocation block.

There is a case for shared blocks that contain an index into a list of shared memory that contains the process id's that have this memory mapped into their separate address spaces.

There is another case for reserved blocks for example blocks where the kernel is statically allocated as well as bios areas etc.

There is a case for dma blocks which contain an index into a list of structures with the process id of the process that allocated the block which receives the real address so it can send it to the device its dma'ing with.

Blocks whose word is 0 is unallocated (of course).

There is a global index to this list of allocation blocks so the allocation routine does not start at 0 every time and have to check each block, it is almost always at the last block allocated (except when it reaches the largest physical address available on the system then it starts at 0 and finds unused blocks again).

Blocks are unallocated when a process request (free()) so via software interrupt or the process that owns them self terminates or is terminated by outside means.

Blocks represent 4 mb of physical address space and there are 8192 blocks to address up to 34 gb.
I may decide to use 2mb blocks instead because alot of memory might be waisted in the shared memory and the dma blocks. I dont think I can go smaller than 2mb because to be x86-64 compatible I will need to use 2mb pages and I do not know of anyway to prevent a process from accessing parts of a page it didn't ask for as well as avoiding having a very large allocation map.

I could avoid using allocation block for dma by using some software interrupt that allows a process to obtain a physical address translation for a block so it can use variable size dma buffers as long as tey are smaller than the allocation size since there are no guaranties that 2 or more blocks will be adjacent to each other. I may have to se a flag bit to indicate that its unsafe to allocate this block to another process for a certain amount of time in case if the process requesting a dma transfer dies and the dma continues- if another process used the block its data would be trashed (which is why I wanted a separate dma classification in the first place).
Post Reply