Kernel dynamic structs
Posted: Sun Sep 24, 2017 4:51 am
Hello,
I have a misconception. I was thinking of implementing the buddy algorithm for physical memory allocator, but in theory the internal structures for buddy algorithm have dynamic size. E. g. for 1MiB you can have:
- 512KiB 512KiB
- 32KiB 32KiB 64KiB 128KiB 256KiB 256KiB 128KiB 128KiB
In the first case the list will have two nodes, while in the second case the list will have 8 nodes. This is just an example, let's say for 2 nodes we need of 4KiB of memory (4KiB is the minimum for physical page size). When I need a new physical page (also virtual page), how can I map the new virtual page in all processes? This is not the only example, the same situation is for open files. When a process open a file, all processes need to know that a new file have been opened.
Briefly, how do I update the virtual memory of the kernel in all processes when it is changed in a process?
I have 2 solutions, but it seems to me primitive.
1. I have a separate process for kernel and when someone wants to allocate memory or to open a file, he send a message (IPC) to the kernel process and he wait for a response.
2. For the physical memory allocator I calculate the maximum memory I need and reserve it. For open files, I reserve memory for x files and can be maximum x open files at the same time. But, for me, that is not a solution, because if x is 1000, I have reserved memory for 1000 open files but at this point only 5 files are open. So it will be a waste of memory.
I want a better solution. I'm sure there's something better.
I have a misconception. I was thinking of implementing the buddy algorithm for physical memory allocator, but in theory the internal structures for buddy algorithm have dynamic size. E. g. for 1MiB you can have:
- 512KiB 512KiB
- 32KiB 32KiB 64KiB 128KiB 256KiB 256KiB 128KiB 128KiB
In the first case the list will have two nodes, while in the second case the list will have 8 nodes. This is just an example, let's say for 2 nodes we need of 4KiB of memory (4KiB is the minimum for physical page size). When I need a new physical page (also virtual page), how can I map the new virtual page in all processes? This is not the only example, the same situation is for open files. When a process open a file, all processes need to know that a new file have been opened.
Briefly, how do I update the virtual memory of the kernel in all processes when it is changed in a process?
I have 2 solutions, but it seems to me primitive.
1. I have a separate process for kernel and when someone wants to allocate memory or to open a file, he send a message (IPC) to the kernel process and he wait for a response.
2. For the physical memory allocator I calculate the maximum memory I need and reserve it. For open files, I reserve memory for x files and can be maximum x open files at the same time. But, for me, that is not a solution, because if x is 1000, I have reserved memory for 1000 open files but at this point only 5 files are open. So it will be a waste of memory.
I want a better solution. I'm sure there's something better.