History log of /haiku/src/system/kernel/slab/Slab.cpp
Revision Date Author Comments
# 8f68daed 25-Apr-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Make use of the new ConditionVariable lock-switching APIs in a few places.


# 6c0b4106 30-Aug-2021 Augustin Cavalier <waddlesplash@gmail.com>

kernel/slab: Fix build with SLAB_ALLOCATION_TRACING enabled.

Unfortunately it does not work, I get this when invoking
allocations_per_caller at the kdebug prompt:

92513 9162096 0x0000000000000000 <NULL> + 0x0 (commpage) (nearest)
12602 2108408 0xffffffff80132a50 _Z23add_alloc_tracing_entryP11ObjectCachejPv + 0x70 (kernel_x86_64)

The stack tracing system must be broken, or maybe it has never been
properly adjusted for x86_64.


# 718d7149 10-Feb-2018 Jérôme Duval <jerome.duval@gmail.com>

white space cleanup


# 271ac910 09-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Remove useless includes of khash.h

* These files were already converted to BOpenHashTable.
* For #9552.


# c3f0fd28 12-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed formatting of output in some debugger commands.

Currently all debugger commands assume 32-bit pointers when formatting their
output. This means that on x86_64 the output is incorrectly formatted. Fixed
this by adding a B_PRINTF_POINTER_WIDTH definition (16 on 64-bit, 8 on
32-bit), and using this to correctly format the output. Not all commands have
been fixed yet, but all VM, slab, VFS, team, thread and image commands should
be correct.


# 4be4fc6b 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 5cbe06f4 04-Dec-2011 Michael Lotz <mmlr@mlotz.ch>

Allow replacing the object cache with the guarded heap.

This allows to use the debug features of the guarded heap also on
allocations made through the object cache API. This is obivously
horrible for performance and uses up huge amounts of memory, so the
initial and grow sizes are adjusted accordingly.

Note that this is a rather simple hack, using the object_cache pointer
to transport the allocation size. The alignment is neglected completely.


# a1396579 28-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Tracking info wasn't always retrieved with the cache locked.

Getting the object slab does a hash lookup which needs to be protected
by the cache lock. Otherwise the hash table may be resized or otherwise
modified while we do the lookup, leading to errors.


# 905c75a5 04-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Tiny pointer style cleanup.


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


# 3d1f420b 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
* Add "allocation_infos" KDL command. Can be used to print the allocation info,
including the stack trace, given an object cache, slab, allocation within a
slab or allocation address. It can also optionally be filtered by team/thread.
* Fix the AllocationDetailPrinterCallback to not access a possibly invalid
trace entry for printing a stack trace.


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


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

mmlr + bonefish:
* AllocationTrackingCallback::ProcessTrackingInfo(): Also pass the
allocation pointer.
* "allocations_per_caller" KDL command: Add option "-d". When given,
each allocation for the specified caller is printed, including the
respective stack trace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43087 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


# 72156a40 31-Oct-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
* Introduce "paranoid" malloc/free into the slab allocator (initializing
allocated memory to 0xcc and setting freed memory to 0xdeadbeef).
* Allow for optional stack traces for slab object cache tracing.


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


# 4b2adaae 14-Jun-2011 Stefano Ceccherini <stefano.ceccherini@gmail.com>

Changed wrong help text


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


# 3aea1d4f 15-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added ObjectCache::alignment, the object alignment and used the alignment for
incrementing the cache color cycle. Using the fixed value (8) would
potentially misalign the object again.
* Don't use CACHE_ALIGN_ON_SIZE for object caches any longer -- we have the
alignment parameter anyway (the flag is still used for the MemoryManager,
though).
* ObjectCache::InitSlab(): Slab coloring *was* done when CACHE_ALIGN_ON_SIZE
was given, i.e. exactly the wrong way around. Also the cache_color_cycle
computation was weird -- color 0 was used twice in a row.
* The "slabs" and "slab_cache" KDL commands also print the alignment, now.



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


# fa04c15c 18-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

object_cache_low_memory(): Reduce the cache pressure indicator even for the
"note" low resource state. Not doing so could result in a very high limit for
the number of empty slabs, which wouldn't change until reaching the "warning"
state.
Fixes #5816.


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


# d3166e46 29-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced no longer necessary send_signal_etc() work-arounds for
resume_thread().


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


# 88f12638 03-Mar-2010 Axel Dörfler <axeld@pinc-software.de>

* The slab_cache command now also dumps the actual slab lists.


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


# 1c164de7 01-Mar-2010 Axel Dörfler <axeld@pinc-software.de>

* Quick&dirty fix of a race condition that caused an endless loop in
object_cache_alloc(): the ObjectCache::total_objects count was increased in
ObjectCache::InitSlab(), but the slab was really only added at a later point
between the cache could be unlocked.
* If a second object_cache_reserve_internal() managed to be called while the
lock was unlocked, it would see that there has to be space available, and
will then return -- however, since the other thread could not yet place the
slab into the cache, object_cache_alloc() cannot find it.


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


# 464d9f12 24-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed object_depot_store() return value to void. It is now always takes
over ownership of the object. Fixes double free introduced in r35605.


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


# bc208a85 24-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed TODO that isn't one.


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


