OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 12:44 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Allocating a memory area for vmalloc
PostPosted: Wed Mar 27, 2024 3:38 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
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)?


Top
 Profile  
 
 Post subject: Re: Allocating a memory area for vmalloc
PostPosted: Wed Mar 27, 2024 3:50 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3195
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.


Top
 Profile  
 
 Post subject: Re: Allocating a memory area for vmalloc
PostPosted: Wed Mar 27, 2024 7:25 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
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)?

APIC MMIO is usually located within that address range.


Top
 Profile  
 
 Post subject: Re: Allocating a memory area for vmalloc
PostPosted: Thu Mar 28, 2024 1:58 pm 
Offline
Member
Member
User avatar

Joined: Sun Jul 21, 2019 7:34 am
Posts: 300
Octocontrabass wrote:
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)?

APIC MMIO is usually located within that address range.

What is the approximate size it use?


Top
 Profile  
 
 Post subject: Re: Allocating a memory area for vmalloc
PostPosted: Thu Mar 28, 2024 10:28 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group