Optimized freeing client memory if it spans the whole area.

* If a block of client memory spans the whole chunk, there is no need to walk
  the free list for adjacent blocks to join.
* Minor cleanup.
This commit is contained in:
Axel Dörfler
2012-04-28 23:35:17 +02:00
parent 03b82a629d
commit 6068e43923
+16 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved. * Copyright 2006-2012, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -19,15 +19,18 @@
area might be temporarily unavailable or might be relocated at any time. area might be temporarily unavailable or might be relocated at any time.
*/ */
// TODO: right now, areas will always stay static until they are deleted; // TODO: right now, areas will always stay static until they are deleted;
// locking is not yet done or enforced! // locking is not yet done or enforced!
#include "ClientMemoryAllocator.h" #include "ClientMemoryAllocator.h"
#include "ServerApp.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ServerApp.h"
typedef block_list::Iterator block_iterator; typedef block_list::Iterator block_iterator;
typedef chunk_list::Iterator chunk_iterator; typedef chunk_list::Iterator chunk_iterator;
@@ -126,7 +129,9 @@ ClientMemoryAllocator::Free(block* freeBlock)
block_iterator iterator = fFreeBlocks.GetIterator(); block_iterator iterator = fFreeBlocks.GetIterator();
struct block* before = NULL; struct block* before = NULL;
struct block* after = NULL; struct block* after = NULL;
bool inFreeList = true;
if (freeBlock->size != freeBlock->chunk->size) {
// TODO: this could be done better if free blocks are sorted, // TODO: this could be done better if free blocks are sorted,
// and if we had one free blocks list per chunk! // and if we had one free blocks list per chunk!
// IOW this is a bit slow... // IOW this is a bit slow...
@@ -160,11 +165,14 @@ ClientMemoryAllocator::Free(block* freeBlock)
freeBlock = after; freeBlock = after;
} else } else
fFreeBlocks.Add(freeBlock); fFreeBlocks.Add(freeBlock);
} else
inFreeList = false;
if (freeBlock->size == freeBlock->chunk->size) { if (freeBlock->size == freeBlock->chunk->size) {
// We can delete the chunk now // We can delete the chunk now
struct chunk* chunk = freeBlock->chunk; struct chunk* chunk = freeBlock->chunk;
if (inFreeList)
fFreeBlocks.Remove(freeBlock); fFreeBlocks.Remove(freeBlock);
free(freeBlock); free(freeBlock);
@@ -284,6 +292,9 @@ ClientMemoryAllocator::_AllocateChunk(size_t size, bool& newArea)
} }
// #pragma mark -
ClientMemory::ClientMemory() ClientMemory::ClientMemory()
: :
fBlock(NULL) fBlock(NULL)
@@ -334,6 +345,9 @@ ClientMemory::AreaOffset()
} }
// #pragma mark -
ClonedAreaMemory::ClonedAreaMemory() ClonedAreaMemory::ClonedAreaMemory()
: :
fClonedArea(-1), fClonedArea(-1),