# ff59ce68 24-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* The low resource handler now empties the cache depot's magazines; before,
they were never freed unless the cache was destroyed (I just wondered why
my system would bury >1G in the magazines).
* Made the magazine capacity variable per cache, ie. for larger objects, it's
not a good idea to have 64*CPU buffers lying around in the worst case.
* Furthermore, the create_object_cache_etc()/object_depot_init() now have
arguments for the magazine capacity as well as the maximum number of full
unused magazines.
* By default, you might want to initialize both to zero, as then some hopefully
usable defaults are computed. Otherwise (the only current example is the
vm_page_mapping cache) you can just put in the values you'd want there.
The page mapping cache uses larger values, as its objects are usually
allocated and deleted in larger chunks.
* Beware, though, I couldn't test these changes yet as Qemu didn't like to run
today. I'll test these changes on another machine now.


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


# 54f3267e 15-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* Fixed maintaining the object depot's free magazine count (it's not really used
though).
* Added/improved some KDL commands to make the slab easier to work with from
KDL.


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


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

Moved added the debugger commands from slab_init() to slab_init_post_area().
Those use malloc(), which obviously doesn't work before the heap is
initialized.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35288 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


# 34bfbec2 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

low resource handler: Clear the maintenance_in_progress flag also when
adding the cache to the maintenance queue. Not so important but more correct.


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


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

Reworked the object cache resizer (renamed to object cache maintainer) and
low resource handler functions. Particularly fixed the race conditions
between those and delete_object_cache().


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


# 8d1316fd 22-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced CACHE_DONT_SLEEP by two new flags CACHE_DONT_WAIT_FOR_MEMORY and
CACHE_DONT_LOCK_KERNEL_SPACE. If the former is given, the slab memory manager
does not wait when reserving memory or pages. The latter prevents area
operations. The new flags add a bit of flexibility. E.g. when allocating page
mapping objects for userland areas CACHE_DONT_WAIT_FOR_MEMORY is sufficient,
i.e. the allocation will succeed as long as pages are available.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35246 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


# 08d66c12 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Always unlock the object cache while allocating memory. This is necessary for
the CACHE_DONT_SLEEP flag to work for real, since otherwise the thread could
block on the mutex held by a thread allocating memory. We use two condition
variables to prevent multiple threads from allocating slabs at the same time.


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


# 8766b8b4 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reverted r35203, i.e. ObjectCache::object_per_slab is gone again.
* Changed the semantics of object_cache_reserve_internal(). Now it makes sure
the given number of objects are free. As a side effect this also changes
the semantics of object_cache_reserve() similarly, though I have trouble
seeing the purpose of the function in the first place.


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


# 4ebe37ab 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added ObjectCache::objects_per_slab, which allowed to squash the TODO in
object_cache_reserve_internal().


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


# bb439b87 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Consequently propagate the CACHE_DONT_SLEEP flag.
* block_alloc(): Create B_FULL_LOCK area.


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


# d66916e3 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Shuffled functions a bit, so that they are in a reasonable order.


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


# 53a87b03 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed debug left-over.


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


# 20ca0c5e 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* object_cache_return_object_wrapper(): Calling object_cache_free() is a bad
idea, since that would potentially add the object back to the object store
or lead to infinite recursion. When the object cache is destroyed it most
likely led to infinite loops, because the object would alternately be
removed from and added back to the object store.
* delete_object_cache(): Lock after destroying the object store, so we don't
deadlock.
* Use the object store on SMP machines. It seems to work, though I only
tested with the network stack and that seems to have problems of its own.


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


# 825566f8 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Split the slab allocator code into separate source files and C++-ified
things a bit.
* Some style cleanup.
* The object depot does now have a cookie that will be passed to the return
hook.
* Fixed object_cache_return_object_wrapper() using the new cookie.


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


# 0fc052b4 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the definition of the CACHE_ALIGN_ON_SIZE flag to the header and fixed
its value.


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


# a8806e5e 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed headers/private/kernel/slab/Depot.h to ObjectDepot.h.
* Moved the object depot code to its own source file.


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


# e50cf876 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


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


# 90d870c1 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved VMAddressSpace definition to vm_address_space.h.
* "Classified" VMAddressSpace, i.e. turned the vm_address_space_*() functions
into methods, made all attributes (but "areas") private, and added
accessors.
* Also turned the vm.cpp functions vm_area_lookup() and
remove_area_from_address_space() into VMAddressSpace methods. The rest of
the area management functionality will follow soon.


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


# 1db31d4d 27-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* The slab and the block cache now both also react on address space shortages.


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


# 68b6dce1 12-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

We already panic to indicate that something's wrong, no real need to crash
afterwards instead of returning gracefully.


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


# ea2abd11 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


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


# d3b44ccb 29-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added explicit physical address parameter to vm_create_anonymous_area() and
create_area_etc(). 0 for the default behavior.


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


# 5147963d 26-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

headers/private/kernel/util/OpenHashTable.h, Hugo's version, is a bit nicer than
Tracker's OpenHashTable.h which it should eventually replace. We've renamed the
class to BOpenHashTable and changed the interface slightly so that HashTableLink
became superfluous.
Adapted all the code that used it. Since the OpenHashTables no longer clash,
this should fix the GCC4 build.


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


# 591bc3f2 28-May-2009 Jérôme Duval <korli@users.berlios.de>

* various fixes identified by gcc4, provided by Joe Prostko


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


# c33667d4 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


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


