From 8c5a0accf5d61de8e2beb7d079d022c56ed0a3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 24 Jun 2011 17:04:50 +0000 Subject: [PATCH] * Do not reserve memory when the area is too large. This fixes #7740 where the reserved amount was simply too small, but also works around address space waste with many larger bitmaps. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42298 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/app/ServerMemoryAllocator.h | 4 ++-- src/kits/app/ServerMemoryAllocator.cpp | 14 ++++++++++---- src/kits/interface/Bitmap.cpp | 8 +++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/headers/private/app/ServerMemoryAllocator.h b/headers/private/app/ServerMemoryAllocator.h index 08e053bdcb..3d83d75154 100644 --- a/headers/private/app/ServerMemoryAllocator.h +++ b/headers/private/app/ServerMemoryAllocator.h @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2011, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -22,7 +22,7 @@ class ServerMemoryAllocator { status_t InitCheck(); status_t AddArea(area_id serverArea, area_id& _localArea, uint8*& _base, - bool readOnly = false); + size_t size, bool readOnly = false); void RemoveArea(area_id serverArea); status_t AreaAndBaseFor(area_id serverArea, area_id& area, uint8*& base); diff --git a/src/kits/app/ServerMemoryAllocator.cpp b/src/kits/app/ServerMemoryAllocator.cpp index 31e4961d20..2518b54ab8 100644 --- a/src/kits/app/ServerMemoryAllocator.cpp +++ b/src/kits/app/ServerMemoryAllocator.cpp @@ -24,6 +24,10 @@ #endif +static const size_t kReservedSize = 128 * 1024 * 1024; +static const size_t kReserveMaxSize = 32 * 1024 * 1024; + + namespace BPrivate { @@ -61,7 +65,7 @@ ServerMemoryAllocator::InitCheck() status_t ServerMemoryAllocator::AddArea(area_id serverArea, area_id& _area, - uint8*& _base, bool readOnly) + uint8*& _base, size_t size, bool readOnly) { area_mapping* mapping = new (std::nothrow) area_mapping; if (mapping == NULL || !fAreas.AddItem(mapping)) { @@ -73,11 +77,13 @@ ServerMemoryAllocator::AddArea(area_id serverArea, area_id& _area, uint32 addressSpec = B_ANY_ADDRESS; void* base; #ifndef HAIKU_TARGET_PLATFORM_LIBBE_TEST - if (!readOnly) { - // reserve 128 MB of space for the area + if (!readOnly && size < kReserveMaxSize) { + // Reserve 128 MB of space for the area, but only if the area + // is smaller than 32 MB (else the address space waste would + // likely to be too large) base = (void*)0x60000000; status = _kern_reserve_address_range((addr_t*)&base, B_BASE_ADDRESS, - 128 * 1024 * 1024); + kReservedSize); addressSpec = status == B_OK ? B_EXACT_ADDRESS : B_BASE_ADDRESS; } #endif diff --git a/src/kits/interface/Bitmap.cpp b/src/kits/interface/Bitmap.cpp index f46084b6c4..ed56794560 100644 --- a/src/kits/interface/Bitmap.cpp +++ b/src/kits/interface/Bitmap.cpp @@ -1008,12 +1008,10 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags, } // allocate the bitmap buffer if (error == B_OK) { - // NOTE: Maybe the code would look more robust if the - // "size" was not calculated here when we ask the server - // to allocate the bitmap. -Stephan + // TODO: Let the app_server return the size when it allocated the bitmap int32 size = bytesPerRow * (bounds.IntegerHeight() + 1); - if (flags & B_BITMAP_NO_SERVER_LINK) { + if ((flags & B_BITMAP_NO_SERVER_LINK) != 0) { fBasePointer = (uint8*)malloc(size); if (fBasePointer) { fSize = size; @@ -1055,7 +1053,7 @@ BBitmap::_InitObject(BRect bounds, color_space colorSpace, uint32 flags, if (allocationFlags & kNewAllocatorArea) { error = allocator->AddArea(fServerArea, fArea, - fBasePointer); + fBasePointer, size); } else { error = allocator->AreaAndBaseFor(fServerArea, fArea, fBasePointer);