Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap memory manager #8

Closed
SamTebbs33 opened this issue Apr 18, 2019 · 9 comments · Fixed by #133
Closed

Heap memory manager #8

SamTebbs33 opened this issue Apr 18, 2019 · 9 comments · Fixed by #133
Labels
arch: none Affects common code across architectures enhancement New feature or request
Projects
Milestone

Comments

@SamTebbs33
Copy link
Collaborator

A heap memory manager will need to be implemented so that dynamic sizes of memory can be allocated and freed. One that I have implemented before uses a list of 'holes', each one having a header stating if it is occupied and what its size is. The allocator then goes through this list of holes and finds one with a size closest to the desired size. If it's too big then it splits the surplus off into a separate hole.

Of course there are many ways this can be done.

@SamTebbs33 SamTebbs33 added enhancement New feature or request arch: none Affects common code across architectures labels Apr 18, 2019
@SamTebbs33 SamTebbs33 added this to To do in General via automation Apr 18, 2019
@SamTebbs33
Copy link
Collaborator Author

The memory manager should be an allocator so that it can be used with the Zig standard library.

@SamTebbs33 SamTebbs33 added this to the v0.1 milestone May 30, 2019
@SamTebbs33
Copy link
Collaborator Author

Instead of writing a new allocator, it would be worth using an existing allocator if a suitable one exists in the std lib.

@SamTebbs33
Copy link
Collaborator Author

SamTebbs33 commented Sep 2, 2019

I've looked through the std lib's allocators and none are suitable so I will write our own. I'll base it on my implementation at https://github.com/SamTebbs33/jaq/blob/dev/src/kernel/mem/heap.c

@SamTebbs33 SamTebbs33 moved this from To do to In progress in General Sep 2, 2019
@DrDeano
Copy link
Member

DrDeano commented Sep 3, 2019

I was thinking should we break this up into a physical and virtual memory manager and then create a Allocator on top of the virtual memory manager to handle more fine grain allocations. I'm not sure if grub supplies the total memory install in the system, (I know my bootloader does ;) ) So could "interface" the heap so can take any source of memory so the heap doesn't have to worry about the real memory, will just ask for more.

https://github.com/DrDeano/DeanOS/blob/master/src/kernel/kernel/paging.c (Near the bottom, functions prefix vmm_)
https://github.com/DrDeano/DeanOS/blob/master/src/kernel/kernel/pmm.c

@SamTebbs33
Copy link
Collaborator Author

Ah so the physical one will track physical page usage, the virtual one would map those pages to virtual addresses and the heap just allocate smaller blocks within that virtual space? I can see the virtual layer being useful if some areas of memory are taken for DMA and the like.

@DrDeano
Copy link
Member

DrDeano commented Sep 3, 2019

Yes, you nailed it :) So can have the heap manage a page of memory. So with the physical layer, it will hide all the I/O mapped regions, and virtual will look continuous.
So for now I guess if we want a heap now, can just use your idea from your OS but have heap layer abstracted so later swap out for the physical/virtual layering.

@SamTebbs33
Copy link
Collaborator Author

Sounds good, if we keep this ticket for the heap layer, could you make issues for the other two parts (we may not need one for each, up to you :) )?

@SamTebbs33
Copy link
Collaborator Author

SamTebbs33 commented Sep 3, 2019

So for now I guess if we want a heap now, can just use your idea from your OS but have heap layer abstracted so later swap out for the physical/virtual layering.

Agreed. The current extremely minimal and unfinished heap just takes a start and end address and allocates within that, so it should still work above the virtual layer without any modifications.

@DrDeano
Copy link
Member

DrDeano commented Sep 3, 2019

Could have one ticket, and have sub tickets for physical and virtual memory, else multiple tickets

@DrDeano DrDeano mentioned this issue Sep 5, 2019
2 tasks
@SamTebbs33 SamTebbs33 modified the milestones: v0.1, v0.2 Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch: none Affects common code across architectures enhancement New feature or request
Projects
No open projects
General
  
In progress
Development

Successfully merging a pull request may close this issue.

2 participants