# 7ce72b98 21-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Implement CACHE_DONT_SLEEP partially. At least for small object caches
without object depot it should be complete. For the other stuff
internal_alloc() would need to pass the flag on to block_alloc(), but
that isn't possible yet.
* Adjusted the low memory handler to respect the minimum object reserve
of the object caches.

The swap_test_heap test does seem to pass reliably with 128 MB RAM and
128 MB allocation, now. It's quite slow, though. Particularly while the
allocation is filled, the system is completely unusable.


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


# 1cda5944 20-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object_cache_set_minimum_reserve() which sets the minimal number
of free objects an object cache should try to have ready. If the number
of free objects drops below the threshold, a new urgent priority thread
is asked to asynchronously resize the object cache (pretty similar to
the heap grower thread). Such a mechanism is necessary for code paths
that are supposed to free pages, but may need memory themselves (like
the swap support).


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


# 5db87665 05-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object_cache_get_usage() function that returns the memory
allocated by an object cache.


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


# 5c99d639 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


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


# f5b3a6a7 05-Jun-2008 Michael Lotz <mmlr@mlotz.ch>

* Initialize all static mutexes in the kernel through a MUTEX_INITIALIZER()
and remove the then unneeded mutex_init() for them.
* Remove the workaround for allowing uninitialized mutexes on kernel startup.
As they are all initialized statically through the MUTEX_INITIALIZER() now
this is not needed anymore.
* An uninitialized mutex will now cause a panic when used to find possibly
remaining cases.
* Remove now unnecessary driver_settings_init_post_sem() function.

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


# b0f5179a 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed recursive_lock to use a mutex instead of a semaphore.
* Adjusted code using recursive locks respectively. The initialization
cannot fail anymore, and it is possible to use recursive locks in the
early boot process (even uninitialized, if in BSS), which simplifies
things a little.


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


# 96235343 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

Now uses mutexes instead of benaphores, that also simplified object
instantiation at early boot a bit.


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


# 97c0a2b3 27-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Paranoia checks were accidentally globally enabled by default. Object
* cache paranoia was always enabled.
* Changed from paranoia on/off to levels. Adjusted the macros to take a
level argument.


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


# 6bf15ffc 27-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed macros that enable tracing for individual components from
defined/undefined to numeric values (0 for undefined). This allows for
trace levels.
* Set SYSCALL_TRACING_IGNORE_KTRACE_OUTPUT default to 1, since this is
what one usually wants.


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


# 2be0b7cc 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added paranoia checks. They reveal that a net buffer data node is freed
twice when running the OpenSSH "forwarding" test, which corrupts the
slab's object list. It's not quite clear to me yet why that happens.


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


# 7526aa66 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed some leftover junk.


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


# 67411c9d 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object cache kernel tracing.


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


# 987de537 02-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Also replaced the cpu store's lock with a recursive lock in order
to fix bug #1731.
* However, it turns out that depot destruction obviously doesn't work
correctly, at least we keep partial or full slabs around when we're
using them (which causes the code to panic).
* Therefore, I've now disabled depots completely, until I find the time
to really work on that code.


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


# 45b17b80 01-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Temporarily switched to a recursive lock for the depot.
* While this is not a really good idea for a lock with supposedly little
contention, but it'll fix bug #1731. I haven't tested it yet, but will
do so in a minute :-)
* I will need to rework the slab anyway so that it's possible to use it
as a replacement for our heap, and then I'll switch back to a benaphore
again.


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


# 06958f90 17-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

We generally handle NULL pointers in free() and friends gracefully.


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


# c21af3b2 16-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Print the missing object.

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


# c6ee79ce 16-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* vm_create_anonymous_area() now accepts B_ANY_KERNEL_BLOCK_ADDRESS.
* As a temporary work-around for the current slab allocator's area usage,
I added the CACHE_LARGE_SLAB flag, which will force the allocator to
use larger areas.


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


# aad0d344 03-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

The slab areas shouldn't be user readable...


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


# 23128566 21-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

Slab.h no longer includes Depot.h.


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


# b062823d 29-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* register_low_memory_handler() was called too early by several kernel
components - now, we divide the initialization of that service into two parts
which allows this (before, most handlers were gone after boot).
* Added debugger command that dumps the low memory handlers.
* The slab allocator now registers its low memory handler with a higher
priority, so that it'll run before the potentially heavier ones.


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


# 5c4ed86b 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Moved some definitions from vm_types.h that functions in vm.h need as
arguments into vm.h.
* This should fix the broken build from earlier - thanks Stefano for the note!
* That also allowed to clean some other includes a bit.


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


# e6dc7903 26-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* vm.h no longer includes vm_types.h - only those that actually need access
to the private VM types are including vm_types.h now.
* Removed vm_page, vm_area, vm_cache, and vm_address_space typedefs; it's
cleaner this way, and the actual types are only used in C++ files now,
anyway.
* And that caused changes in many files...
* Made commpage.h self-containing.
* Minor cleanup.


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


# 84052230 31-Jul-2007 Axel Dörfler <axeld@pinc-software.de>

axeld+bonefish: Got rid of the ParentType in the HashTableDefinition; it doesn't really
belong there.


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


# 8cfe0be3 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

slab/cache: a couple more fixes.

- on CACHE_DURING_BOOT init benaphore count with 1.
- account for allocated space on early_allocate_pages.
- fixed slab position calculation in small slabs.
- we can now init all allocator sizes early rather than later.


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


# 698b6d71 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cache/slab: when CACHE_DURING_BOOT is specified, use vm_allocate_early to obtain pages for slabs, and create the associated areas on post bootup.


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


