History log of /haiku/src/system/kernel/slab/MemoryManager.h
Revision Date Author Comments
# 30c9d3c0 01-Dec-2017 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Correct class/struct mixups.

Almost certainly harmless. Spotted by Clang.


# 1bd07482 11-Sep-2012 Ingo Weinhold <ingo_weinhold@gmx.de>

Fix crash in MemoryManager::PerformMaintenance()

sFreeAreaCount wasn't decremented after removing an area from
sFreeAreas, thus causing the loop to continue until enountering and
crashing on a NULL pointer after removing the last area. Introduce
helper methods _PushFreeArea() and _PopFreeArea() to ensure this cannot
easily happen again.

Fixes ticket #8972.


# 81fea743 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
Add MemoryManager::DebugObjectCacheForAddress() to retrieve the ObjectCache for
a certain address from KDL.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43117 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a5e2a430 01-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Fix the build with memory manager tracing disabled. The guard was missing
in the header.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43084 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 50175c99 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
Refactor the "allocations_per_caller" KDL command related functions.
They expect an instance of a class implementing the new
AllocationTrackingCallback interface, now. The only implementation ATM
is AllocationCollectorCallback, which does the work the now removed
slab_debug_add_allocation_for_caller() did before.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43082 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f908ff9b 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* Fix build broken in r43078. The slab_debug_add_allocation_for_caller()
wasn't guarded correctly.
* slab_debug_add_allocation_for_caller(): Add bool resetAllocationInfos
parameter, which makes the function clear the allocation tracking
infos after processing the data.
* "allocations_per_caller" KDL command: Add option "-r" to reset the
allocation tracking infos. The next invocation of the command will
only show the allocations made after the reset.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43079 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0422a0f3 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* dump_allocations_per_caller(): Compute the total allocation count and
size from the caller infos instead of using return arguments in the
helper functions called.
* Move caller info update code from analyze_allocation_callers() to new
function slab_debug_add_allocation_for_caller(), so it can be reused.
* Add MemoryManager::AnalyzeAllocationCallers() to collect the
allocation information for the memory manager.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43078 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e1c6140e 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* Add optional stack trace capturing for slab memory manager tracing.
* Add allocation tracking for the slab allocator (enabled via
SLAB_ALLOCATION_TRACKING). The allocation tracking requires tracing
with stack traces to be enabled for object caches and/or the memory
manager.
- Add class AllocationTrackingInfo that associates an allocation with
its respective tracing entry. The structure is added to the end of
an allocation done by the memory manager. For the object caches
there's a separate array for each slab.
- Add code range markers to the slab code, so that the first caller
into the slab code can be retrieved from the stack traces.
- Add KDL command "allocations_per_caller" that lists all allocations
summarized by caller.
* Move debug definitions from slab_private.h to slab_debug.h.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43072 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3c0b4af4 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Remove unused macro.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37704 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 93a56baf 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the Area structure from the beginning of area to one page inside the
area. The first page is not mapped, so someone writing over the bounds of the
previous area will be axed immediately.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37701 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 05951b9b 02-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added optional paranoid checking of the slab memory manager meta chunks
after each chunk allocation/deallocation.
* The commands that dump chunks also verify, whether chunks that look free
are in the free list.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37360 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b4e5e498 25-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

MemoryManager:
* Added support to do larger raw allocations (up to one large chunk (128 pages))
in the slab areas. For an even larger allocation an area is created (haven't
seen that happen yet, though).
* Added kernel tracing (SLAB_MEMORY_MANAGER_TRACING).
* _FreeArea(): Copy and paste bug: The meta chunks of the to be freed area
would be added to the free lists instead of being removed from them. This
would corrupt the lists and also lead to all kinds of misuse of meta chunks.

