Skip to content

Commit

Permalink
Overload new[] to properly align LRUCacheShard
Browse files Browse the repository at this point in the history
Summary:
Also verify it fixes gcc7 compile failure facebook#2672 (see also facebook#2699)
Closes facebook#2732

Differential Revision: D5620348

Pulled By: yiwu-arbug

fbshipit-source-id: 87db657ab734f23b1bfaaa9db9b9956d10eaef59
  • Loading branch information
yiwu-arbug authored and facebook-github-bot committed Aug 14, 2017
1 parent ad42d2f commit e367774
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,6 @@ default: all
WARNING_FLAGS = -W -Wextra -Wall -Wsign-compare -Wshadow \
-Wno-unused-parameter

CCVERSION = $(shell $(CXX) -dumpversion)
CCNAME = $(shell $(CXX) --version | awk 'NR==1' | cut -f1 -d " ")

ifeq ($(CCNAME), clang)
ifeq ($(CCVERSION), 4*)
CXXFLAGS += -faligned-new
endif
else
ifeq ($(CCVERSION), 7)
CXXFLAGS += -faligned-new
endif
endif

ifndef DISABLE_WARNING_AS_ERROR
WARNING_FLAGS += -Werror
endif
Expand Down
12 changes: 10 additions & 2 deletions cache/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,19 @@ void LRUCacheShard::EvictFromLRU(size_t charge,
}

void* LRUCacheShard::operator new(size_t size) {
return rocksdb::port::cacheline_aligned_alloc(size);
return port::cacheline_aligned_alloc(size);
}

void* LRUCacheShard::operator new[](size_t size) {
return port::cacheline_aligned_alloc(size);
}

void LRUCacheShard::operator delete(void *memblock) {
rocksdb::port::cacheline_aligned_free(memblock);
port::cacheline_aligned_free(memblock);
}

void LRUCacheShard::operator delete[](void* memblock) {
port::cacheline_aligned_free(memblock);
}

void LRUCacheShard::SetCapacity(size_t capacity) {
Expand Down
4 changes: 4 additions & 0 deletions cache/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShard : public CacheShard {
// Overloading to aligned it to cache line size
void* operator new(size_t);

void* operator new[](size_t);

void operator delete(void *);

void operator delete[](void*);

private:
void LRU_Remove(LRUHandle* e);
void LRU_Insert(LRUHandle* e);
Expand Down

0 comments on commit e367774

Please sign in to comment.