# 39af4459 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added object_cache_reserve to allow cache users to pre-allocate slabs.


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


# 11debaf6 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added CACHE_UNLOCKED_PAGES flag to allow caches' pages to be created with no locking instead of full locking.


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


# c49aa60a 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cache allocator: for allocations > 8k create areas, and delete them on free.


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


# 0be6e977 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

minimal cleanups


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


# 9a9cba59 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

don't need TRACE_SLAB by default now.


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


# 6bad4934 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

pushed the slab init a bit deeper. added a object cache based allocator, including a bootstrap mechanism to have it init during bootup.


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


# 6e31ae98 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some object cache / slab improvements.

- call the reclaimer callback when low on memory.
- use the depot when on multi-cpu setups (for scalability).
- fixed the amount of memory spent on slabs for very large objects.


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


# 11b5020f 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

rewrote the object cache (slab) implementation a bit, preparing for further integration.


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


# 8a96ba39 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some slab cleanups, split the C interface to another file.


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


# 0cd08b10 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

ups, TRACE_SLAB was on.


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


# 5d6551d6 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

removed some of the slab's initial heavy debugging. we now merge the links into the slab itself resulting in zero overhead per buffer with MergedLink strategy.


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


# d7ae189e 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

slab: be smarter when picking the underlying strategy for the slab C API (based on requested object size).


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


# e6fb3d39 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

more slab fixes, also introduced a new strategy optimized for medium sized buffers (64 >= x < 512) with lengths other than power of 2 (has an overhead of 2 words per buffer).


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


# dd89ad0e 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added locking to slab's Cache<>. Now we react to system's low memory conditions freeing up empty slabs.


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


# 81bc5709 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

assorted slab fixes.


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


# 81423c91 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added initial slab code to the kernel. It is still unused, and there is still no VM interaction.


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


# 271ac910a4cfdefa6393c1e7cb5e3a665404757d 09-Jan-2015 Adrien Destugues <pulkomandy@gmail.com>

Remove useless includes of khash.h

* These files were already converted to BOpenHashTable.
* For #9552.


# c3f0fd28cda13d70a8c092003609442e4e29cf78 12-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Fixed formatting of output in some debugger commands.

Currently all debugger commands assume 32-bit pointers when formatting their
output. This means that on x86_64 the output is incorrectly formatted. Fixed
this by adding a B_PRINTF_POINTER_WIDTH definition (16 on 64-bit, 8 on
32-bit), and using this to correctly format the output. Not all commands have
been fixed yet, but all VM, slab, VFS, team, thread and image commands should
be correct.


# 4be4fc6b1faddbd037146214a0011d320842b4f3 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 5cbe06f482858c8b79671927e887ab08375a721c 04-Dec-2011 Michael Lotz <mmlr@mlotz.ch>

Allow replacing the object cache with the guarded heap.

This allows to use the debug features of the guarded heap also on
allocations made through the object cache API. This is obivously
horrible for performance and uses up huge amounts of memory, so the
initial and grow sizes are adjusted accordingly.

Note that this is a rather simple hack, using the object_cache pointer
to transport the allocation size. The alignment is neglected completely.


# a1396579211a1ba97f118b5a498a34e52ef18803 28-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Tracking info wasn't always retrieved with the cache locked.

Getting the object slab does a hash lookup which needs to be protected
by the cache lock. Otherwise the hash table may be resized or otherwise
modified while we do the lookup, leading to errors.


# 905c75a595ed3c645b436c87beefbc5a60d01be0 04-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Tiny pointer style cleanup.


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


# 3d1f420b2320c2634d506b7767cd5d3e0640b72a 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
* Add "allocation_infos" KDL command. Can be used to print the allocation info,
including the stack trace, given an object cache, slab, allocation within a
slab or allocation address. It can also optionally be filtered by team/thread.
* Fix the AllocationDetailPrinterCallback to not access a possibly invalid
trace entry for printing a stack trace.


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


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

mmlr + bonefish:
* AllocationTrackingCallback::ProcessTrackingInfo(): Also pass the
allocation pointer.
* "allocations_per_caller" KDL command: Add option "-d". When given,
each allocation for the specified caller is printed, including the
respective stack trace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43087 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


# 72156a402f54ea4be9dc3e3e9704c612f7d9ad16 31-Oct-2011 Michael Lotz <mmlr@mlotz.ch>

bonefish+mmlr:
* Introduce "paranoid" malloc/free into the slab allocator (initializing
allocated memory to 0xcc and setting freed memory to 0xdeadbeef).
* Allow for optional stack traces for slab object cache tracing.


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


# 4b2adaae5ff698a896a07c9491fbe510dde79775 14-Jun-2011 Stefano Ceccherini <stefano.ceccherini@gmail.com>

Changed wrong help text


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


# 3aea1d4f53835e8ccbd87a2bdb114dafb988a094 15-Jul-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added ObjectCache::alignment, the object alignment and used the alignment for
incrementing the cache color cycle. Using the fixed value (8) would
potentially misalign the object again.
* Don't use CACHE_ALIGN_ON_SIZE for object caches any longer -- we have the
alignment parameter anyway (the flag is still used for the MemoryManager,
though).
* ObjectCache::InitSlab(): Slab coloring *was* done when CACHE_ALIGN_ON_SIZE
was given, i.e. exactly the wrong way around. Also the cache_color_cycle
computation was weird -- color 0 was used twice in a row.
* The "slabs" and "slab_cache" KDL commands also print the alignment, now.



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