object caches:
* Implemented CACHE_ALIGN_ON_SIZE. It is no longer set for all small object
caches, but the block allocator sets it on all power of two size caches.
* object_cache_reserve_internal(): Detect recursion and don't wait in such a
case. The function could deadlock itself, since
HashedObjectCache::CreateSlab() does allocate memory, thus potentially
reentering.
* object_cache_low_memory():
- I missed some returns when reworking that one in r35254, so the function
might stop early and also leave the cache in maintenance mode, which would
cause it to be ignored by object cache resizer and low memory handler from
that point on.
- Since ReturnSlab() potentially unlocks, the conditions weren't quite correct
and too many slabs could be freed.
- Simplified things a bit.
* object_cache_alloc(): Since object_cache_reserve_internal() does potentially
unlock the cache, the situation might have changed and their might not be an
empty slab available, but a partial one. The function would crash.
* Renamed the object cache tracing variable to SLAB_OBJECT_CACHE_TRACING.
* Renamed debugger command "cache_info" to "slab_cache" to avoid confusion with
the VMCache commands.
* ObjectCache::usage was not maintained anymore since I introduced the
MemoryManager. object_cache_get_usage() would thus always return 0 and the
block cache would not be considered cached memory. This was only of
informational relevance, though.

slab allocator misc.:
* Disable the object depots of block allocator caches for object sizes > 2 KB.
Allocations of those sizes aren't so common that the object depots yield any
benefit.
* The slab allocator is now fully self-sufficient. It allocates its bootstrap
memory from the MemoryManager, and the hash tables for HashedObjectCaches use
the block allocator instead of the heap, now.
* Added option to use the slab allocator for malloc() and friends
(USE_SLAB_ALLOCATOR_FOR_MALLOC). Currently disabled. Works in principle and
has virtually no lock contention. Handling for low memory situations is yet
missing, though.
* Improved the output of some debugger commands.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5726fbda 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

MemoryManager:
* Does now keep one or two empty areas around, so that even in case of
CACHE_DONT_LOCK_KERNEL_SPACE memory can be provided as long as pages are
available. The object cache maintainer thread is used to asynchronously
allocate/delete the free areas.
* Added new debugger commands "slab_meta_chunk[s]" and improved the existing
ones.
* Moved Area::chunks to MetaChunk.
* Removed unused _AllocationArea() "chunkSize" parameter.
* Fixed serious bug in _FreeChunk(): Empty meta chunks were not removed from
the partial chunk lists and could thus be used twice.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35264 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 10189b50 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed the memory management algorithm: Instead of designating the area for
a certain chunk size, the areas are split into meta chunks (which are as
large as a large chunk) each of which can be a used independently for chunks
of a certain size. This reduces the vulnerablity to fragmentation, so that we
need fewer areas overall.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35250 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 86c794e5 21-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

slab allocator:
* Implemented a more elaborated raw memory allocation backend (MemoryManager).
We allocate 8 MB areas whose pages we allocate and map when needed. An area is
divided into equally-sized chunks which form the basic units of allocation. We
have areas with three possible chunk sizes (small, medium, large), which is
basically what the ObjectCache implementations were using anyway.
* Added "uint32 flags" parameter to several of the slab allocator's object
cache and object depot functions. E.g. object_depot_store() potentially wants
to allocate memory for a magazine. But also in pure freeing functions it
might eventually become useful to have those flags, since they could end up
deleting an area, which might not be allowable in all situations. We should
introduce specific flags to indicate that.
* Reworked the block allocator. Since the MemoryManager allocates block-aligned
areas, maintains a hash table for lookup, and maps chunks to object caches,
we can quickly find out which object cache a to be freed allocation belongs
to and thus don't need the boundary tags anymore.
* Reworked the slab boot strap process. We allocate from the initial area only
when really necessary, i.e. when the object cache for the respective
allocation size has not been created yet. A single page is thus sufficient.

other:
* vm_allocate_early(): Added boolean "blockAlign" parameter. If true, the
semantics is the same as for B_ANY_KERNEL_BLOCK_ADDRESS.
* Use an object cache for page mappings. This significantly reduces the
contention on the heap bin locks.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35232 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1bd07482531e9fae514212e729ce94eb7b534f42 11-Sep-2012 Ingo Weinhold <ingo_weinhold@gmx.de>

Fix crash in MemoryManager::PerformMaintenance()

