Use the empty_index field as the allocation_id for large allocations and just

use the index of the first page of the allocation as an id. This removes the
need for separate id generation. This also fixes the possible problem of
multiple large allocations getting the same allocation_id (due to the limited
range of possible ids), which in the worst case (i.e. for adjacent allocations)
could cause pages to be freed that were still in use.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2008-03-15 17:35:34 +00:00
parent fe8b72bc69
commit f4af1fba51
+2 -11
View File
@@ -59,7 +59,7 @@ typedef struct heap_page_s {
} heap_page;
// used for bin == bin_count allocations
#define allocation_id free_count
#define allocation_id empty_index
typedef struct heap_bin_s {
uint32 element_size;
@@ -71,7 +71,6 @@ typedef struct heap_allocator_s {
addr_t base;
size_t size;
mutex lock;
vint32 large_alloc_id;
uint32 bin_count;
uint32 page_count;
@@ -536,13 +535,6 @@ heap_attach(addr_t base, size_t size, bool postSem)
}
static inline uint32
heap_next_alloc_id(heap_allocator *heap)
{
return atomic_add(&heap->large_alloc_id, 1) & ((1 << 9) - 1);
}
static inline void
heap_link_page(heap_page *page, heap_page **list)
{
@@ -672,7 +664,6 @@ heap_raw_alloc(heap_allocator *heap, size_t size, uint32 binIndex)
return NULL;
}
uint32 allocationID = heap_next_alloc_id(heap);
uint32 pageCount = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
for (uint32 i = first; i < first + pageCount; i++) {
heap_page *page = &heap->page_table[i];
@@ -683,7 +674,7 @@ heap_raw_alloc(heap_allocator *heap, size_t size, uint32 binIndex)
page->next = page->prev = NULL;
page->free_list = NULL;
page->allocation_id = allocationID;
page->allocation_id = (uint16)first;
}
#if KERNEL_HEAP_LEAK_CHECK