# fa04c15cdee39691a126bda1a5b67eabe5750e43 18-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

object_cache_low_memory(): Reduce the cache pressure indicator even for the
"note" low resource state. Not doing so could result in a very high limit for
the number of empty slabs, which wouldn't change until reaching the "warning"
state.
Fixes #5816.


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


# d3166e469cd337a6910f1cb1515b74f73d36466f 29-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced no longer necessary send_signal_etc() work-arounds for
resume_thread().


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


# 88f1263865ec2896f16566c335ed95f7a81a2d50 03-Mar-2010 Axel Dörfler <axeld@pinc-software.de>

* The slab_cache command now also dumps the actual slab lists.


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


# 1c164de7d21bd20efda561b647ebe08717699096 01-Mar-2010 Axel Dörfler <axeld@pinc-software.de>

* Quick&dirty fix of a race condition that caused an endless loop in
object_cache_alloc(): the ObjectCache::total_objects count was increased in
ObjectCache::InitSlab(), but the slab was really only added at a later point
between the cache could be unlocked.
* If a second object_cache_reserve_internal() managed to be called while the
lock was unlocked, it would see that there has to be space available, and
will then return -- however, since the other thread could not yet place the
slab into the cache, object_cache_alloc() cannot find it.


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


# 464d9f1252a638eee63ca5cdf72e5cd321df47e1 24-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed object_depot_store() return value to void. It is now always takes
over ownership of the object. Fixes double free introduced in r35605.


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


# bc208a852bfe32af45b35147ce8e7a452c1b9890 24-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed TODO that isn't one.


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


# ff59ce680df5d2032ea5a11c666688269225f033 24-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* The low resource handler now empties the cache depot's magazines; before,
they were never freed unless the cache was destroyed (I just wondered why
my system would bury >1G in the magazines).
* Made the magazine capacity variable per cache, ie. for larger objects, it's
not a good idea to have 64*CPU buffers lying around in the worst case.
* Furthermore, the create_object_cache_etc()/object_depot_init() now have
arguments for the magazine capacity as well as the maximum number of full
unused magazines.
* By default, you might want to initialize both to zero, as then some hopefully
usable defaults are computed. Otherwise (the only current example is the
vm_page_mapping cache) you can just put in the values you'd want there.
The page mapping cache uses larger values, as its objects are usually
allocated and deleted in larger chunks.
* Beware, though, I couldn't test these changes yet as Qemu didn't like to run
today. I'll test these changes on another machine now.


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


# 54f3267e78aaf6fb1e2b941596f1c2863e7f1790 15-Feb-2010 Axel Dörfler <axeld@pinc-software.de>

* Fixed maintaining the object depot's free magazine count (it's not really used
though).
* Added/improved some KDL commands to make the slab easier to work with from
KDL.


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


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

Moved added the debugger commands from slab_init() to slab_init_post_area().
Those use malloc(), which obviously doesn't work before the heap is
initialized.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35288 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


# 34bfbec29790299524f5135bc8210eacb4c0c5ec 23-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

low resource handler: Clear the maintenance_in_progress flag also when
adding the cache to the maintenance queue. Not so important but more correct.


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


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

Reworked the object cache resizer (renamed to object cache maintainer) and
low resource handler functions. Particularly fixed the race conditions
between those and delete_object_cache().


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


# 8d1316fd23616f6dac131a0eba5dab08acc6e76d 22-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced CACHE_DONT_SLEEP by two new flags CACHE_DONT_WAIT_FOR_MEMORY and
CACHE_DONT_LOCK_KERNEL_SPACE. If the former is given, the slab memory manager
does not wait when reserving memory or pages. The latter prevents area
operations. The new flags add a bit of flexibility. E.g. when allocating page
mapping objects for userland areas CACHE_DONT_WAIT_FOR_MEMORY is sufficient,
i.e. the allocation will succeed as long as pages are available.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35246 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


# 08d66c12887e28e2760a85076561eba91a00ab66 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Always unlock the object cache while allocating memory. This is necessary for
the CACHE_DONT_SLEEP flag to work for real, since otherwise the thread could
block on the mutex held by a thread allocating memory. We use two condition
variables to prevent multiple threads from allocating slabs at the same time.


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


# 8766b8b4b92d8bdc4e17b946356edf6a537538ea 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reverted r35203, i.e. ObjectCache::object_per_slab is gone again.
* Changed the semantics of object_cache_reserve_internal(). Now it makes sure
the given number of objects are free. As a side effect this also changes
the semantics of object_cache_reserve() similarly, though I have trouble
seeing the purpose of the function in the first place.


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


# 4ebe37ab694f3941b36d8d61a0d6614cc76791b2 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added ObjectCache::objects_per_slab, which allowed to squash the TODO in
object_cache_reserve_internal().


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


# bb439b871e0be2e107ecc868be8c5660836f4253 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Consequently propagate the CACHE_DONT_SLEEP flag.
* block_alloc(): Create B_FULL_LOCK area.


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


# d66916e33b3df16f88cf939f37be7ce580787d72 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Shuffled functions a bit, so that they are in a reasonable order.


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


# 53a87b035bfa018353e10f6ea293a270652d1fac 20-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed debug left-over.


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


