What is the meaning of the term arena in relation to memory?

前端 未结 4 1303
感情败类
感情败类 2021-01-29 19:02

I\'m reading a book on memory as a programming concept. In one of the later chapters, the author makes heavy use of the word arena, but never defines it. I\'ve

4条回答
  •  离开以前
    2021-01-29 19:49

    From http://www.bozemanpass.com/info/linux/malloc/Linux_Heap_Contention.html:

    The libc.so.x shared library contains the glibc component and the heap code resides inside it. The current implementation of the heap uses multiple independent sub-heaps called arenas. Each arena has its own mutex for concurrency protection. Thus if there are sufficient arenas within a process' heap, and a mechanism to distribute the threads' heap accesses evenly between them, then the potential for contention for the mutexes should be minimal. It turns out that this works well for allocations. In malloc(), a test is made to see if the mutex for current target arena for the current thread is free (trylock). If so then the arena is now locked and the allocation proceeds. If the mutex is busy then each remaining arena is tried in turn and used if the mutex is not busy. In the event that no arena can be locked without blocking, a fresh new arena is created. This arena by definition is not already locked, so the allocation can now proceed without blocking. Lastly, the ID of the arena last used by a thread is retained in thread local storage, and subsequently used as the first arena to try when malloc() is next called by that thread. Therefore all calls to malloc() will proceed without blocking.

    You can also refer to this link:

    http://www.codeproject.com/Articles/44850/Arena-Allocator-DTOR-and-Embedded-Preallocated-Buf

提交回复
热议问题