2002-07-25 18:49:29 +04:00
|
|
|
/*
|
2006-03-13 20:18:15 +03:00
|
|
|
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
2005-05-26 13:11:30 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2008-02-11 00:00:13 +03:00
|
|
|
#ifndef _KERNEL_HEAP_H
|
|
|
|
#define _KERNEL_HEAP_H
|
2005-05-26 13:11:30 +04:00
|
|
|
|
2004-10-18 19:23:34 +04:00
|
|
|
#include <OS.h>
|
2003-05-03 20:03:26 +04:00
|
|
|
|
2008-10-20 18:24:46 +04:00
|
|
|
#include "kernel_debug_config.h"
|
|
|
|
|
|
|
|
|
2008-02-11 00:00:13 +03:00
|
|
|
// allocate 16MB initial heap for the kernel
|
2008-02-18 04:04:19 +03:00
|
|
|
#define INITIAL_HEAP_SIZE 16 * 1024 * 1024
|
2008-07-02 03:19:35 +04:00
|
|
|
// grow by another 4MB each time the heap runs out of memory
|
|
|
|
#define HEAP_GROW_SIZE 4 * 1024 * 1024
|
2008-06-18 23:55:51 +04:00
|
|
|
// allocate a dedicated 1MB area for dynamic growing
|
|
|
|
#define HEAP_DEDICATED_GROW_SIZE 1 * 1024 * 1024
|
2008-07-02 03:19:35 +04:00
|
|
|
// use areas for allocations bigger than 1MB
|
|
|
|
#define HEAP_AREA_USE_THRESHOLD 1 * 1024 * 1024
|
2002-08-05 21:22:19 +04:00
|
|
|
|
2002-07-25 18:49:29 +04:00
|
|
|
|
2008-08-14 04:40:40 +04:00
|
|
|
typedef struct heap_class_s {
|
|
|
|
const char *name;
|
|
|
|
uint32 initial_percentage;
|
|
|
|
size_t max_allocation_size;
|
|
|
|
size_t page_size;
|
|
|
|
size_t min_bin_size;
|
|
|
|
size_t bin_alignment;
|
|
|
|
uint32 min_count_per_page;
|
|
|
|
size_t max_waste_per_page;
|
|
|
|
} heap_class;
|
|
|
|
|
|
|
|
typedef struct heap_allocator_s heap_allocator;
|
|
|
|
|
|
|
|
|
2004-10-18 19:23:34 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-08-03 17:59:45 +04:00
|
|
|
// malloc- and memalign_nogrow disallow waiting for a grow to happen - only to
|
|
|
|
// be used by vm functions that may deadlock on a triggered area creation.
|
* The alphabet is obviously hard, moved some tracing defines at their
(hopefully) correct place.
* It seems to be even harder to understand basic locking primitives: when you
think about it, it shouldn't surprise you that conditional variables never
return B_WOULD_BLOCK. This fixes gdb again.
* Added tracing support to the ports subsystem.
* get_port_message() will now resize the port heap if needed (but will also
take timeouts into account while doing so, more or less). The initial port
space is 4MB (as before), the growth rate is the same, and the system wide
limit is arbitrarily set to 64 MB (all swappable). A team limit has been set
to 8 MB, but is not enforced yet. Since ports are using up address space in
the kernel, those seems to be proper limits.
* This also fixes a strange, and rare lockup where the mouse cursor would still
move, but everything else would basically hang, but look perfectly normal from
KDL on the first look. As recently happened on Brecht's laptop, and debugged
by mmlr and me: the cbuf space got used up when lots of windows wanted to
redraw after a workspace switch. The app_server wouldn't answer anymore to
client requests, but thought it would have done so, as LinkSender::Flush()
doesn't care if it got a B_NO_MEMORY (the ports will now block until memory
is available if possible, so that should not be a problem anymore).
* Improved "port" KDL command, it now also prints the messages in the port.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33735 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-10-23 03:14:10 +04:00
|
|
|
void* memalign_nogrow(size_t alignment, size_t size);
|
|
|
|
void* malloc_nogrow(size_t size);
|
2008-06-18 23:55:51 +04:00
|
|
|
|
* The alphabet is obviously hard, moved some tracing defines at their
(hopefully) correct place.
* It seems to be even harder to understand basic locking primitives: when you
think about it, it shouldn't surprise you that conditional variables never
return B_WOULD_BLOCK. This fixes gdb again.
* Added tracing support to the ports subsystem.
* get_port_message() will now resize the port heap if needed (but will also
take timeouts into account while doing so, more or less). The initial port
space is 4MB (as before), the growth rate is the same, and the system wide
limit is arbitrarily set to 64 MB (all swappable). A team limit has been set
to 8 MB, but is not enforced yet. Since ports are using up address space in
the kernel, those seems to be proper limits.
* This also fixes a strange, and rare lockup where the mouse cursor would still
move, but everything else would basically hang, but look perfectly normal from
KDL on the first look. As recently happened on Brecht's laptop, and debugged
by mmlr and me: the cbuf space got used up when lots of windows wanted to
redraw after a workspace switch. The app_server wouldn't answer anymore to
client requests, but thought it would have done so, as LinkSender::Flush()
doesn't care if it got a B_NO_MEMORY (the ports will now block until memory
is available if possible, so that should not be a problem anymore).
* Improved "port" KDL command, it now also prints the messages in the port.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33735 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-10-23 03:14:10 +04:00
|
|
|
void* memalign(size_t alignment, size_t size);
|
2004-10-18 19:23:34 +04:00
|
|
|
|
2008-03-09 20:44:55 +03:00
|
|
|
void deferred_free(void* block);
|
|
|
|
|
2008-03-30 03:55:34 +04:00
|
|
|
void* malloc_referenced(size_t size);
|
|
|
|
void* malloc_referenced_acquire(void* data);
|
|
|
|
void malloc_referenced_release(void* data);
|
|
|
|
|
* The alphabet is obviously hard, moved some tracing defines at their
(hopefully) correct place.
* It seems to be even harder to understand basic locking primitives: when you
think about it, it shouldn't surprise you that conditional variables never
return B_WOULD_BLOCK. This fixes gdb again.
* Added tracing support to the ports subsystem.
* get_port_message() will now resize the port heap if needed (but will also
take timeouts into account while doing so, more or less). The initial port
space is 4MB (as before), the growth rate is the same, and the system wide
limit is arbitrarily set to 64 MB (all swappable). A team limit has been set
to 8 MB, but is not enforced yet. Since ports are using up address space in
the kernel, those seems to be proper limits.
* This also fixes a strange, and rare lockup where the mouse cursor would still
move, but everything else would basically hang, but look perfectly normal from
KDL on the first look. As recently happened on Brecht's laptop, and debugged
by mmlr and me: the cbuf space got used up when lots of windows wanted to
redraw after a workspace switch. The app_server wouldn't answer anymore to
client requests, but thought it would have done so, as LinkSender::Flush()
doesn't care if it got a B_NO_MEMORY (the ports will now block until memory
is available if possible, so that should not be a problem anymore).
* Improved "port" KDL command, it now also prints the messages in the port.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33735 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-10-23 03:14:10 +04:00
|
|
|
void heap_add_area(heap_allocator* heap, area_id areaID, addr_t base,
|
|
|
|
size_t size);
|
2008-08-14 04:40:40 +04:00
|
|
|
heap_allocator* heap_create_allocator(const char* name, addr_t base,
|
2009-10-22 12:57:34 +04:00
|
|
|
size_t size, const heap_class* heapClass, bool allocateOnHeap);
|
2008-08-14 04:40:40 +04:00
|
|
|
void* heap_memalign(heap_allocator* heap, size_t alignment, size_t size);
|
|
|
|
status_t heap_free(heap_allocator* heap, void* address);
|
|
|
|
|
2008-08-21 07:04:12 +04:00
|
|
|
#if KERNEL_HEAP_LEAK_CHECK
|
|
|
|
void heap_set_get_caller(heap_allocator* heap, addr_t (*getCaller)());
|
|
|
|
#endif
|
|
|
|
|
2006-03-19 18:02:21 +03:00
|
|
|
status_t heap_init(addr_t heapBase, size_t heapSize);
|
2008-02-11 00:00:13 +03:00
|
|
|
status_t heap_init_post_sem();
|
|
|
|
status_t heap_init_post_thread();
|
2004-10-18 19:23:34 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2008-07-23 00:36:32 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
#include <new>
|
|
|
|
|
2008-10-22 18:46:20 +04:00
|
|
|
#include <util/SinglyLinkedList.h>
|
|
|
|
|
|
|
|
|
2008-07-23 00:36:32 +04:00
|
|
|
static const struct nogrow_t {
|
|
|
|
} nogrow = {};
|
|
|
|
|
2009-10-11 02:29:11 +04:00
|
|
|
|
2008-07-23 00:36:32 +04:00
|
|
|
inline void*
|
2008-10-17 12:32:42 +04:00
|
|
|
operator new(size_t size, const nogrow_t& nogrow) throw()
|
2008-07-23 00:36:32 +04:00
|
|
|
{
|
|
|
|
return malloc_nogrow(size);
|
|
|
|
}
|
|
|
|
|
2008-10-22 18:46:20 +04:00
|
|
|
|
2009-10-11 02:29:11 +04:00
|
|
|
inline void*
|
|
|
|
operator new[](size_t size, const nogrow_t& nogrow) throw()
|
|
|
|
{
|
|
|
|
return malloc_nogrow(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-22 18:46:20 +04:00
|
|
|
class DeferredDeletable : public SinglyLinkedListLinkImpl<DeferredDeletable> {
|
|
|
|
public:
|
|
|
|
virtual ~DeferredDeletable();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void deferred_delete(DeferredDeletable* deletable);
|
|
|
|
|
|
|
|
|
2008-07-23 00:36:32 +04:00
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
2002-10-30 02:03:47 +03:00
|
|
|
#endif /* _KERNEL_MEMHEAP_H */
|