sFreeAreaCount wasn't decremented after removing an area from
sFreeAreas, thus causing the loop to continue until enountering and
crashing on a NULL pointer after removing the last area. Introduce
helper methods _PushFreeArea() and _PopFreeArea() to ensure this cannot
easily happen again.

Fixes ticket #8972.


# 81fea743949e8fcd9f7738204f5853b2cd15c868 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
Add MemoryManager::DebugObjectCacheForAddress() to retrieve the ObjectCache for
a certain address from KDL.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43117 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a5e2a43050d65404153e20c01681d3463948610b 01-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Fix the build with memory manager tracing disabled. The guard was missing
in the header.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43084 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 50175c99c4747dcc83dcdeff24c259500cbf7478 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
Refactor the "allocations_per_caller" KDL command related functions.
They expect an instance of a class implementing the new
AllocationTrackingCallback interface, now. The only implementation ATM
is AllocationCollectorCallback, which does the work the now removed
slab_debug_add_allocation_for_caller() did before.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43082 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f908ff9bb658aa86aa53760c51070415e69f951d 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* Fix build broken in r43078. The slab_debug_add_allocation_for_caller()
wasn't guarded correctly.
* slab_debug_add_allocation_for_caller(): Add bool resetAllocationInfos
parameter, which makes the function clear the allocation tracking
infos after processing the data.
* "allocations_per_caller" KDL command: Add option "-r" to reset the
allocation tracking infos. The next invocation of the command will
only show the allocations made after the reset.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43079 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0422a0f3ae8f12f32bd27868a7e742293786f0a0 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* dump_allocations_per_caller(): Compute the total allocation count and
size from the caller infos instead of using return arguments in the
helper functions called.
* Move caller info update code from analyze_allocation_callers() to new
function slab_debug_add_allocation_for_caller(), so it can be reused.
* Add MemoryManager::AnalyzeAllocationCallers() to collect the
allocation information for the memory manager.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43078 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e1c6140eaa641aa95fc6d82f0d5c53cf4fe41a16 01-Nov-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

mmlr + bonefish:
* Add optional stack trace capturing for slab memory manager tracing.
* Add allocation tracking for the slab allocator (enabled via
SLAB_ALLOCATION_TRACKING). The allocation tracking requires tracing
with stack traces to be enabled for object caches and/or the memory
manager.
- Add class AllocationTrackingInfo that associates an allocation with
its respective tracing entry. The structure is added to the end of
an allocation done by the memory manager. For the object caches
there's a separate array for each slab.
- Add code range markers to the slab code, so that the first caller
into the slab code can be retrieved from the stack traces.
- Add KDL command "allocations_per_caller" that lists all allocations
summarized by caller.
* Move debug definitions from slab_private.h to slab_debug.h.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43072 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3c0b4af4b46e5836e0f371709c014ff4a24517c0 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Remove unused macro.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37704 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 93a56baf09e19689d669f7f24f8cf74b23c7b4b3 22-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the Area structure from the beginning of area to one page inside the
area. The first page is not mapped, so someone writing over the bounds of the
previous area will be axed immediately.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37701 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 05951b9b6a3bbf94106b2167283166aae78af820 02-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added optional paranoid checking of the slab memory manager meta chunks
after each chunk allocation/deallocation.
* The commands that dump chunks also verify, whether chunks that look free
are in the free list.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37360 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b4e5e4982360e684c5a13d227b9a958dbe725554 25-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

MemoryManager:
* Added support to do larger raw allocations (up to one large chunk (128 pages))
in the slab areas. For an even larger allocation an area is created (haven't
seen that happen yet, though).
* Added kernel tracing (SLAB_MEMORY_MANAGER_TRACING).
* _FreeArea(): Copy and paste bug: The meta chunks of the to be freed area
would be added to the free lists instead of being removed from them. This
would corrupt the lists and also lead to all kinds of misuse of meta chunks.