# 20ca0c5eaa6a1d4e0a3ddc9d203eab905b3a34d7 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* object_cache_return_object_wrapper(): Calling object_cache_free() is a bad
idea, since that would potentially add the object back to the object store
or lead to infinite recursion. When the object cache is destroyed it most
likely led to infinite loops, because the object would alternately be
removed from and added back to the object store.
* delete_object_cache(): Lock after destroying the object store, so we don't
deadlock.
* Use the object store on SMP machines. It seems to work, though I only
tested with the network stack and that seems to have problems of its own.


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


# 825566f82f652d82ffaf3f0deca0a2bcda1e02c2 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Split the slab allocator code into separate source files and C++-ified
things a bit.
* Some style cleanup.
* The object depot does now have a cookie that will be passed to the return
hook.
* Fixed object_cache_return_object_wrapper() using the new cookie.


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


# 0fc052b47dfb40f53cddfb38c9498384b22b5466 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Moved the definition of the CACHE_ALIGN_ON_SIZE flag to the header and fixed
its value.


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


# a8806e5e0dad28238343bd4dcc8d035657d358ff 19-Jan-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed headers/private/kernel/slab/Depot.h to ObjectDepot.h.
* Moved the object depot code to its own source file.


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


# e50cf8765be50a7454c9488db38b638cf90805af 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


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


# 90d870c1556bdc415c7f41de5474ebebb0ceebdd 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved VMAddressSpace definition to vm_address_space.h.
* "Classified" VMAddressSpace, i.e. turned the vm_address_space_*() functions
into methods, made all attributes (but "areas") private, and added
accessors.
* Also turned the vm.cpp functions vm_area_lookup() and
remove_area_from_address_space() into VMAddressSpace methods. The rest of
the area management functionality will follow soon.


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


# 1db31d4dbddb1f0af6c41f8f12da95f1b4439d67 27-Nov-2009 Axel Dörfler <axeld@pinc-software.de>

* The slab and the block cache now both also react on address space shortages.


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


# 68b6dce107b4a515e87004fc57d76b36a6c0a212 12-Aug-2009 Michael Lotz <mmlr@mlotz.ch>

We already panic to indicate that something's wrong, no real need to crash
afterwards instead of returning gracefully.


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


# ea2abd110bd6a4518a954477562e2dd94a5fef9d 02-Aug-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed the ROUNDOWN macro to ROUNDDOWN. Also changed the implementation of
ROUNDUP to use '*' and '/' -- the compiler will optimize that for powers of
two anyway and this implementation works for other numbers as well.
* The thread::fault_handler use in C[++] code was broken with gcc 4. At least
when other functions were invoked. Trying to trick the compiler wasn't a
particularly good idea anyway, since the next compiler version could break
the trick again. So the general policy is to use the fault handlers only in
assembly code where we have full control. Changed that for x86 (save for the
vm86 mode, which has a similar mechanism), but not for the other
architectures.
* Introduced fault_handler, fault_handler_stack_pointer, and fault_jump_buffer
fields in the cpu_ent structure, which must be used instead of
thread::fault_handler in the kernel debugger. Consequently user_memcpy() must
not be used in the kernel debugger either. Introduced a debug_memcpy()
instead.
* Introduced debug_call_with_fault_handler() function which calls a function
in a setjmp() and fault handler context. The architecture specific backend
arch_debug_call_with_fault_handler() has only been implemented for x86 yet.
* Introduced debug_is_kernel_memory_accessible() for use in the kernel
debugger. It determines whether a range of memory can be accessed in the
way specified. The architecture specific back end
arch_vm_translation_map_is_kernel_page_accessible() has only been implemented
for x86 yet.
* Added arch_debug_unset_current_thread() (only implemented for x86) to unset
the current thread pointer in the kernel debugger. When entering the kernel
debugger we do some basic sanity checks of the currently set thread structure
and unset it, if they fail. This allows certain commands (most importantly
the stack trace command) to avoid accessing the thread structure.
* x86: When handling a double fault, we do now install a special handler for
page faults. This allows us to gracefully catch faulting commands, even if
e.g. the thread structure is toast.

We are now in much better shape to deal with double faults. Hopefully avoiding
the triple faults that some people have been experiencing on their hardware
and ideally even allowing to use the kernel debugger normally.


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


# d3b44ccb1470db823a443d0f9b32e09bfa0d0a9c 29-Jul-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Added explicit physical address parameter to vm_create_anonymous_area() and
create_area_etc(). 0 for the default behavior.


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


# 5147963dcd57fefa4f63c484eb88e9eaf4002976 26-Jul-2009 Stephan Aßmus <superstippi@gmx.de>

headers/private/kernel/util/OpenHashTable.h, Hugo's version, is a bit nicer than
Tracker's OpenHashTable.h which it should eventually replace. We've renamed the
class to BOpenHashTable and changed the interface slightly so that HashTableLink
became superfluous.
Adapted all the code that used it. Since the OpenHashTables no longer clash,
this should fix the GCC4 build.


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


# 591bc3f2d99168a9b2a9bdcbda20c47e97a4ff80 28-May-2009 Jérôme Duval <korli@users.berlios.de>

* various fixes identified by gcc4, provided by Joe Prostko


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


# c33667d400856680a8e0122300861eda77d1847a 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


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


