* 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
This commit is contained in:
Ingo Weinhold
2010-01-27 12:45:53 +00:00
parent 94a877f0e5
commit deee8524b7
37 changed files with 511 additions and 458 deletions
+35 -10
View File
@@ -23,6 +23,12 @@
#define HEAP_AREA_USE_THRESHOLD 1 * 1024 * 1024
// allocation/deallocation flags for {malloc,free}_etc()
#define HEAP_DONT_WAIT_FOR_MEMORY 0x01
#define HEAP_DONT_LOCK_KERNEL_SPACE 0x02
#define HEAP_PRIORITY_VIP 0x04
typedef struct heap_class_s {
const char *name;
uint32 initial_percentage;
@@ -41,10 +47,9 @@ typedef struct heap_allocator_s heap_allocator;
extern "C" {
#endif
// 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.
void* memalign_nogrow(size_t alignment, size_t size);
void* malloc_nogrow(size_t size);
void* memalign_etc(size_t alignment, size_t size, uint32 flags);
void free_etc(void* address, uint32 flags);
void* memalign(size_t alignment, size_t size);
@@ -74,6 +79,13 @@ status_t heap_init_post_thread();
#endif
static inline void*
malloc_etc(size_t size, uint32 flags)
{
return memalign_etc(0, size, flags);
}
#ifdef __cplusplus
#include <new>
@@ -81,21 +93,34 @@ status_t heap_init_post_thread();
#include <util/SinglyLinkedList.h>
static const struct nogrow_t {
} nogrow = {};
struct malloc_flags {
uint32 flags;
malloc_flags(uint32 flags)
:
flags(flags)
{
}
malloc_flags(const malloc_flags& other)
:
flags(other.flags)
{
}
};
inline void*
operator new(size_t size, const nogrow_t& nogrow) throw()
operator new(size_t size, const malloc_flags& flags) throw()
{
return malloc_nogrow(size);
return malloc_etc(size, flags.flags);
}
inline void*
operator new[](size_t size, const nogrow_t& nogrow) throw()
operator new[](size_t size, const malloc_flags& flags) throw()
{
return malloc_nogrow(size);
return malloc_etc(size, flags.flags);
}
+14 -12
View File
@@ -8,24 +8,26 @@
#define _SLAB_SLAB_H_
#include <KernelExport.h>
#include <OS.h>
#include <heap.h>
enum {
/* create_object_cache_etc flags */
CACHE_NO_DEPOT = 1 << 0,
CACHE_UNLOCKED_PAGES = 1 << 1, // unsupported
CACHE_LARGE_SLAB = 1 << 2,
/* object_cache_{alloc,free}() flags */
CACHE_DONT_WAIT_FOR_MEMORY = HEAP_DONT_WAIT_FOR_MEMORY,
CACHE_DONT_LOCK_KERNEL_SPACE = HEAP_DONT_LOCK_KERNEL_SPACE,
CACHE_PRIORITY_VIP = HEAP_PRIORITY_VIP,
CACHE_ALLOC_FLAGS = CACHE_DONT_WAIT_FOR_MEMORY
| CACHE_DONT_LOCK_KERNEL_SPACE
| CACHE_PRIORITY_VIP,
/* object_cache_{alloc,free}() flags */
CACHE_DONT_WAIT_FOR_MEMORY = 1 << 8,
CACHE_DONT_LOCK_KERNEL_SPACE = 1 << 9,
CACHE_PRIORITY_VIP = 1 << 10,
/* create_object_cache_etc flags */
CACHE_NO_DEPOT = 0x08000000,
CACHE_UNLOCKED_PAGES = 0x10000000, // unsupported
CACHE_LARGE_SLAB = 0x20000000,
/* internal */
CACHE_ALIGN_ON_SIZE = 1 << 30,
CACHE_DURING_BOOT = 1 << 31
CACHE_ALIGN_ON_SIZE = 0x40000000,
CACHE_DURING_BOOT = 0x80000000
};
struct ObjectCache;
-2
View File
@@ -289,8 +289,6 @@ public:
bool partialTransfer,
size_t bytesTransferred) = 0;
void operator delete(void* address, size_t size);
static status_t IORequestCallback(void* data,
io_request* request, status_t status,
bool partialTransfer,
+18 -12
View File
@@ -70,25 +70,31 @@ public:
virtual VMArea* LookupArea(addr_t address) const = 0;
virtual VMArea* CreateArea(const char* name, uint32 wiring,
uint32 protection) = 0;
virtual void DeleteArea(VMArea* area) = 0;
uint32 protection,
uint32 allocationFlags) = 0;
virtual void DeleteArea(VMArea* area,
uint32 allocationFlags) = 0;
virtual status_t InsertArea(void** _address, uint32 addressSpec,
size_t size, VMArea* area) = 0;
virtual void RemoveArea(VMArea* area) = 0;
size_t size, VMArea* area,
uint32 allocationFlags) = 0;
virtual void RemoveArea(VMArea* area,
uint32 allocationFlags) = 0;
virtual bool CanResizeArea(VMArea* area, size_t newSize) = 0;
virtual status_t ResizeArea(VMArea* area, size_t newSize) = 0;
virtual status_t ShrinkAreaHead(VMArea* area, size_t newSize)
= 0;
virtual status_t ShrinkAreaTail(VMArea* area, size_t newSize)
= 0;
virtual status_t ResizeArea(VMArea* area, size_t newSize,
uint32 allocationFlags) = 0;
virtual status_t ShrinkAreaHead(VMArea* area, size_t newSize,
uint32 allocationFlags) = 0;
virtual status_t ShrinkAreaTail(VMArea* area, size_t newSize,
uint32 allocationFlags) = 0;
virtual status_t ReserveAddressRange(void** _address,
uint32 addressSpec, size_t size,
uint32 flags) = 0;
uint32 flags, uint32 allocationFlags) = 0;
virtual status_t UnreserveAddressRange(addr_t address,
size_t size) = 0;
virtual void UnreserveAllAddressRanges() = 0;
size_t size, uint32 allocationFlags) = 0;
virtual void UnreserveAllAddressRanges(
uint32 allocationFlags) = 0;
virtual void Dump() const;
+1 -1
View File
@@ -53,7 +53,7 @@ protected:
uint32 wiring, uint32 protection);
~VMArea();
status_t Init(const char* name);
status_t Init(const char* name, uint32 allocationFlags);
protected:
friend class VMAddressSpace;
+1 -1
View File
@@ -67,7 +67,7 @@ public:
VMCache();
virtual ~VMCache();
status_t Init(uint32 cacheType);
status_t Init(uint32 cacheType, uint32 allocationFlags);
virtual void Delete();