lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT


From: address@hidden
Subject: Re: [lwip-users] LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
Date: Wed, 12 Oct 2022 21:11:28 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

Am 11.10.2022 um 17:11 schrieb Giuseppe Modugno:
Another thing I can't understand is why the code around
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is needed if:

  * NO_SYS=1
  * MEM_USE_POOLS=0
  * MEM_LIBC_MALLOC=0
  * SYS_LIGHTWEIGHT_PROT=1
  * sys_arch_protect() simply disables interrupts

In mem_malloc there's a point where LWIP_MEM_ALLOC_PROTECT is called,
before the "scan through the heap searching for a free block". Why
during the scan, for each loop, UNPROTECT/PROTECT are called? The
comment says /* allow mem_free or mem_trim to run */.

Maybe this is done because the scan could take a long time to finish
(for big and fragmented heap) and having interrupts disabled for so long
time is not good? So the interrupts are enabled and disabled for each
loop to give them opportunity to run?

Exactly:
- Heap allocation takes a mutex as it should not block interrupts while
scanning for memory (takes too long).
- Heap free is fast as it does not need to scan.

Therefore, heap allocation uses double protection: mutex to block
against other allocations, PROTECT/UNPROTECT to protect against
concurrent free.

Regards,
Simon



reply via email to

[Prev in Thread] Current Thread [Next in Thread]