object caches:
* Implemented CACHE_ALIGN_ON_SIZE. It is no longer set for all small object
caches, but the block allocator sets it on all power of two size caches.
* object_cache_reserve_internal(): Detect recursion and don't wait in such a
case. The function could deadlock itself, since
HashedObjectCache::CreateSlab() does allocate memory, thus potentially
reentering.
* object_cache_low_memory():
- I missed some returns when reworking that one in r35254, so the function
might stop early and also leave the cache in maintenance mode, which would
cause it to be ignored by object cache resizer and low memory handler from
that point on.
- Since ReturnSlab() potentially unlocks, the conditions weren't quite correct
and too many slabs could be freed.
- Simplified things a bit.
* object_cache_alloc(): Since object_cache_reserve_internal() does potentially
unlock the cache, the situation might have changed and their might not be an
empty slab available, but a partial one. The function would crash.
* Renamed the object cache tracing variable to SLAB_OBJECT_CACHE_TRACING.
* Renamed debugger command "cache_info" to "slab_cache" to avoid confusion with
the VMCache commands.
* ObjectCache::usage was not maintained anymore since I introduced the
MemoryManager. object_cache_get_usage() would thus always return 0 and the
block cache would not be considered cached memory. This was only of
informational relevance, though.

slab allocator misc.:
* Disable the object depots of block allocator caches for object sizes > 2 KB.
Allocations of those sizes aren't so common that the object depots yield any
benefit.
* The slab allocator is now fully self-sufficient. It allocates its bootstrap
memory from the MemoryManager, and the hash tables for HashedObjectCaches use
the block allocator instead of the heap, now.
* Added option to use the slab allocator for malloc() and friends
(USE_SLAB_ALLOCATOR_FOR_MALLOC). Currently disabled. Works in principle and
has virtually no lock contention. Handling for low memory situations is yet
missing, though.
* Improved the output of some debugger commands.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35283 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5726fbda3ccb0b57c3504053a67110dd0d3922bd 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

MemoryManager:
* Does now keep one or two empty areas around, so that even in case of
CACHE_DONT_LOCK_KERNEL_SPACE memory can be provided as long as pages are
available. The object cache maintainer thread is used to asynchronously
allocate/delete the free areas.
* Added new debugger commands "slab_meta_chunk[s]" and improved the existing
ones.
* Moved Area::chunks to MetaChunk.
* Removed unused _AllocationArea() "chunkSize" parameter.
* Fixed serious bug in _FreeChunk(): Empty meta chunks were not removed from
the partial chunk lists and could thus be used twice.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35264 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 10189b502d840f2adc5e8d98fdc4fc4d54eb15ca 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed the memory management algorithm: Instead of designating the area for
a certain chunk size, the areas are split into meta chunks (which are as
large as a large chunk) each of which can be a used independently for chunks
of a certain size. This reduces the vulnerablity to fragmentation, so that we
need fewer areas overall.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35250 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 86c794e5c10f1b2d99d672d424a8637639c703dd 21-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

slab allocator:
* Implemented a more elaborated raw memory allocation backend (MemoryManager).
We allocate 8 MB areas whose pages we allocate and map when needed. An area is
divided into equally-sized chunks which form the basic units of allocation. We
have areas with three possible chunk sizes (small, medium, large), which is
basically what the ObjectCache implementations were using anyway.
* Added "uint32 flags" parameter to several of the slab allocator's object
cache and object depot functions. E.g. object_depot_store() potentially wants
to allocate memory for a magazine. But also in pure freeing functions it
might eventually become useful to have those flags, since they could end up
deleting an area, which might not be allowable in all situations. We should
introduce specific flags to indicate that.
* Reworked the block allocator. Since the MemoryManager allocates block-aligned
areas, maintains a hash table for lookup, and maps chunks to object caches,
we can quickly find out which object cache a to be freed allocation belongs
to and thus don't need the boundary tags anymore.
* Reworked the slab boot strap process. We allocate from the initial area only
when really necessary, i.e. when the object cache for the respective
allocation size has not been created yet. A single page is thus sufficient.

other:
* vm_allocate_early(): Added boolean "blockAlign" parameter. If true, the
semantics is the same as for B_ANY_KERNEL_BLOCK_ADDRESS.
* Use an object cache for page mappings. This significantly reduces the
contention on the heap bin locks.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35232 a95241bf-73f2-0310-859d-f6bbb57e9c96