[haiku-commits] haiku: hrev44077 - src/servers/app

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 28 Apr 2012 23:35:38 +0200 (CEST)

hrev44077 adds 1 changeset to branch 'master'
old head: 03b82a629d6358fc6c4ad3b5bb45793fd028a0f2
new head: 6068e439237ee80ed675fb1deb255de6cb252a6f

----------------------------------------------------------------------------

6068e43: 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.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44077
Commit:      6068e439237ee80ed675fb1deb255de6cb252a6f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6068e43
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Sat Apr 28 21:32:02 2012 UTC

----------------------------------------------------------------------------

1 file changed, 46 insertions(+), 32 deletions(-)
src/servers/app/ClientMemoryAllocator.cpp |   78 +++++++++++++++----------

----------------------------------------------------------------------------

diff --git a/src/servers/app/ClientMemoryAllocator.cpp 
b/src/servers/app/ClientMemoryAllocator.cpp
index e7ff90a..99e6c86 100644
--- a/src/servers/app/ClientMemoryAllocator.cpp
+++ b/src/servers/app/ClientMemoryAllocator.cpp
@@ -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.
  *
  * Authors:
@@ -19,15 +19,18 @@
        area might be temporarily unavailable or might be relocated at any time.
 */
 
+
 //     TODO: right now, areas will always stay static until they are deleted;
 //             locking is not yet done or enforced!
 
+
 #include "ClientMemoryAllocator.h"
-#include "ServerApp.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "ServerApp.h"
+
 
 typedef block_list::Iterator block_iterator;
 typedef chunk_list::Iterator chunk_iterator;
@@ -126,46 +129,51 @@ ClientMemoryAllocator::Free(block* freeBlock)
        block_iterator iterator = fFreeBlocks.GetIterator();
        struct block* before = NULL;
        struct block* after = NULL;
+       bool inFreeList = true;
 
-       // TODO: this could be done better if free blocks are sorted,
-       //      and if we had one free blocks list per chunk!
-       //      IOW this is a bit slow...
+       if (freeBlock->size != freeBlock->chunk->size) {
+               // TODO: this could be done better if free blocks are sorted,
+               //      and if we had one free blocks list per chunk!
+               //      IOW this is a bit slow...
 
-       while (struct block* block = iterator.Next()) {
-               if (block->chunk != freeBlock->chunk)
-                       continue;
+               while (struct block* block = iterator.Next()) {
+                       if (block->chunk != freeBlock->chunk)
+                               continue;
 
-               if (block->base + block->size == freeBlock->base)
-                       before = block;
+                       if (block->base + block->size == freeBlock->base)
+                               before = block;
 
-               if (block->base == freeBlock->base + freeBlock->size)
-                       after = block;
-       }
+                       if (block->base == freeBlock->base + freeBlock->size)
+                               after = block;
+               }
 
-       if (before != NULL && after != NULL) {
-               // merge with adjacent blocks
-               before->size += after->size + freeBlock->size;
-               fFreeBlocks.Remove(after);
-               free(after);
-               free(freeBlock);
-               freeBlock = before;
-       } else if (before != NULL) {
-               before->size += freeBlock->size;
-               free(freeBlock);
-               freeBlock = before;
-       } else if (after != NULL) {
-               after->base -= freeBlock->size;
-               after->size += freeBlock->size;
-               free(freeBlock);
-               freeBlock = after;
+               if (before != NULL && after != NULL) {
+                       // merge with adjacent blocks
+                       before->size += after->size + freeBlock->size;
+                       fFreeBlocks.Remove(after);
+                       free(after);
+                       free(freeBlock);
+                       freeBlock = before;
+               } else if (before != NULL) {
+                       before->size += freeBlock->size;
+                       free(freeBlock);
+                       freeBlock = before;
+               } else if (after != NULL) {
+                       after->base -= freeBlock->size;
+                       after->size += freeBlock->size;
+                       free(freeBlock);
+                       freeBlock = after;
+               } else
+                       fFreeBlocks.Add(freeBlock);
        } else
-               fFreeBlocks.Add(freeBlock);
+               inFreeList = false;
 
        if (freeBlock->size == freeBlock->chunk->size) {
                // We can delete the chunk now
                struct chunk* chunk = freeBlock->chunk;
 
-               fFreeBlocks.Remove(freeBlock);
+               if (inFreeList)
+                       fFreeBlocks.Remove(freeBlock);
                free(freeBlock);
 
                fChunks.Remove(chunk);
@@ -284,6 +292,9 @@ ClientMemoryAllocator::_AllocateChunk(size_t size, bool& 
newArea)
 }
 
 
+// #pragma mark -
+
+
 ClientMemory::ClientMemory()
        :
        fBlock(NULL)
@@ -303,7 +314,7 @@ ClientMemory::Allocate(ClientMemoryAllocator* allocator, 
size_t size,
        bool& newArea)
 {
        fAllocator = allocator;
-       return fAllocator->Allocate(size, &fBlock, newArea); 
+       return fAllocator->Allocate(size, &fBlock, newArea);
 }
 
 
@@ -334,6 +345,9 @@ ClientMemory::AreaOffset()
 }
 
 
+// #pragma mark -
+
+
 ClonedAreaMemory::ClonedAreaMemory()
        :
        fClonedArea(-1),


Other related posts:

  • » [haiku-commits] haiku: hrev44077 - src/servers/app - axeld