From e367774d19501a78c0699e6458d420c57ac73567 Mon Sep 17 00:00:00 2001 From: yiwu-arbug Date: Mon, 14 Aug 2017 14:28:33 -0700 Subject: [PATCH] Overload new[] to properly align LRUCacheShard Summary: Also verify it fixes gcc7 compile failure #2672 (see also #2699) Closes https://github.com/facebook/rocksdb/pull/2732 Differential Revision: D5620348 Pulled By: yiwu-arbug fbshipit-source-id: 87db657ab734f23b1bfaaa9db9b9956d10eaef59 --- Makefile | 13 ------------- cache/lru_cache.cc | 12 ++++++++++-- cache/lru_cache.h | 4 ++++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 9b80864fc..a657fad72 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index f833374e7..a78a52dff 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -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) { diff --git a/cache/lru_cache.h b/cache/lru_cache.h index 2fd44bbce..abe78fd0c 100644 --- a/cache/lru_cache.h +++ b/cache/lru_cache.h @@ -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);