Page 1 of 1

Virtual address allocator in 64bit kernel

Posted: Thu Apr 20, 2023 9:12 pm
by colorglass
Is it necessary to implement a virtual address (or virtual space) allocator in a 64bit kernel?

When in the 32bit kennel, there are usually not enough virtual space to identically (offset) mapping the whole physical address space. And when kernel wants to access the physical memory where is not identically mapped to the kernel's virtual address space, it requests the kernel to find a free virtual address space to temporarily map that physical space.
In this way, there should be a virtual address allocator in the kernel for allocating the free virtual address spaces and recycle them when they are not used any more.

While in the 64bit kernel, there are enough virtual space in the kernel for creating a whole permanent identical (offset) mapping to the physical space.
And now the kernel wants to access the physical memory, it can just request the physical frame allocator for the physical memory and caculate its virtual address in its virtual address space.

So I think there should be no need to write a virtual address allocator in the 64bit kernel. Is there something I get wrong or missed?

Re: Virtual address allocator in 64bit kernel

Posted: Sun May 07, 2023 12:55 pm
by nullplan
You may still want a logical mapping of some memory to some other addresses. Personally, while I have a linear mapping at 0xfff8'0000'0000'0000, it only extends up to 0xfffb'ffff'fffff'ffff, and the rest of virtual space still needs management. My kernel runs at the -2GB line, so that part is taken care of. Also, I want to have a contiguous kernel heap independent of memory fragmentation in physical RAM. I mean, I don't anticipate needing any large objects, but you never know. And maybe in future some other need will arise.

Managing memory directly on top of physical RAM runs into the issue that you are tied directly to its fragmentation. At work, I once had a problem with that. On a system with very little RAM and no virtual memory, the only memory blocks left free were 2MB in one place and 3MB in another. So naturally, a request for 4MB failed. Although enough RAM would have been free to fulfill the request, it was not contiguous, and the system had no way to make it appear contiguous.