G
G
German2020-02-23 09:48:10
Programming
German, 2020-02-23 09:48:10

How to implement memory management in the kernel?

I can not fully understand how to implement virtual memory and how to allocate it for the kernel and processes.
Now I'm interested in how to implement memory management at the kernel level.

As I imagine it:
1. Divide the available RAM into equal blocks (frame) of 4KB.
2. Then, if we want to allocate a certain amount of memory for a variable in the kernel, then we look for a certain number of blocks (frames) in memory, the total size of which is not less than the requested amount of memory. Then we enter the address of the first block, the number of blocks in a
certain table and give the address of the first block for data to this process.

But will it be optimal to go through all the pages of memory every time in search of a free one?
Is it right to give a whole page at once if the required volume is small?

How to implement all this? And what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
none7, 2020-02-24
@none7

x86-64 processors can address 256TB of virtual memory. Would it be optimal to enumerate all 4k blocks? Would it be generally acceptable to store information about every 4k block of each process, with this amount of virtual memory for each? Obviously, a size-indexed free block table is needed. Windows, by the way, in order to avoid the growth of these tables, allocates virtual memory in blocks of 64k.
Usually, the heap is responsible for allocating virtual memory for variables, and gives the application as much memory as requested, regardless of the size of the virtual memory block. Naturally, the first selection is not less than one page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question