# 7ce72b986c1dfa844e8362a45dcec078aea91d56 21-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Implement CACHE_DONT_SLEEP partially. At least for small object caches
without object depot it should be complete. For the other stuff
internal_alloc() would need to pass the flag on to block_alloc(), but
that isn't possible yet.
* Adjusted the low memory handler to respect the minimum object reserve
of the object caches.

The swap_test_heap test does seem to pass reliably with 128 MB RAM and
128 MB allocation, now. It's quite slow, though. Particularly while the
allocation is filled, the system is completely unusable.


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


# 1cda5944ad23e0ee134b13b9e3c0c0fd2f68d6ca 20-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object_cache_set_minimum_reserve() which sets the minimal number
of free objects an object cache should try to have ready. If the number
of free objects drops below the threshold, a new urgent priority thread
is asked to asynchronously resize the object cache (pretty similar to
the heap grower thread). Such a mechanism is necessary for code paths
that are supposed to free pages, but may need memory themselves (like
the swap support).


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


# 5db876653b9bd56d9cf54f71e28f210f9782d2d1 05-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object_cache_get_usage() function that returns the memory
allocated by an object cache.


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


# 5c99d639708df9b4e2cc847b38d510149d19ec78 22-Jul-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/vm into trunk. This
introduces the following relevant changes:
* VMCache:
- Renamed vm_cache to VMCache, merged it with vm_store and made it a
C++ class with virtual methods (replacing the store operations).
Turned the different store implementations into subclasses.
- Introduced MergeStore() callback, changed semantics of Commit().
- Changed locking and referencing semantics. A reference can only be
acquired/released with the cache locked. An unreferenced cache is
deleted and a mergeable cache merged when it is unlocked. This
removes the "busy" state of a cache and simplifies the page fault
code.
* Added VMAnonymousCache, which will implement swap support (work by
Zhao Shuai). It is not integrated and used yet, though.
* Enabled the mutex/recursive lock holder asserts.
* Fixed DoublyLinkedList::Swap().
* Generalized the low memory handler to a low resource handler. And made
semaphores and reserved memory handled resources. Made
vm_try_resource_memory() optionally wait (with timeout), and used that
feature to reserve memory for areas.
...


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


# f5b3a6a7968b849c8cb3d06ffe6d19acccf910a8 05-Jun-2008 Michael Lotz <mmlr@mlotz.ch>

* Initialize all static mutexes in the kernel through a MUTEX_INITIALIZER()
and remove the then unneeded mutex_init() for them.
* Remove the workaround for allowing uninitialized mutexes on kernel startup.
As they are all initialized statically through the MUTEX_INITIALIZER() now
this is not needed anymore.
* An uninitialized mutex will now cause a panic when used to find possibly
remaining cases.
* Remove now unnecessary driver_settings_init_post_sem() function.

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


# b0f5179aa51eb680cdeea656a8b11fdbc6b56d63 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed recursive_lock to use a mutex instead of a semaphore.
* Adjusted code using recursive locks respectively. The initialization
cannot fail anymore, and it is possible to use recursive locks in the
early boot process (even uninitialized, if in BSS), which simplifies
things a little.


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


# 962353439998f83a7cfa3cf7fa413ed49be4a030 08-May-2008 Axel Dörfler <axeld@pinc-software.de>

Now uses mutexes instead of benaphores, that also simplified object
instantiation at early boot a bit.


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


# 97c0a2b3f1f9c3782c833b1d3201a4472259afac 27-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Paranoia checks were accidentally globally enabled by default. Object
* cache paranoia was always enabled.
* Changed from paranoia on/off to levels. Adjusted the macros to take a
level argument.


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


# 6bf15ffcdcfc62c39948e0e9449064e65b7f13bd 27-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed macros that enable tracing for individual components from
defined/undefined to numeric values (0 for undefined). This allows for
trace levels.
* Set SYSCALL_TRACING_IGNORE_KTRACE_OUTPUT default to 1, since this is
what one usually wants.


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


# 2be0b7cc432eee1cb0c2a5e2edf5e85a6eb5687d 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added paranoia checks. They reveal that a net buffer data node is freed
twice when running the OpenSSH "forwarding" test, which corrupts the
slab's object list. It's not quite clear to me yet why that happens.


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


# 7526aa66f41e9b8058e5cc294fb1ade9bcf4c940 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed some leftover junk.


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


# 67411c9d36b48c6c7a7d5c00fb060ac4388647a4 26-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added object cache kernel tracing.


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


# 987de537468a66f55f5b4050f7ddd84484b002ae 02-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Also replaced the cpu store's lock with a recursive lock in order
to fix bug #1731.
* However, it turns out that depot destruction obviously doesn't work
correctly, at least we keep partial or full slabs around when we're
using them (which causes the code to panic).
* Therefore, I've now disabled depots completely, until I find the time
to really work on that code.


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


# 45b17b80d14e99316d9c853e4248b6b659d0f1ff 01-Feb-2008 Axel Dörfler <axeld@pinc-software.de>

* Temporarily switched to a recursive lock for the depot.
* While this is not a really good idea for a lock with supposedly little
contention, but it'll fix bug #1731. I haven't tested it yet, but will
do so in a minute :-)
* I will need to rework the slab anyway so that it's possible to use it
as a replacement for our heap, and then I'll switch back to a benaphore
again.


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


# 06958f901c137e593fbe406c49e557bc89b8542a 17-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

We generally handle NULL pointers in free() and friends gracefully.


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


# c21af3b29989bb771d9548edbaa5259201ee8b27 16-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Print the missing object.

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


