Skip to content

Commit 398a0fe

Browse files
committed
Release 1.0. Fixing one small issue that allocates small objects in block-wise way
1 parent fdc025c commit 398a0fe

1 file changed

Lines changed: 9 additions & 65 deletions

File tree

source/mainheap.hh

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -37,70 +37,6 @@
3737
*/
3838

3939
class MainHeap {
40-
#if 0
41-
class MainThreadSizeClass {
42-
private:
43-
unsigned int _csize;
44-
unsigned int _sc;
45-
unsigned int _pages;
46-
unsigned int _nodeIndex;
47-
char * _bumpPointer;
48-
char * _bumpPointerEnd;
49-
PerSizeClassList _list;
50-
51-
public:
52-
53-
void initialize(unsigned int sc, unsigned int classsize, unsigned int nodeindex) {
54-
_sc = sc;
55-
_csize = classsize;
56-
_nodeIndex = nodeindex;
57-
_pages = classsize >> PAGE_SIZE_SHIFT;
58-
_bumpPointer = NULL;
59-
_bumpPointerEnd = NULL;
60-
_list.initialize();
61-
}
62-
63-
bool hasObject() {
64-
return ((_list.length() > 0) || (_bumpPointer < _bumpPointerEnd));
65-
}
66-
67-
// The current object will be pushed with a new block of memory
68-
void updateBumpPointer(char * start, size_t size) {
69-
_bumpPointer = start;
70-
_bumpPointerEnd = start + size;
71-
}
72-
73-
unsigned int getClassSize() {
74-
return _csize;
75-
}
76-
77-
void * allocate(void) {
78-
void * ptr = NULL;
79-
80-
// Allocate from the freelist first.
81-
if(_list.hasItems()) {
82-
ptr = _list.pop();
83-
}
84-
else {
85-
// Allocate from the bump pointer right now.
86-
ptr = _bumpPointer;
87-
_bumpPointer += _csize;
88-
89-
if(_csize > (PAGE_SIZE * NUMA_NODES/2)) {
90-
// Notify the OS to allocate physical memory in the block-wise way
91-
MM::bindMemoryBlockwise((char *)ptr, _pages, _nodeIndex);
92-
}
93-
}
94-
95-
return ptr;
96-
}
97-
98-
void deallocate(void * ptr) {
99-
_list.push(ptr);
100-
}
101-
};
102-
103-
#endif
10440
private:
10541
char * _begin;
10642
char * _end;
@@ -342,14 +278,15 @@ class MainHeap {
342278

343279
int numb = 0;
344280
void * head = NULL;
281+
size_t classSize = sc->getClassSize();
345282
if(sc->hasItems() != true) {
346283
void * tail = NULL;
347284

348285
// Get objects from the bump pointer (with the cache warmup mechanism)
349286
numb = sc->getObjectsFromBumpPointer(&head, &tail);
350287
if(numb == 0) {
351288
// Get objects from the bumppointer
352-
void * bPtr = allocateOneBag(sc->getBagSize(), sc->getClassSize());
289+
void * bPtr = allocateOneBag(sc->getBagSize(), classSize);
353290

354291
// Update the bumppointer
355292
numb = sc->updateBumpPointerAndGetObjects(bPtr, &head, &tail);
@@ -367,6 +304,13 @@ class MainHeap {
367304
void * ptr = NULL;
368305
if(numb == 1) {
369306
ptr = head;
307+
// Check size. If possible, we will bind the memory in the block-wise.
308+
if(classSize > (PAGE_SIZE * NUMA_NODES/2)) {
309+
size_t pages = classSize >> PAGE_SIZE_SHIFT;
310+
311+
// Notify the OS to allocate physical memory in the block-wise way
312+
MM::bindMemoryBlockwise((char *)ptr, pages, _nodeIndex);
313+
}
370314
}
371315
else {
372316
ptr = sc->allocateFromFreeList();

0 commit comments

Comments
 (0)