haikuwebkit/Source/bmalloc/bmalloc/IsoSharedPage.cpp

44 lines
1.6 KiB
C++
Raw Permalink Normal View History

[bmalloc] IsoHeap should have lower tier using shared IsoPage https://bugs.webkit.org/show_bug.cgi?id=196837 Reviewed by Filip Pizlo. IsoHeap had a scalability problem. Once one instance is allocated from IsoHeap, it immediately allocates 16KB page for this type. But some types allocate only a few instances. It leads to memory wastage, and it also limits the scalability of IsoHeap since we need to carefully select classes which will be confined in IsoHeap due to this characteristics. If we can remove this wastage, we can apply IsoHeap more aggressively without causing memory regression, this is the goal of this patch. In this patch, we introduce a slow tier to IsoHeap allocation. Initially, the allocator for a certain type allocates instances from a shared page with the other allocators, and eventually, the allocator tiers up and gets dedicated pages if instances of the type are allocated a lot. This "shared" tier is slow, but it is totally OK because we will tier up to the normal fast tier if allocation frequently happens. Even the instance is allocated from pages shared with the other allocators, we still make the allocated memory region dedicated to the specific type: once a memory region is allocated for a certain type from a shared page, this region continues being used only for this type even after this memory is freed. To summarize the changes: 1. We introduce "shared" tier to IsoHeap allocation. Up to N (N = 8 for now, but we can pick any power-of-two numbers up to 32) allocations, we continue using this tier. We allocate memory from shared pages so that we do not waste 16KB pages for types which only allocates a few instances. 2. We eventually tier up to the "fast" tier, and eventually tier down to the "shared" tier too. We measure the period between slow paths, and switch the appropriate tier for the type. Currently, we use 1 seconds as heuristics. We also count # of allocations per cycle to avoid pathological slow downs. 3. Shared page mechanism must keep the characteristics of IsoHeap. Once a memory region is allocated for a certain type, this memory region must be dedicated to this type. We keep track the allocated memory regions from shared pages in IsoHeapImpl, and ensure that we never reuse a memory region for a different type. This patch improves PLUM2 by 1.4% (128.4MB v.s. 126.62MB), and early Speedometer2 results are performance-neutral. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOfImpl): (bmalloc::roundUpToMultipleOf): * bmalloc/BCompiler.h: * bmalloc/BExport.h: * bmalloc/FreeList.h: * bmalloc/IsoAllocator.h: * bmalloc/IsoAllocatorInlines.h: (bmalloc::IsoAllocator<Config>::allocateSlow): * bmalloc/IsoDeallocator.h: * bmalloc/IsoDeallocatorInlines.h: (bmalloc::IsoDeallocator<Config>::deallocate): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): (bmalloc::IsoHeapImpl<Config>::updateAllocationMode): (bmalloc::IsoHeapImpl<Config>::allocateFromShared): * bmalloc/IsoPage.h: (bmalloc::IsoPageBase::IsoPageBase): (bmalloc::IsoPageBase::isShared const): * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::IsoPage): (bmalloc::IsoPageBase::pageFor): (bmalloc::IsoPage<Config>::pageFor): (bmalloc::IsoPage<Config>::free): * bmalloc/IsoSharedConfig.h: Copied from Source/bmalloc/bmalloc/BExport.h. * bmalloc/IsoSharedHeap.cpp: Copied from Source/bmalloc/bmalloc/BExport.h. * bmalloc/IsoSharedHeap.h: Copied from Source/bmalloc/bmalloc/IsoAllocator.h. (bmalloc::VariadicBumpAllocator::VariadicBumpAllocator): (bmalloc::IsoSharedHeap::IsoSharedHeap): * bmalloc/IsoSharedHeapInlines.h: Added. (bmalloc::VariadicBumpAllocator::allocate): (bmalloc::IsoSharedHeap::allocateNew): (bmalloc::IsoSharedHeap::allocateSlow): * bmalloc/IsoSharedPage.cpp: Copied from Source/bmalloc/bmalloc/BExport.h. (bmalloc::IsoSharedPage::tryCreate): * bmalloc/IsoSharedPage.h: Copied from Source/bmalloc/bmalloc/IsoDeallocator.h. (bmalloc::IsoSharedPage::IsoSharedPage): (bmalloc::indexSlotFor): * bmalloc/IsoSharedPageInlines.h: Added. (bmalloc::IsoSharedPage::free): (bmalloc::IsoSharedPage::startAllocating): (bmalloc::IsoSharedPage::stopAllocating): * bmalloc/IsoTLS.h: * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::deallocateImpl): (bmalloc::IsoTLS::deallocateFast): (bmalloc::IsoTLS::deallocateSlow): * bmalloc/StdLibExtras.h: (bmalloc::bitwise_cast): * test/testbmalloc.cpp: (testIsoMallocAndFreeFast): (run): Canonical link: https://commits.webkit.org/211356@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244481 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-04-20 03:29:40 +00:00
/*
* Copyright (C) 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "IsoSharedPage.h"
#include "StdLibExtras.h"
#include "VMAllocate.h"
namespace bmalloc {
IsoSharedPage* IsoSharedPage::tryCreate()
{
void* memory = allocatePageMemory();
if (!memory)
return nullptr;
return new (memory) IsoSharedPage();
}
} // namespace bmalloc