# c6ee79ce388772e847063f6d52111db54b0bbc71 16-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

* vm_create_anonymous_area() now accepts B_ANY_KERNEL_BLOCK_ADDRESS.
* As a temporary work-around for the current slab allocator's area usage,
I added the CACHE_LARGE_SLAB flag, which will force the allocator to
use larger areas.


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


# aad0d344f0b6e3c3e1d48f95a43b8e97bc83d585 03-Jan-2008 Axel Dörfler <axeld@pinc-software.de>

The slab areas shouldn't be user readable...


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


# 23128566a45f71c5978e70a84b329f9e96331385 21-Oct-2007 Axel Dörfler <axeld@pinc-software.de>

Slab.h no longer includes Depot.h.


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


# b062823d817b8d2bdffe10cb3d390230dffdff18 29-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* register_low_memory_handler() was called too early by several kernel
components - now, we divide the initialization of that service into two parts
which allows this (before, most handlers were gone after boot).
* Added debugger command that dumps the low memory handlers.
* The slab allocator now registers its low memory handler with a higher
priority, so that it'll run before the potentially heavier ones.


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


# 5c4ed86b56868e2584298c05792a6e65d4d3fa78 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Moved some definitions from vm_types.h that functions in vm.h need as
arguments into vm.h.
* This should fix the broken build from earlier - thanks Stefano for the note!
* That also allowed to clean some other includes a bit.


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


# e6dc7903e4277bf6e22527ed611df619c7e645f1 26-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* vm.h no longer includes vm_types.h - only those that actually need access
to the private VM types are including vm_types.h now.
* Removed vm_page, vm_area, vm_cache, and vm_address_space typedefs; it's
cleaner this way, and the actual types are only used in C++ files now,
anyway.
* And that caused changes in many files...
* Made commpage.h self-containing.
* Minor cleanup.


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


# 84052230379abf8e556e20e499d9a6040157f4a6 31-Jul-2007 Axel Dörfler <axeld@pinc-software.de>

axeld+bonefish: Got rid of the ParentType in the HashTableDefinition; it doesn't really
belong there.


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


# 8cfe0be38e511ad0dfcbbb6b04fe00fd2260900b 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

slab/cache: a couple more fixes.

- on CACHE_DURING_BOOT init benaphore count with 1.
- account for allocated space on early_allocate_pages.
- fixed slab position calculation in small slabs.
- we can now init all allocator sizes early rather than later.


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


# 698b6d7195c415b907449e44cd2fd295bbdb8523 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cache/slab: when CACHE_DURING_BOOT is specified, use vm_allocate_early to obtain pages for slabs, and create the associated areas on post bootup.


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


# 39af44596634e640b76b9cef47acb1f93e6bf514 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added object_cache_reserve to allow cache users to pre-allocate slabs.


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


# 11debaf6e42791116afaf167883ea2c73f88db66 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added CACHE_UNLOCKED_PAGES flag to allow caches' pages to be created with no locking instead of full locking.


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


# c49aa60ace411ea452ebf3ad0b49d1da9d3cc10c 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

cache allocator: for allocations > 8k create areas, and delete them on free.


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


# 0be6e97788ab8763aeb034c2cd0117df9b1fd408 29-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

minimal cleanups


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


# 9a9cba598a13516e7b1e9c0af87ffb8cd30298fc 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

don't need TRACE_SLAB by default now.


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


# 6bad4934393e784ea38685a76d28643deec67184 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

pushed the slab init a bit deeper. added a object cache based allocator, including a bootstrap mechanism to have it init during bootup.


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


# 6e31ae98f913672d23413f4c4f1422416284dafe 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some object cache / slab improvements.

- call the reclaimer callback when low on memory.
- use the depot when on multi-cpu setups (for scalability).
- fixed the amount of memory spent on slabs for very large objects.


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


# 11b5020f2fa2dcc510704cf3fb8dc9c3d3ea1f71 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

rewrote the object cache (slab) implementation a bit, preparing for further integration.


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


# 8a96ba39e3079d7c31898deb920496c101391d66 28-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

some slab cleanups, split the C interface to another file.


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


# 0cd08b100c9658e2ec2510f14efc797b1ef10b08 27-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

ups, TRACE_SLAB was on.


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


# 5d6551d69fba2bf63472185322b85f96fbc68b54 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

removed some of the slab's initial heavy debugging. we now merge the links into the slab itself resulting in zero overhead per buffer with MergedLink strategy.


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


# d7ae189ecfa82a8ee64a75a49b7b0a3f7b5f24ee 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

slab: be smarter when picking the underlying strategy for the slab C API (based on requested object size).


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


# e6fb3d3947b167b0b79b4c6932c481fde9d79c5c 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

more slab fixes, also introduced a new strategy optimized for medium sized buffers (64 >= x < 512) with lengths other than power of 2 (has an overhead of 2 words per buffer).


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


# dd89ad0e7e1cd4d1499084bc781e8a19ae78deae 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added locking to slab's Cache<>. Now we react to system's low memory conditions freeing up empty slabs.


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


# 81bc5709221d7cfd6696e1422b388fd01e5cbff6 26-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

assorted slab fixes.


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


# 81423c91c784578220954adf9ed003575f8db8a0 25-Apr-2007 Hugo Santos <hugosantos@nowhere.fake>

added initial slab code to the kernel. It is still unused, and there is still no VM interaction.


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