Liblor / advanced_operating_systems_2020

Advanced Operating System Course at ETHZ
MIT License
19 stars 3 forks source link

make malloc/free work correctly with threads #132

Open abertschi opened 4 years ago

abertschi commented 4 years ago

As of handin of milestone 6 we do not free memory. free rather returns immediately. There seems to be a bug in morecore which is triggered if multiple threads are involved.

Liblor commented 4 years ago

I did some experimenting on the branch locking-experiments-loris.

My current suspicion is that the static refill function is the issue. When I put the static heap size to 4000*BASE_PAGE_SIZE, the test seems to work.

I don't think it is clear what happens in the following control flow:

page fault -> malloc (static) in paging code [depth 0] -> morecore (static) -> morecore_alloc_static -> ensure_static_threshold -> initlalize_static_zone -> paging_alloc -> calloc -> malloc (static) [depth 1] -> ...

The question is still, why the problem only arises with several threads though, but (given that in my branch I used nonreantrant locks, the second malloc should not be entered, i.e. we would be stuck) it can happen that in the meantime the morecore state gets set to dynamic, which can cause trouble. No, other thread should be able to change the status of heap_static if another is in malloc...

abertschi commented 4 years ago

Resolved by dropping thread support, reactivating free and using event driven approach with waitsets throughout code base. Thread support still broken