Commit Graph

33 Commits

Author SHA1 Message Date
Ingo Weinhold ef9d9a1720 Add new operator that takes an ObjectCache* and allocation flags and
template function object_cache_delete() to be used to delete objects
constructed with it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43132 a95241bf-73f2-0310-859d-f6bbb57e9c96
2011-11-02 21:12:09 +00:00
Michael Lotz 72156a402f 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
2011-10-31 21:58:00 +00:00
Ingo Weinhold 464d9f1252 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
2010-02-24 19:04:41 +00:00
Axel Dörfler ff59ce680d * 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
2010-02-24 14:43:20 +00:00
Ingo Weinhold deee8524b7 * Introduced {malloc,memalign,free}_etc() which take an additional "flags"
argument. They replace the previous special-purpose allocation functions
  (malloc_nogrow(), vip_io_request_malloc()).
* Moved the I/O VIP heap to heap.cpp accordingly.
* Added quite a bit of passing around of allocation flags in the VM,
  particularly in the VM*AddressSpace classes.
* Fixed IOBuffer::GetNextVirtualVec(): It was ignoring the VIP flag and always
  allocated on the normal heap.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35316 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-01-27 12:45:53 +00:00
Ingo Weinhold cff6e9e406 * The system now holds back a small reserve of committable memory and pages. The
memory and page reservation functions have a new "priority" parameter that
  indicates how deep the function may tap into that reserve. The currently
  existing priority levels are "user", "system", and "VIP". The idea is that
  user programs should never be able to cause a state that gets the kernel into
  trouble due to heavy battling for memory. The "VIP" level (not really used
  yet) is intended for allocations that are required to free memory eventually
  (in the page writer). More levels are thinkable in the future, like "user real
  time" or "user system server".
* Added "priority" parameters to several VMCache methods.
* Replaced the map_backing_store() "unmapAddressRange" parameter by a "flags"
  parameter.
* Added area creation flag CREATE_AREA_PRIORITY_VIP and slab allocator flag
  CACHE_PRIORITY_VIP indicating the importance of the request.
* Changed most code to pass the right priorities/flags.

These changes already significantly improve the behavior in low memory
situations. I've tested a bit with 64 MB (virtual) RAM and, while not
particularly fast and responsive, the system remains at least usable under high
memory pressure.
As a side effect the slab allocator can now be used as general memory allocator.
Not done by default yet, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35295 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-01-26 14:44:58 +00:00
Ingo Weinhold 71f65beeb3 Marked CACHE_UNLOCKED_PAGES as unsupported.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35281 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-01-25 12:22:36 +00:00
Ingo Weinhold 8d1316fd23 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
2010-01-22 21:19:23 +00:00
Ingo Weinhold 86c794e5c1 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
2010-01-21 23:10:52 +00:00
Ingo Weinhold 453a2bdd18 Replaced the locking strategy (formerly a recursive lock for the depot and
one for each per CPU store):
* The depot is now protected by a R/W lock combined with a spinlock. It is
  required to either hold read lock + spinlock or just the write lock.
* When accessing the per CPU stores we only need to acquire the read lock
  and disable interrupts. When switching magazines with the depot we
  additionally get the spinlock.
* When allocating a new magazine we do completely unlock.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35200 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-01-20 13:00:57 +00:00
Ingo Weinhold 7dcd388aa6 Coding style fix.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35180 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-01-19 20:36:29 +00:00
Ingo Weinhold 825566f82f * 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
2010-01-19 19:13:25 +00:00
Ingo Weinhold 0fc052b47d 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
2010-01-19 10:17:16 +00:00
Ingo Weinhold a8806e5e0d * 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
2010-01-19 10:12:48 +00:00
Ingo Weinhold 1cda5944ad 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
2008-08-21 03:21:37 +00:00
Ingo Weinhold 5db876653b 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
2008-08-06 00:07:55 +00:00
Axel Dörfler 45b17b80d1 * 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
2008-02-02 12:12:54 +00:00
Axel Dörfler c6ee79ce38 * 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
2008-01-16 20:30:16 +00:00
Axel Dörfler 23128566a4 Slab.h no longer includes Depot.h.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22647 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-10-21 20:56:34 +00:00
Axel Dörfler b623d277fa Moved Base.h into Slab.h, and removed Base.h.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22646 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-10-21 20:44:19 +00:00
Hugo Santos 39af445966 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
2007-04-29 21:45:23 +00:00
Hugo Santos 11debaf6e4 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
2007-04-29 20:55:44 +00:00
Hugo Santos 0be6e97788 minimal cleanups
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20901 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-04-29 13:11:30 +00:00
Hugo Santos 6bad493439 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
2007-04-29 02:23:37 +00:00
Hugo Santos 6e31ae98f9 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
2007-04-28 21:35:23 +00:00
Hugo Santos 11b5020f2f 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
2007-04-28 18:53:58 +00:00
Hugo Santos 8a96ba39e3 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
2007-04-28 09:37:38 +00:00
Hugo Santos 5d6551d69f 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
2007-04-26 15:40:53 +00:00
Hugo Santos e6fb3d3947 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
2007-04-26 11:38:24 +00:00
Hugo Santos dd89ad0e7e 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
2007-04-26 07:31:19 +00:00
Hugo Santos b8c0d6618e gcc 4 compilation fixes.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20835 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-04-26 06:32:25 +00:00
Hugo Santos 81bc570922 assorted slab fixes.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20833 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-04-26 06:05:08 +00:00
Hugo Santos 81423c91c7 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
2007-04-26 03:41:24 +00:00