I plan to implement vmalloc for the kernel memory, but I can't decide which part of the virtual memory to define for this.
I want to do like Linux, allocate a 128 megabyte virtual memory area from 0xF8000000(3 GB + 896 MB) to 0xFFFFFFFF(3 GB + 1024 MB).
I have a x86 protected mode higher half kernel, in the kernel space VA = PA + 0xC0000000,
which means that if there is memory in the physical memory area from 0x38000000(896 MB) to 0x3FFFFFFF(1024 MB) that I need to put into the kernel (for example ACPI or something like that),
then I will not be able to map it so easily as with all other physical memory related to the kernel.
I will give all the free physical memory from this interval for user applications and there will be no such problems with it.
According to the wiki(https://wiki.osdev.org/Memory_Map_(x86)), the first gigabyte of physical memory will not contain anything that drivers will need.
Can I just hope that the last 128 megabytes of the first gigabyte of physical memory will not contain data that I will have to map for drivers (for example, ACPI and so on)?
Allocating a memory area for vmalloc
Re: Allocating a memory area for vmalloc
Memory that drivers need should be marked as unavailable by UEFI or BIOS memory map, so I don't see the issue. Also, I don't see how virtual memory management relates to physical memory. You should add available physical memory to a pool. You then have a physical memory allocator that you use to get memory for a virtual memory object. For things like PCI BARs, you read out the BAR physical address and then map it to a virtual memory address, and mark it as "don't free" if something happens to try to free the virtual memory address.
A virtual memory manager that allocates 4k pages could be implemented by scanning page tables, and then either mapping them to physical addresses (using the physical memory manager), or marking them as allocated, and letting the page fault handler allocate physical memory on demand.
A virtual memory manager that allocates 4k pages could be implemented by scanning page tables, and then either mapping them to physical addresses (using the physical memory manager), or marking them as allocated, and letting the page fault handler allocate physical memory on demand.
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Allocating a memory area for vmalloc
APIC MMIO is usually located within that address range.mrjbom wrote:Can I just hope that the last 128 megabytes of the first gigabyte of physical memory will not contain data that I will have to map for drivers (for example, ACPI and so on)?
Re: Allocating a memory area for vmalloc
What is the approximate size it use?Octocontrabass wrote:APIC MMIO is usually located within that address range.mrjbom wrote:Can I just hope that the last 128 megabytes of the first gigabyte of physical memory will not contain data that I will have to map for drivers (for example, ACPI and so on)?
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Allocating a memory area for vmalloc
It depends on how many APICs are in your system, but they don't use much - maybe 4kB for the local APIC and 4kB for each IOAPIC.
But why do the physical addresses matter? You can use paging to assign whatever virtual addresses you like.
But why do the physical addresses matter? You can use paging to assign whatever virtual addresses you like.