Hi
I have spend a day writing a physical memory manager for my kernel using a bitmap to keep track of allocations.
To further tweak what i wrote, i wanted to get some comments from you guru's
The implementation does (seems to) work, but i'm unsure if i haven't left some concrete blocks in it slowing me down And i'm not sure if all my calculations for addresses/offsets/etc. are correct, so that i may miss some areas of memory while searching for free pages, etc.
i attached both the header and c file, maybe somebody has some time to look at it. if not, maybe the code is good enough, to help others out writing their own physical memory manager....
how i use it:
i call SxPhysMemInit(), then i call SxPhysMemAddRegion for each of the mmap entries with type 1 reported by GRUB.
i maybe have to also mention that i use Microsofts Visual C++ to compile this so maybe gcc will not work out of the box...
Physical Memory Management
Physical Memory Management
- Attachments
-
- physmem.tar.gz
- memory manager sources (c/h)
- (2.23 KiB) Downloaded 116 times
Re: Physical Memory Management
Hi,
I took a quick look at your code, and i have some comments.
In my design i have a allocpage() and freepage() wich just returns / frees 1 physical page at the time. These functions are in my code 1 line statements. Very easy code. Then i have a vmalloc & vfree on top of that.
My vmalloc and vfree contains a self maintainable linked list of areas in vmem that are allocated, and the routines update the asking process pdir and ptab with the info. All pages are set to non-present so that i dont do a allocpage() befor i get a PF for a request to one of the addresses in the allocated vm region.
I have also a Flag attribute to my malloc to force it to do allocpage() on vmalloc. I have also a few flags for having malloc() do zerofill.
Just want to comment on your use of Vc++ for doing stuff like this. I do the same. For code with liked lists, bit-fippling etc its very good to debug code in Vc++ i use it alot.
Good luck with your coding!
-
Thomas
I took a quick look at your code, and i have some comments.
In my design i have a allocpage() and freepage() wich just returns / frees 1 physical page at the time. These functions are in my code 1 line statements. Very easy code. Then i have a vmalloc & vfree on top of that.
My vmalloc and vfree contains a self maintainable linked list of areas in vmem that are allocated, and the routines update the asking process pdir and ptab with the info. All pages are set to non-present so that i dont do a allocpage() befor i get a PF for a request to one of the addresses in the allocated vm region.
I have also a Flag attribute to my malloc to force it to do allocpage() on vmalloc. I have also a few flags for having malloc() do zerofill.
Just want to comment on your use of Vc++ for doing stuff like this. I do the same. For code with liked lists, bit-fippling etc its very good to debug code in Vc++ i use it alot.
Good luck with your coding!
-
Thomas