virtual memory manager
virtual memory manager
i wrote physical mm. Now i have to allocate memory for my kernel structures and memory for device drivers. Kernel structures takes some 30 or 40 bytes. For device drivers i have to allocate in MBs. So what should i do in vmm. What are the best algorithms for managing virtual memory. Do i need another memory manager to allocate memory in terms of bytes i.e should a special malloc implementation is required. I have to allocate memory for kernel from heap. But for device drivers i have to allocate from somewhere else like 0x80000000. I don't get it. Now there is no user programs requesting memory but in future i have to allocate memory. It is also done by vmm. So how do i implement my vmm?
Re:virtual memory manager
hi..
You have done ur physical mem manager. So u must now be able to allocate memory in terms of pages..
What i have done is :
in short virtual memory manager will take a page from phy mem man and then bind it in current page directory..
if u r having problem with Page Directories & Page Tables then u must see tutorials on Memory Management (1 & 2) by Tim Robinson at www.osdever.net
You have done ur physical mem manager. So u must now be able to allocate memory in terms of pages..
What i have done is :
Code: Select all
class PhyMemMan
{
void * allocatePage();
bool freePage(void * address);
}
class VirMemMan : public PhyMemMan
{
void * kmalloc(int bytes);
bool kfree(void * addr);
int bindPhyToVir(void * virtualaddr);
bool unbind(void *virtualaddr);
}
in short virtual memory manager will take a page from phy mem man and then bind it in current page directory..
if u r having problem with Page Directories & Page Tables then u must see tutorials on Memory Management (1 & 2) by Tim Robinson at www.osdever.net
Re:virtual memory manager
Where to allocate from heap memory? Also need to keep track of pages used for heap memory. Then how do i track of virtual memory, from where to allocate next. A global variable wouldn't be sufficient. I don't want to waste my virtual memory space either. bitmap for <1mb and 1mb to 16 mb. stack for the rest of memory. I need a better way of managing virtual memory. Not just count the bytes and return the address. Coz i don't want to have a redesign. I am thinking of making a slab allocator. But it couldn't be used if i have to allocate in terms of MB's so what do i do?
Ouch! I haven't look at osfaq for sometime(may be a long time). Now only noticed that virtual address allocator page is changed. Previosly there was no content. Keep up the good work guys.
Ouch! I haven't look at osfaq for sometime(may be a long time). Now only noticed that virtual address allocator page is changed. Previosly there was no content. Keep up the good work guys.
Re:virtual memory manager
Hi,
In my kernel i've adopted the following design
++++++++++++++++++++++++++++++++++++
Slab Allocator
++++++++++++++++++++++++++++++++++++
Virtual Regions Allocator
++++++++++++++++++++++++++++++++++++
Physical AAllocator
+++++++++++++++++++++++++++++++++++
in the low level, the physical allocator can allocate pages frames from the physical memory. it is intended to give a backend storage to the virtaul region allocator
the virtual region allocator allocates region from the kernel heap witch starts just after the 4096-aligned end of the kernel image+objects allocated at boot time. the VRegion allocator can allocates only a multiples of VPAGE (witch are in my kernel equals to PAGE = 4096bytes). this allocator uses a VRegion object to represent a region in the heap. there are tow lists of region : the free list and the used list, the free list is kept sorted by address order to facilitate free regions merging.
There is another object: SelfBuffer a generic object that take a buffer (array of bytes), a size 's' and then can allocate objects of size 's' from that buffer. the new operator is overloaded to create the SelfBuffer object at the start of the buffer and then creating a linked list of free object in the remainig space.
To bootstarp this allocator, i map the first page of the heap, create an empty SelfBuffer on that page to hold VRegion, then i allocate tow VRegion objects from that buffer, the first represent the page itself, the second the remaining free heap space. the VRegion allocator takes care to create a new buffer each time there is less than 2 free objects in total in the all existing SelfBuffer's (because creating a new SelfBuffer need a new VRegion object t be allocated).
The Slab allocator is implemented on the top of the VRegion allocator and uses also SelfBuffer to represent the slabs.
thus, when i need to allocate small objects i use the salb allocator. when i need to allocate page_aligned large objects i use directly the VRegion allocator.
I hope this would give you some ideas
Salam
In my kernel i've adopted the following design
++++++++++++++++++++++++++++++++++++
Slab Allocator
++++++++++++++++++++++++++++++++++++
Virtual Regions Allocator
++++++++++++++++++++++++++++++++++++
Physical AAllocator
+++++++++++++++++++++++++++++++++++
in the low level, the physical allocator can allocate pages frames from the physical memory. it is intended to give a backend storage to the virtaul region allocator
the virtual region allocator allocates region from the kernel heap witch starts just after the 4096-aligned end of the kernel image+objects allocated at boot time. the VRegion allocator can allocates only a multiples of VPAGE (witch are in my kernel equals to PAGE = 4096bytes). this allocator uses a VRegion object to represent a region in the heap. there are tow lists of region : the free list and the used list, the free list is kept sorted by address order to facilitate free regions merging.
There is another object: SelfBuffer a generic object that take a buffer (array of bytes), a size 's' and then can allocate objects of size 's' from that buffer. the new operator is overloaded to create the SelfBuffer object at the start of the buffer and then creating a linked list of free object in the remainig space.
To bootstarp this allocator, i map the first page of the heap, create an empty SelfBuffer on that page to hold VRegion, then i allocate tow VRegion objects from that buffer, the first represent the page itself, the second the remaining free heap space. the VRegion allocator takes care to create a new buffer each time there is less than 2 free objects in total in the all existing SelfBuffer's (because creating a new SelfBuffer need a new VRegion object t be allocated).
The Slab allocator is implemented on the top of the VRegion allocator and uses also SelfBuffer to represent the slabs.
thus, when i need to allocate small objects i use the salb allocator. when i need to allocate page_aligned large objects i use directly the VRegion allocator.
I hope this would give you some ideas
Salam