"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/include/superblocks/alignedsuperblockheap.h" between
Hoard-3.12.tar.gz and Hoard-3.13.tar.gz

About: The Hoard memory allocator is a drop-in replacement for malloc() that can improve application performance, especially for multithreaded programs running on multiprocessors (hint: newer releases now part of the HeapLayers package).

alignedsuperblockheap.h  (Hoard-3.12):alignedsuperblockheap.h  (Hoard-3.13)
// -*- C++ -*- // -*- C++ -*-
/* /*
The Hoard Multiprocessor Memory Allocator The Hoard Multiprocessor Memory Allocator
www.hoard.org www.hoard.org
Author: Emery Berger, http://www.cs.umass.edu/~emery Author: Emery Berger, http://www.emeryberger.com
Copyright (c) 1998-2012 Emery Berger Copyright (c) 1998-2018 Emery Berger
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
skipping to change at line 46 skipping to change at line 46
namespace Hoard { namespace Hoard {
template <size_t SuperblockSize, template <size_t SuperblockSize,
class TheLockType, class TheLockType,
class MmapSource> class MmapSource>
class SuperblockStore { class SuperblockStore {
public: public:
enum { Alignment = MmapSource::Alignment }; enum { Alignment = MmapSource::Alignment };
SuperblockStore() {
#if defined(__SVR4)
// We only get 64K chunks from mmap on Solaris, so we need to grab
// more chunks (and align them to 64K!) for smaller superblock sizes.
// Right now, we do not handle this case and just assert here that
// we are getting chunks of 64K.
static_assert(SuperblockSize == 65536,
"This is needed to prevent mmap fragmentation.");
#endif
}
void * malloc (size_t) { void * malloc (size_t) {
if (_freeSuperblocks.isEmpty()) { if (_freeSuperblocks.isEmpty()) {
// Get more memory. // Get more memory.
void * ptr = _superblockSource.malloc (ChunksToGrab * SuperblockSize); void * ptr = _superblockSource.malloc (ChunksToGrab * SuperblockSize);
if (!ptr) { if (!ptr) {
return NULL; return nullptr;
} }
char * p = (char *) ptr; char * p = (char *) ptr;
for (int i = 0; i < ChunksToGrab; i++) { for (int i = 0; i < ChunksToGrab; i++) {
_freeSuperblocks.insert ((DLList::Entry *) p); _freeSuperblocks.insert ((DLList::Entry *) p);
p += SuperblockSize; p += SuperblockSize;
} }
} }
return _freeSuperblocks.get(); return _freeSuperblocks.get();
} }
void free (void * ptr) { void free (void * ptr) {
_freeSuperblocks.insert ((DLList::Entry *) ptr); _freeSuperblocks.insert ((DLList::Entry *) ptr);
} }
private: private:
#if defined(__SVR4) #if defined(__SVR4)
enum { ChunksToGrab = 1 }; enum { ChunksToGrab = 1 };
// We only get 64K chunks from mmap on Solaris, so we need to grab
// more chunks (and align them to 64K!) for smaller superblock sizes.
// Right now, we do not handle this case and just assert here that
// we are getting chunks of 64K.
HL::sassert<(SuperblockSize == 65536)> PreventMmapFragmentation;
#else #else
enum { ChunksToGrab = 1 }; enum { ChunksToGrab = 1 };
#endif #endif
MmapSource _superblockSource; MmapSource _superblockSource;
DLList _freeSuperblocks; DLList _freeSuperblocks;
}; };
} }
skipping to change at line 111 skipping to change at line 115
size_t SuperblockSize> size_t SuperblockSize>
class AlignedSuperblockHeap : public AlignedMmap<SuperblockSize,TheLockType> { }; class AlignedSuperblockHeap : public AlignedMmap<SuperblockSize,TheLockType> { };
#else #else
template <class TheLockType, template <class TheLockType,
size_t SuperblockSize, size_t SuperblockSize,
class MmapSource> class MmapSource>
class AlignedSuperblockHeap : class AlignedSuperblockHeap :
public AlignedSuperblockHeapHelper<TheLockType, SuperblockSize, MmapSource> { public AlignedSuperblockHeapHelper<TheLockType, SuperblockSize, MmapSource> {
public:
HL::sassert<(AlignedSuperblockHeapHelper<TheLockType, SuperblockSize, MmapSo AlignedSuperblockHeap() {
urce>::Alignment % SuperblockSize == 0)> EnsureProperAlignment; static_assert(AlignedSuperblockHeapHelper<TheLockType, SuperblockSize, Mma
pSource>::Alignment % SuperblockSize == 0,
"Ensure proper alignment.");
}
}; };
#endif #endif
} }
#endif #endif
 End of changes. 6 change blocks. 
13 lines changed or deleted 20 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)