rust-osdev/linked-list-allocator

Merge padding inside global allocate_first_fit

Closed this issue · 1 comments

I found that in function HoleList::allocate_first_fit, it will call the global allocate_first_fit.
The global allocate_first_fit will search and call split_hole to get the allocated memory, also generating front_padding and back_padding to cope with align problem.
However the two padding are merged by deallocate in HoleList::allocate_first_fit which seems less efficient. Since deallocate need to search for the previous holes of two padding, which means it has to go through the linked-list again all over.
In global allocate_first_fit after it call split_hole, it already get the previous hole that can merge the front padding and back padding. I think it will be more efficient to merge padding in global allocate_first_fit.

Please correct me if there are anything wrong.

Yeah, I think you're correct that this approach would be more efficient (and still correct). It's been some time since I wrote that code though, so I'm not 100% sure about this. Feel free to try to improve this and create a PR if you like, I'm happy to take a closer look then. (I'm a bit short on time right now, so I probably won't have time to do it myself anytime soon.)