SNU-ARC / 2024_spring_sysprog_Lab3

8 stars 0 forks source link

Question regarding sbrk #14

Open k296070 opened 2 months ago

k296070 commented 2 months ago

Hello, I have a question regarding ds_sbrk. Q1.When I use ds_sbrk to shrink heap size, Is the amount the same as CHUNKSIZE? It doesn't seem to be shrinking in CHUNKSIZE as expected.

Q2. If I am using SHRINKTHLD, does it mean that shrink activates if the free block (that contains heap_end) size is above SHRINKTHLD? It seems that the reference code isn't working like that. I made 40896 Bytes of free block which is bigger than "1<<14"Bytes, but ds_heap_brk does not shrink.

Q3. Could I only consider the double-free error?(mm_free) Specifically, What about conditions that ds_heap_brk becomes greater than ds_heap_end? Should I halt the program? I saw that errno is being set. (mm_malloc)

Q4. In mm_realloc, is the concept "successor" including previous blocks too?

Have a nice weekend. Thank you!

kwonsw055 commented 2 months ago

A1. The shrinking size is the same as the argument you pass in ds_sbrk. For example, calling ds_sbrk(-32) will shrink the heap size by 32.

A2. The reference code tries to maintain a certain size of free block at the end of the heap after shrinking. So, it might not shrink the heap even if SHRINKTHLD is exceeded. Your implementation may differ.

A3. Ifds_sbrk failed, the mm_malloc call should return NULL with the program still running.

A4. "Successor" only accounts for the block after the footer. Blocks before the header should not be considered.

k296070 commented 2 months ago

Thank you for answering. For Q1, I meant If I should use CHUNKSIZE for ds_sbrk when shrinking heapsize. Regarding A1,A2 I wonder If I could decide the amount and when to shrink.

Thank you!

kwonsw055 commented 2 months ago

You don't need to use CHUNKSIZE. Feel free to use your own scheme/threshold/size for shrinking the heap.

k296070 commented 2 months ago

Thank you!