├── hoard ├── heaplayers │ ├── TODO │ ├── threads │ │ ├── all.h │ │ └── fred.h │ ├── utility │ │ ├── a.out │ │ ├── bins.h │ │ ├── lcm.h │ │ ├── gcd.h │ │ ├── testalign.cpp │ │ ├── all.h │ │ ├── align.h │ │ ├── sassert.h │ │ ├── hash.h │ │ ├── istrue.h │ │ ├── freesllist.h │ │ ├── guard.h │ │ └── bins4k.h │ ├── heaps │ │ ├── general │ │ │ ├── all.h │ │ │ └── leamallocheap.h │ │ ├── top │ │ │ ├── all.h │ │ │ ├── sbrkheap.h │ │ │ └── staticheap.h │ │ ├── combining │ │ │ ├── all.h │ │ │ └── tryheap.h │ │ ├── objectrep │ │ │ ├── all.h │ │ │ └── addheap.h │ │ ├── debug │ │ │ ├── all.h │ │ │ ├── debugheap.h │ │ │ └── checkheap.h │ │ ├── buildingblock │ │ │ ├── all.h │ │ │ └── boundedfreelistheap.h │ │ ├── threads │ │ │ ├── all.h │ │ │ ├── sizethreadheap.h │ │ │ └── lockedheap.h │ │ ├── utility │ │ │ ├── all.h │ │ │ ├── nullheap.h │ │ │ ├── exceptionheap.h │ │ │ └── oneheap.h │ │ ├── all.h │ │ └── README │ ├── wrappers │ │ ├── all.h │ │ ├── gnuwrapper.h │ │ └── macinterpose.h │ ├── arch-specific │ │ ├── x86_64-interchange.il │ │ ├── sparc-interchange.il │ │ ├── x86-interchange.il │ │ └── mallocinfo.h │ └── locks │ │ ├── maclock.h │ │ └── posixlock.h ├── include │ ├── hoard │ │ ├── README │ │ ├── hash_maps.h │ │ ├── hoardconstants.h │ │ ├── statistics.h │ │ └── emptyhoardmanager.h │ ├── README │ ├── VERSION.h │ └── util │ │ ├── conformantheap.h │ │ ├── array.h │ │ ├── lockmallocheap.h │ │ ├── fixedrequestheap.h │ │ ├── mmapalloc.h │ │ ├── exactlyoneheap.h │ │ ├── exactlyone.h │ │ ├── releaseheap.h │ │ └── check.h ├── compile_install_hoard.sh ├── test │ └── testoverflow.cpp ├── source │ ├── hash_maps.h │ └── uselibhoard.cpp └── README ├── scripts ├── graph.pyc ├── install_cmake.sh ├── flushcache.sh ├── mount_dax.sh ├── mount_nova.sh ├── mount_ramdisk.sh ├── setup_vanilla_leveldb.sh ├── setvars.sh ├── run_vanilla_leveldb.sh ├── linuxperf.sh ├── run_dbbench.sh ├── run_cachekv_dbbench.sh └── run_read_parallel.sh ├── leveldb-1.20 ├── .gitignore ├── .travis.yml ├── AUTHORS ├── util │ ├── filter_policy.cc │ ├── hash.h │ ├── options.cc │ ├── env_posix_test_helper.h │ ├── histogram.h │ ├── mutexlock.h │ ├── hash.cc │ ├── logging.h │ ├── crc32c.h │ ├── testutil.cc │ ├── hash_test.cc │ ├── arena_test.cc │ ├── testharness.cc │ ├── logging.cc │ ├── crc32c_test.cc │ └── arena.h ├── port │ ├── README │ ├── port.h │ ├── win │ │ └── stdint.h │ ├── thread_annotations.h │ └── port_posix.cc ├── NEWS ├── TODO ├── helpers │ └── memenv │ │ └── memenv.h ├── db │ ├── db_iter.h │ ├── log_format.h │ ├── builder.h │ ├── version_edit_test.cc │ ├── log_writer.h │ ├── write_batch_internal.h │ ├── leveldbutil.cc │ └── snapshot.h ├── table │ ├── merger.h │ ├── block.h │ ├── two_level_iterator.h │ ├── iterator.cc │ └── block_builder.h ├── include │ └── leveldb │ │ ├── dumpfile.h │ │ └── write_batch.h ├── LICENSE ├── CONTRIBUTING.md └── issues │ └── issue200_test.cc ├── util ├── cpumap.h ├── debug.h ├── defs.h ├── filter_policy.cc ├── bitops.h ├── BloomFilter.h ├── hash.h ├── debug.cc ├── MurmurHash3.h ├── lsm_mutex.h ├── options.cc ├── histogram.h ├── mutexlock.h ├── BloomFilter.cc ├── hash.cc ├── logging.h ├── crc32c.h ├── testutil.cc ├── affinity.h ├── hash_test.cc ├── arena_test.cc ├── testharness.cc ├── logging.cc └── crc32c_test.cc ├── AUTHORS ├── port ├── README ├── port.h ├── win │ └── stdint.h ├── cache_flush.h ├── thread_annotations.h └── port_posix.cc ├── NEWS ├── TODO ├── helpers └── memenv │ └── memenv.h ├── db ├── db_iter.h ├── log_format.h ├── builder.h ├── version_edit_test.cc ├── log_writer.h ├── write_batch_internal.h ├── leveldbutil.cc └── snapshot.h ├── table ├── merger.h ├── block.h ├── two_level_iterator.h ├── iterator.cc └── block_builder.h ├── include └── leveldb │ ├── dumpfile.h │ └── write_batch.h ├── README.md ├── doc └── doc.css ├── LICENSE ├── CONTRIBUTING.md └── issues └── issue200_test.cc /hoard/heaplayers/TODO: -------------------------------------------------------------------------------- 1 | - Make MyHashMap dynamic. 2 | -------------------------------------------------------------------------------- /hoard/heaplayers/threads/all.h: -------------------------------------------------------------------------------- 1 | #include "cpuinfo.h" 2 | #include "fred.h" 3 | -------------------------------------------------------------------------------- /scripts/graph.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shenzr/CacheKV-code/HEAD/scripts/graph.pyc -------------------------------------------------------------------------------- /hoard/include/hoard/README: -------------------------------------------------------------------------------- 1 | This directory contains Hoard-specific heap layers and helpers. 2 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shenzr/CacheKV-code/HEAD/hoard/heaplayers/utility/a.out -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/general/all.h: -------------------------------------------------------------------------------- 1 | #include "dlheap.h" 2 | #include "kingsleyheap.h" 3 | #include "leamallocheap.h" 4 | 5 | -------------------------------------------------------------------------------- /leveldb-1.20/.gitignore: -------------------------------------------------------------------------------- 1 | build_config.mk 2 | *.a 3 | *.o 4 | *.dylib* 5 | *.so 6 | *.so.* 7 | *_test 8 | db_bench 9 | leveldbutil 10 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/top/all.h: -------------------------------------------------------------------------------- 1 | #include "mallocheap.h" 2 | #include "mmapheap.h" 3 | #include "sbrkheap.h" 4 | #include "staticheap.h" 5 | 6 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/combining/all.h: -------------------------------------------------------------------------------- 1 | #include "hybridheap.h" 2 | #include "segheap.h" 3 | #include "strictsegheap.h" 4 | #include "tryheap.h" 5 | 6 | -------------------------------------------------------------------------------- /hoard/heaplayers/wrappers/all.h: -------------------------------------------------------------------------------- 1 | #include "ansiwrapper.h" 2 | #include "macinterpose.h" 3 | #include "mmapwrapper.h" 4 | #include "stlallocator.h" 5 | -------------------------------------------------------------------------------- /hoard/heaplayers/arch-specific/x86_64-interchange.il: -------------------------------------------------------------------------------- 1 | .inline MyInterlockedExchange,0 2 | 3 | movq %rsi,%rax 4 | lock 5 | xchgq %rax,(%rdi) 6 | 7 | .end 8 | -------------------------------------------------------------------------------- /hoard/heaplayers/arch-specific/sparc-interchange.il: -------------------------------------------------------------------------------- 1 | .inline MyInterlockedExchange,8 2 | 3 | mov %o0,%o2 4 | mov %o1,%o0 5 | swap [%o2],%o0 6 | 7 | .end 8 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/objectrep/all.h: -------------------------------------------------------------------------------- 1 | #include "addheap.h" 2 | #include "coalesceableheap.h" 3 | #include "sizeheap.h" 4 | #include "sizeownerheap.h" 5 | 6 | 7 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/debug/all.h: -------------------------------------------------------------------------------- 1 | #include "checkheap.h" 2 | #include "debugheap.h" 3 | #include "logheap.h" 4 | #include "sanitycheckheap.h" 5 | #include "statsheap.h" 6 | 7 | -------------------------------------------------------------------------------- /scripts/install_cmake.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git clone https://github.com/Kitware/CMake.git 3 | cd CMake 4 | ./configure 5 | make -j16 6 | sudo make install 7 | cd $NOVELSMSRC 8 | -------------------------------------------------------------------------------- /hoard/heaplayers/arch-specific/x86-interchange.il: -------------------------------------------------------------------------------- 1 | .inline MyInterlockedExchange,0 2 | 3 | movl (%esp),%ecx 4 | movl 4(%esp),%eax 5 | lock 6 | xchgl %eax,(%ecx) 7 | 8 | .end 9 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/buildingblock/all.h: -------------------------------------------------------------------------------- 1 | #include "adaptheap.h" 2 | #include "boundedfreelistheap.h" 3 | #include "chunkheap.h" 4 | #include "coalesceheap.h" 5 | #include "freelistheap.h" 6 | 7 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/threads/all.h: -------------------------------------------------------------------------------- 1 | #include "lockedheap.h" 2 | #include "phothreadheap.h" 3 | #include "threadheap.h" 4 | #include "threadspecificheap.h" 5 | #include "sizethreadheap.h" 6 | 7 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/bins.h: -------------------------------------------------------------------------------- 1 | #ifndef HL_BINS_H 2 | #define HL_BINS_H 3 | 4 | namespace HL { 5 | 6 | template 7 | class bins; 8 | 9 | } 10 | 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /leveldb-1.20/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | compiler: 3 | - clang 4 | - gcc 5 | os: 6 | - linux 7 | - osx 8 | sudo: false 9 | before_install: 10 | - echo $LANG 11 | - echo $LC_ALL 12 | script: 13 | - make -j 4 check 14 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/lcm.h: -------------------------------------------------------------------------------- 1 | #ifndef LCM_H 2 | #define LCM_H 3 | 4 | #include "gcd.h" 5 | 6 | template struct lcm 7 | { 8 | static const int value = (a * b) / (gcd::value); 9 | }; 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /hoard/include/README: -------------------------------------------------------------------------------- 1 | Directory structure: 2 | 3 | hoard/ - files specific to Hoard 4 | superblocks/ - files that perform superblock management 5 | util/ - generic files, candidates for inclusion in Heap Layers 6 | 7 | -------------------------------------------------------------------------------- /hoard/compile_install_hoard.sh: -------------------------------------------------------------------------------- 1 | #compile and install hoard 2 | 3 | make clean 4 | make linux-gcc-x86-64 5 | sudo cp libhoard.so /usr/lib/ 6 | #sudo cp libhoard.so /usr/lib64/ 7 | sudo cp heaplayers/wrappers/gnuwrapper.h /usr/include/gnuwrapper.h 8 | -------------------------------------------------------------------------------- /scripts/flushcache.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" 3 | sudo sh -c "sync" 4 | sudo sh -c "sync" 5 | sudo sh -c "echo 3 > /proc/sys/vm/drop_caches" 6 | 7 | rm -rf /mnt/pmemdir/chk* 8 | rm -rf /mnt/pmemdir/dbbench/* 9 | -------------------------------------------------------------------------------- /scripts/mount_dax.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | #script to create and mount a pmemdir 3 | #requires size as input 4 | sudo umount $TEST_TMPDIR 5 | sudo mkdir $TEST_TMPDIR 6 | sudo mkfs.ext4 /dev/pmem0 7 | sudo mount dax /dev/pmem0 $TEST_TMPDIR 8 | sudo chown -R $USER $TEST_TMPDIR 9 | -------------------------------------------------------------------------------- /scripts/mount_nova.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | #script to create and mount a pmemdir 3 | #requires size as input 4 | sudo umount $TEST_TMPDIR 5 | sudo mkdir $TEST_TMPDIR 6 | sudo modprobe nova 7 | sudo mount -t NOVA -o init /dev/pmem0 $TEST_TMPDIR 8 | sudo chown -R $USER $TEST_TMPDIR 9 | -------------------------------------------------------------------------------- /util/cpumap.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int print_numa(void); 4 | int get_numa_count(void); 5 | int get_node_cpus(int node); 6 | int get_num_cpus(); 7 | int* get_used_cpu_map(); 8 | int* get_ftlcpu_map(); 9 | int fill_cpumap_info(void); 10 | int get_free_core(void); 11 | -------------------------------------------------------------------------------- /util/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: Apr 7, 2017 5 | * Author: skannan 6 | */ 7 | 8 | #ifndef DEBUG_H_ 9 | #define DEBUG_H_ 10 | 11 | void DEBUG(const char* format, ... ); 12 | void DEBUG_T(const char* format, ... ); 13 | 14 | #endif /* DEBUG_H_ */ 15 | -------------------------------------------------------------------------------- /util/defs.h: -------------------------------------------------------------------------------- 1 | #ifndef FTL_DEFS_H 2 | #define FTL_DEFS_H 3 | 4 | #define KB (1024ull) 5 | #define MB (1024ull * KB) 6 | #define GB (1024ull * MB) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #endif //FTL_DEFS_H 14 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/gcd.h: -------------------------------------------------------------------------------- 1 | #ifndef GCD_H 2 | #define GCD_H 3 | 4 | template struct gcd 5 | { 6 | static const int value = gcd::value; 7 | }; 8 | 9 | template struct gcd 10 | { 11 | static const int value = a; 12 | }; 13 | 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/utility/all.h: -------------------------------------------------------------------------------- 1 | #include "exceptionheap.h" 2 | #include "nullheap.h" 3 | #include "perclassheap.h" 4 | #include "slopheap.h" 5 | #include "uniqueheap.h" 6 | #include "localmallocheap.h" 7 | #include "oneheap.h" 8 | #include "profileheap.h" 9 | #include "traceheap.h" 10 | 11 | 12 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/testalign.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | #include "align.h" 6 | 7 | int 8 | main(int argc, char * argv[]) 9 | { 10 | for (int i = 0; i < 100; i++) { 11 | cout << i << "\t" << HL::align<4>(i) << endl; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/all.h: -------------------------------------------------------------------------------- 1 | #include "buildingblock/all.h" 2 | #include "debug/all.h" 3 | #include "objectrep/all.h" 4 | #include "threads/all.h" 5 | #include "utility/all.h" 6 | #include "combining/all.h" 7 | #include "general/all.h" 8 | #include "top/all.h" 9 | 10 | // #include "special/" 11 | 12 | 13 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /hoard/heaplayers/wrappers/gnuwrapper.h: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | void * xxmalloc (size_t); 3 | void xxfree (void *); 4 | void * xxrealloc (void *ptr, size_t sz); 5 | void *get_page_list(unsigned int *pgcount); 6 | void migrate_pages(int node); 7 | size_t xx_get_largemmap_range (void *start, void *end); 8 | void* xx_reserve(size_t sz); 9 | } 10 | -------------------------------------------------------------------------------- /leveldb-1.20/AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file like so: 2 | # Name or Organization 3 | 4 | Google Inc. 5 | 6 | # Initial version authors: 7 | Jeffrey Dean 8 | Sanjay Ghemawat 9 | 10 | # Partial list of contributors: 11 | Kevin Regan 12 | Johan Bilien 13 | -------------------------------------------------------------------------------- /util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /leveldb-1.20/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /scripts/mount_ramdisk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | #script to create and mount a pmemdir 3 | #requires size as input 4 | sudo umount /mnt/pmemdir 5 | 6 | if [[ x$1 == x ]]; 7 | then 8 | echo You have specify correct pmemdir size in GB 9 | exit 1 10 | fi 11 | 12 | sudo mkdir /mnt/pmemdir 13 | sudo chown -R $USER /mnt/pmemdir 14 | chmod 777 /mnt/pmemdir 15 | sudo mount -t tmpfs -o size=$1M tmpfs /mnt/pmemdir 16 | 17 | -------------------------------------------------------------------------------- /port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /leveldb-1.20/port/README: -------------------------------------------------------------------------------- 1 | This directory contains interfaces and implementations that isolate the 2 | rest of the package from platform details. 3 | 4 | Code in the rest of the package includes "port.h" from this directory. 5 | "port.h" in turn includes a platform specific "port_.h" file 6 | that provides the platform specific implementation. 7 | 8 | See port_posix.h for an example of what must be provided in a platform 9 | specific header file. 10 | 11 | -------------------------------------------------------------------------------- /scripts/setup_vanilla_leveldb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x 3 | export TEST_TMPDIR="/mnt/pmemdir" 4 | 5 | SETUP() { 6 | cd $NOVELSMSRC 7 | #git clone https://github.com/google/leveldb 8 | cd $NOVELSMSRC/leveldb-1.20 9 | } 10 | 11 | MAKE() { 12 | #mkdir out-static 13 | #cd out-static 14 | #rm -rf CMakeCache.txt 15 | #cmake -DCMAKE_BUILD_TYPE=Release .. 16 | make clean 17 | make -j$PARA 18 | cd $NOVELSMSRC 19 | } 20 | 21 | SETUP 22 | MAKE 23 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/all.h: -------------------------------------------------------------------------------- 1 | #include "align.h" 2 | #include "bins.h" 3 | #include "bins16k.h" 4 | #include "bins4k.h" 5 | #include "bins64k.h" 6 | #include "bins8k.h" 7 | #include "dllist.h" 8 | #include "dynarray.h" 9 | #include "freesllist.h" 10 | #include "hash.h" 11 | #include "gcd.h" 12 | #include "guard.h" 13 | #include "istrue.h" 14 | #include "lcm.h" 15 | #include "myhashmap.h" 16 | #include "sassert.h" 17 | #include "sllist.h" 18 | #include "timer.h" 19 | 20 | -------------------------------------------------------------------------------- /util/bitops.h: -------------------------------------------------------------------------------- 1 | #ifndef BITOPS_H 2 | #define BITOPS_H 1 3 | 4 | #define BITS_PER_LONG (sizeof(unsigned long) * 8) 5 | #define BYTES_PER_LONG (sizeof(long)) 6 | 7 | #define MAXCORES 256 8 | 9 | #define test_bit(i,p) ((p)[(i) / BITS_PER_LONG] & (1UL << ((i)%BITS_PER_LONG))) 10 | #define set_bit(i,p) ((p)[(i) / BITS_PER_LONG] |= (1UL << ((i)%BITS_PER_LONG))) 11 | #define clear_bit(i,p) ((p)[(i) / BITS_PER_LONG] &= ~(1UL << ((i)%BITS_PER_LONG))) 12 | 13 | extern int find_first_bit(void *mask, int max); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/align.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_ALIGN_H 4 | #define HL_ALIGN_H 5 | 6 | #include 7 | 8 | #include "sassert.h" 9 | 10 | namespace HL { 11 | 12 | /// @name align 13 | /// @brief Rounds up a value to the next multiple of v. 14 | /// @note Argument must be a power of two. 15 | template 16 | inline size_t align (size_t v) { 17 | sassert<((Alignment & (Alignment-1)) == 0)> isPowerOfTwo; 18 | return ((v + (Alignment-1)) & ~(Alignment-1)); 19 | } 20 | 21 | } 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Release 1.2 2011-05-16 2 | ---------------------- 3 | 4 | Fixes for larger databases (tested up to one billion 100-byte entries, 5 | i.e., ~100GB). 6 | 7 | (1) Place hard limit on number of level-0 files. This fixes errors 8 | of the form "too many open files". 9 | 10 | (2) Fixed memtable management. Before the fix, a heavy write burst 11 | could cause unbounded memory usage. 12 | 13 | A fix for a logging bug where the reader would incorrectly complain 14 | about corruption. 15 | 16 | Allow public access to WriteBatch contents so that users can easily 17 | wrap a DB. 18 | -------------------------------------------------------------------------------- /util/BloomFilter.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOOMFILTER_H_ 2 | #define BLOOMFILTER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | //13MB Bloom filter 9 | #define BLOOMSIZE 13631488 10 | #define BLOOMHASH 13 11 | 12 | 13 | class BloomFilter { 14 | 15 | public: 16 | BloomFilter(uint64_t size, uint8_t numHashes); 17 | BloomFilter(); 18 | void add(const uint8_t *data, size_t len); 19 | bool possiblyContains(const uint8_t *data, size_t len) const; 20 | 21 | private: 22 | uint8_t m_numHashes; 23 | std::vector m_bits; 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /leveldb-1.20/NEWS: -------------------------------------------------------------------------------- 1 | Release 1.2 2011-05-16 2 | ---------------------- 3 | 4 | Fixes for larger databases (tested up to one billion 100-byte entries, 5 | i.e., ~100GB). 6 | 7 | (1) Place hard limit on number of level-0 files. This fixes errors 8 | of the form "too many open files". 9 | 10 | (2) Fixed memtable management. Before the fix, a heavy write burst 11 | could cause unbounded memory usage. 12 | 13 | A fix for a logging bug where the reader would incorrectly complain 14 | about corruption. 15 | 16 | Allow public access to WriteBatch contents so that users can easily 17 | wrap a DB. 18 | -------------------------------------------------------------------------------- /leveldb-1.20/TODO: -------------------------------------------------------------------------------- 1 | ss 2 | - Stats 3 | 4 | db 5 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key) 6 | that would blow away files whose ranges are entirely contained 7 | within [start_key..end_key]? For Chrome, deletion of obsolete 8 | object stores, etc. can be done in the background anyway, so 9 | probably not that important. 10 | - There have been requests for MultiGet. 11 | 12 | After a range is completely deleted, what gets rid of the 13 | corresponding files if we do no future changes to that range. Make 14 | the conditions for triggering compactions fire in more situations? 15 | -------------------------------------------------------------------------------- /hoard/heaplayers/wrappers/macinterpose.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_MACINTERPOSE_H 4 | #define HL_MACINTERPOSE_H 5 | 6 | // The interposition data structure (just pairs of function pointers), 7 | // used an interposition table like the following: 8 | // 9 | 10 | typedef struct interpose_s { 11 | void *new_func; 12 | void *orig_func; 13 | } interpose_t; 14 | 15 | #define MAC_INTERPOSE(newf,oldf) __attribute__((used)) \ 16 | static const interpose_t macinterpose##newf##oldf \ 17 | __attribute__ ((section("__DATA, __interpose"))) = \ 18 | { (void *) newf, (void *) oldf } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/sassert.h: -------------------------------------------------------------------------------- 1 | #ifndef HL_SASSERT_H 2 | #define HL_SASSERT_H 3 | 4 | /** 5 | * @class sassert 6 | * @brief Implements compile-time assertion checking. 7 | * @author Emery Berger 8 | * 9 | * @code 10 | * sassert<(1+1 == 2)> CheckOnePlusOneIsTwo; 11 | * @endcode 12 | * 13 | * This code is part of the Hoard distribution and is governed by its license. 14 | * 15 | * 16 | */ 17 | 18 | namespace HL { 19 | 20 | template 21 | class sassert; 22 | 23 | template<> class sassert { }; 24 | 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /leveldb-1.20/util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /scripts/setvars.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export NOVELSMSRC=$PWD 3 | export NOVELSMSCRIPT=$NOVELSMSRC/scripts 4 | export DBBENCH=$NOVELSMSRC/out-static 5 | export TEST_TMPDIR=/mnt/pmemdir 6 | #DRAM buffer size in MB 7 | export DRAMBUFFSZ=64 8 | #NVM buffer size in MB 9 | export NVMBUFFSZ=12 10 | export INPUTXML=$NOVELSMSCRIPT/input.xml 11 | #Vanilla LevelDB benchmark 12 | export LEVELDB_VANILLA=$NOVELSMSRC/leveldb-1.20 13 | export DBBENCH_VANLILLA=$LEVELDB_VANILLA/out-static 14 | export PARA=40 15 | export NUMA_AFFINITY=0 16 | #Numa binding 17 | export APP_PREFIX="numactl --membind=$NUMA_AFFINITY --cpunodebind=$NUMA_AFFINITY" 18 | #export APP_PREFIX="" 19 | -------------------------------------------------------------------------------- /util/debug.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | //#define DEBUG 14 | 15 | //Trouble shooting debug 16 | //use only if trouble shooting 17 | //some specific functions 18 | void DEBUG_T(const char* format, ... ) { 19 | #ifdef DEBUG 20 | FILE *fp; 21 | va_list args; 22 | va_start( args, format ); 23 | vfprintf( stdout, format, args ); 24 | va_end( args ); 25 | #endif 26 | } 27 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | -Compilation warnings when enabling BLOOM PREDICTION 2 | 3 | 4 | 5 | ss 6 | - Stats 7 | 8 | 9 | 10 | db 11 | - Maybe implement DB::BulkDeleteForRange(start_key, end_key) 12 | that would blow away files whose ranges are entirely contained 13 | within [start_key..end_key]? For Chrome, deletion of obsolete 14 | object stores, etc. can be done in the background anyway, so 15 | probably not that important. 16 | - There have been requests for MultiGet. 17 | 18 | After a range is completely deleted, what gets rid of the 19 | corresponding files if we do no future changes to that range. Make 20 | the conditions for triggering compactions fire in more situations? 21 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/README: -------------------------------------------------------------------------------- 1 | Heap organization: 2 | 3 | top/ - "source" heaps that have no superheap. 4 | combining/ - heaps whose purpose is to combine two existing superheaps. 5 | debug/ - heaps whose only purpose is debugging or statistics-gathering. 6 | threads/ - heaps designed to support multiple threads. 7 | special/ - esoteric heaps to support custom allocation schemes like obstacks. 8 | 9 | buildingblock/ - layers that cannot be used standalone but rather are useful for building other heaps. 10 | objectrep/ - heaps that change the representation of individual objects (e.g., by adding headers). 11 | (admittedly this is a terrible organizational principle) 12 | utility/ - currently a grab-bag 13 | -------------------------------------------------------------------------------- /port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #endif 18 | 19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 20 | -------------------------------------------------------------------------------- /leveldb-1.20/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if defined(LEVELDB_PLATFORM_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #endif 18 | 19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 20 | -------------------------------------------------------------------------------- /helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /leveldb-1.20/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/hash.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_HASH_H 4 | #define HL_HASH_H 5 | 6 | #include 7 | #include 8 | 9 | namespace HL { 10 | 11 | template 12 | class Hash { 13 | public: 14 | static size_t hash (Key k); 15 | }; 16 | 17 | template <> 18 | class Hash { 19 | public: 20 | static inline size_t hash (void * v) { 21 | return (size_t) v; 22 | } 23 | }; 24 | 25 | template <> 26 | class Hash { 27 | public: 28 | static inline size_t hash (void * v) { 29 | return (size_t) ((size_t) v); 30 | } 31 | }; 32 | 33 | template <> 34 | class Hash { 35 | public: 36 | static inline size_t hash (int v) { 37 | return (size_t) v; 38 | } 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /util/MurmurHash3.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // MurmurHash3 was written by Austin Appleby, and is placed in the public 3 | // domain. The author hereby disclaims copyright to this source code. 4 | 5 | #ifndef _MURMURHASH3_H_ 6 | #define _MURMURHASH3_H_ 7 | 8 | #include 9 | 10 | //----------------------------------------------------------------------------- 11 | 12 | void MurmurHash3_x86_32 ( const void * key, int len, uint32_t seed, void * out ); 13 | 14 | void MurmurHash3_x86_128 ( const void * key, int len, uint32_t seed, void * out ); 15 | 16 | void MurmurHash3_x64_128 ( const void * key, int len, uint32_t seed, void * out ); 17 | 18 | //----------------------------------------------------------------------------- 19 | 20 | #endif // _MURMURHASH3_H_ 21 | -------------------------------------------------------------------------------- /scripts/run_vanilla_leveldb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | NUMTHREAD=1 4 | BENCHMARKS="fillrandom,readrandom" 5 | NUMKEYS="1000000" 6 | let BUFFBYTES=$DRAMBUFFSZ*1024*1024 7 | OTHERPARAMS="--write_buffer_size=$BUFFBYTES" 8 | VALUSESZ=4096 9 | 10 | SETUP() { 11 | if [ -z "$TEST_TMPDIR" ] 12 | then 13 | echo "DB path empty. Run source scripts/setvars.sh from source parent dir" 14 | exit 15 | fi 16 | rm -rf $TEST_TMPDIR/* 17 | mkdir -p $TEST_TMPDIR 18 | } 19 | 20 | MAKE() { 21 | cd $LEVELDB_VANILLA 22 | #make clean 23 | make -j8 24 | } 25 | 26 | SETUP 27 | MAKE 28 | $DBBENCH_VANLILLA/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --benchmarks=$BENCHMARKS --value_size=$VALUSESZ $OTHERPARAMS 29 | SETUP 30 | 31 | #Run all benchmarks 32 | $DBBENCH_VANLILLA/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --value_size=$VALUSESZ $OTHERPARAMS 33 | 34 | -------------------------------------------------------------------------------- /util/lsm_mutex.h: -------------------------------------------------------------------------------- 1 | #ifndef FTL_MUTEX_H 2 | #define FTL_MUTEX_H 3 | 4 | #include "defs.h" 5 | #include 6 | 7 | #include 8 | 9 | struct ftl_mutex { 10 | pthread_mutex_t lock; 11 | }; 12 | 13 | #define FTL_ATOMIC_ADD_FETCH(p, val) __atomic_fetch_add(p, val, __ATOMIC_SEQ_CST); 14 | #define FTL_ATOMIC_SUB_FETCH(p, val) __atomic_fetch_sub(p, val, __ATOMIC_SEQ_CST); 15 | #define FTL_ATOMIC_STORE(p, val) __atomic_store(p, val, __ATOMIC_SEQ_CST); 16 | #define ATOMIC_LOAD(p) __atomic_load_n(p, __ATOMIC_SEQ_CST); 17 | 18 | void ftl_mutex_init(struct ftl_mutex *mutex); 19 | void ftl_mutex_lock(struct ftl_mutex *mutex); 20 | void ftl_mutex_unlock(struct ftl_mutex *mutex); 21 | void ftl_mutex_destroy(struct ftl_mutex *mutex); 22 | int64_t ftl_atomic_add_fetch(volatile int*, int64_t); 23 | int64_t ftl_atomic_sub_fetch(volatile int*, int64_t); 24 | #endif 25 | -------------------------------------------------------------------------------- /db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /leveldb-1.20/db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | class DBImpl; 15 | 16 | // Return a new iterator that converts internal keys (yielded by 17 | // "*internal_iter") that were live at the specified "sequence" number 18 | // into appropriate user keys. 19 | extern Iterator* NewDBIterator( 20 | DBImpl* db, 21 | const Comparator* user_key_comparator, 22 | Iterator* internal_iter, 23 | SequenceNumber sequence, 24 | uint32_t seed); 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 29 | -------------------------------------------------------------------------------- /port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /leveldb-1.20/util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | max_file_size(2<<20), 25 | compression(kSnappyCompression), 26 | reuse_logs(false), 27 | filter_policy(NULL) { 28 | } 29 | 30 | } // namespace leveldb 31 | -------------------------------------------------------------------------------- /leveldb-1.20/port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /hoard/test/testoverflow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef __APPLE__ 4 | #include 5 | #endif 6 | 7 | #include "heaplayers/wrappers/gnuwrapper.h" 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | cout << "size = " << (size_t) -1 << endl; 16 | cout << "uint_max = " << UINT_MAX << endl; 17 | cout << "ulong_max = " << ULONG_MAX << endl; 18 | 19 | void * m1 = xxmalloc(1024); 20 | void * c1 = calloc(1024, 1024); 21 | int * n1 = new int[1024-1]; 22 | 23 | cout << "Result of malloc = " << m1 << endl 24 | << "Result of calloc = " << c1 << endl 25 | << "Result of new = " << n1 << endl; 26 | 27 | 28 | void * m = malloc((size_t) -1); 29 | void * c = calloc(UINT_MAX, UINT_MAX); 30 | int * n = new int[UINT_MAX]; 31 | 32 | cout << "Result of malloc = " << m << endl 33 | << "Result of calloc = " << c << endl 34 | << "Result of new = " << n << endl; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | nvm_buffer_size(40<<20), 21 | num_levels(1), 22 | max_open_files(1000), 23 | block_cache(NULL), 24 | block_size(4096), 25 | block_restart_interval(16), 26 | compression(kSnappyCompression), 27 | reuse_logs(false), 28 | filter_policy(NULL) { 29 | } 30 | 31 | } // namespace leveldb 32 | -------------------------------------------------------------------------------- /include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /leveldb-1.20/table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /hoard/source/hash_maps.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_MAPS_H_ 2 | #define HASH_MAPS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "nv_map.h" 15 | #include "nv_def.h" 16 | #include "nv_structs.h" 17 | 18 | //int record_addr(void* addr, size_t size); 19 | void* get_chunk_from_map(void *addr); 20 | void* get_chunk_with_id(UINT chunkid); 21 | int record_chunks(void* addr, chunkobj_s *chunk); 22 | int get_chnk_cnt_frm_map(); 23 | void *get_chunk_from_map_o1(void *addr); 24 | int record_vmas(int vmaid, size_t size); 25 | int record_metadata_vma(int vmaid, size_t size); 26 | size_t get_vma_size(int vmaid); 27 | void add_alloc_map(void *ptr, size_t size); 28 | size_t get_alloc_size(void *ptr, unsigned long *addr); 29 | void protect_all_chunks(); 30 | void *get_alloc_pagemap(unsigned int *count, size_t **ptr); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /leveldb-1.20/include/leveldb/dumpfile.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 6 | #define STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 7 | 8 | #include 9 | #include "leveldb/env.h" 10 | #include "leveldb/status.h" 11 | 12 | namespace leveldb { 13 | 14 | // Dump the contents of the file named by fname in text format to 15 | // *dst. Makes a sequence of dst->Append() calls; each call is passed 16 | // the newline-terminated text corresponding to a single item found 17 | // in the file. 18 | // 19 | // Returns a non-OK result if fname does not name a leveldb storage 20 | // file, or if the file cannot be read. 21 | Status DumpFile(Env* env, const std::string& fname, WritableFile* dst); 22 | 23 | } // namespace leveldb 24 | 25 | #endif // STORAGE_LEVELDB_INCLUDE_DUMPFILE_H_ 26 | -------------------------------------------------------------------------------- /hoard/include/hoard/hash_maps.h: -------------------------------------------------------------------------------- 1 | #ifndef HASH_MAPS_H_ 2 | #define HASH_MAPS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "nv_map.h" 15 | #include "nv_def.h" 16 | #include "nv_structs.h" 17 | 18 | //int record_addr(void* addr, size_t size); 19 | void* get_chunk_from_map(void *addr); 20 | void* get_chunk_with_id(UINT chunkid); 21 | int record_chunks(void* addr, chunkobj_s *chunk); 22 | int get_chnk_cnt_frm_map(); 23 | void *get_chunk_from_map_o1(void *addr); 24 | int record_vmas(int vmaid, size_t size); 25 | int record_metadata_vma(int vmaid, size_t size); 26 | size_t get_vma_size(int vmaid); 27 | void add_alloc_map(void *ptr, size_t size); 28 | size_t get_alloc_size(void *ptr, unsigned long *addr); 29 | void protect_all_chunks(); 30 | void *get_alloc_pagemap(unsigned int *count, size_t **sz); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CacheKV 2 | ## 1 Introduction 3 | This is the implementation of CacheKV described in the paper "**Redesigning High-Performance LSM-based Key-Value Stores with Persistent CPU Caches**". CacheKV is a LSM-Tree based KV store utilizing Persistent CPU Cache provided by Intel Optane Persistent Memory 200 Series. 4 | We implement CacheKV based on [NoveLSM] (https://github.com/sudarsunkannan/lsm_nvm). 5 | 6 | ## 2 Compilation and Run CacheKV 7 | ### 2.1 Tools 8 | CacheKV relies on Intel(R) RDT Software Package (https://github.com/intel/intel-cmt-cat). 9 | To run CacheKV, please install it first (https://github.com/intel/intel-cmt-cat/blob/master/INSTALL). 10 | 11 | ### 2.2 Compilation 12 | The GCC version in our environment is 7.5.0. 13 | ``` 14 | $ cd hoard 15 | $ ./compile_install_hoard.sh 16 | $ cd .. 17 | $ make -j8 18 | ``` 19 | 20 | ### 2.3 Run 21 | First set the environment variables and then run the DB_Bench benchmark. 22 | ``` 23 | $ source scripts/setvars.sh 24 | $ scripts/run_cachekv_dbbench.sh 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /leveldb-1.20/util/env_posix_test_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 6 | #define STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class EnvPosixTest; 11 | 12 | // A helper for the POSIX Env to facilitate testing. 13 | class EnvPosixTestHelper { 14 | private: 15 | friend class EnvPosixTest; 16 | 17 | // Set the maximum number of read-only files that will be opened. 18 | // Must be called before creating an Env. 19 | static void SetReadOnlyFDLimit(int limit); 20 | 21 | // Set the maximum number of read-only files that will be mapped via mmap. 22 | // Must be called before creating an Env. 23 | static void SetReadOnlyMMapLimit(int limit); 24 | }; 25 | 26 | } // namespace leveldb 27 | 28 | #endif // STORAGE_LEVELDB_UTIL_ENV_POSIX_TEST_HELPER_H_ 29 | -------------------------------------------------------------------------------- /db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.txt for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /leveldb-1.20/db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.md for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), length (2 bytes), type (1 byte). 30 | static const int kHeaderSize = 4 + 2 + 1; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /leveldb-1.20/util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/top/sbrkheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | #ifndef HL_SBRKHEAP_H 4 | #define HL_SBRKHEAP_H 5 | 6 | #ifdef WIN32 7 | 8 | // If we're using Windows, we'll need to link in sbrk.c, 9 | // a replacement for sbrk(). 10 | 11 | extern "C" void * sbrk (size_t sz); 12 | 13 | #endif 14 | 15 | /* 16 | * @class SbrkHeap 17 | * @brief A source heap that is a thin wrapper over sbrk. 18 | * 19 | * As it stands, memory cannot be returned to sbrk(). 20 | * This is not a significant limitation, since only memory 21 | * at the end of the break point can ever be returned anyway. 22 | */ 23 | 24 | namespace HL { 25 | 26 | class SbrkHeap { 27 | public: 28 | 29 | enum { Alignment = 16 }; 30 | 31 | SbrkHeap (void) 32 | { 33 | void * ptr = sbrk(0); 34 | while ((size_t) ptr % Alignment != 0) { 35 | ptr = sbrk(1); 36 | } 37 | } 38 | 39 | inline void * malloc (size_t sz) { 40 | if (sz == 0) { 41 | sz = Alignment; 42 | } else { 43 | while (sz % Alignment != 1) { 44 | sz++; 45 | } 46 | } 47 | return sbrk(sz); 48 | } 49 | inline void free (void *) { } 50 | }; 51 | 52 | } 53 | 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /scripts/linuxperf.sh: -------------------------------------------------------------------------------- 1 | #/users/skannan/ssd/schedsp/linux-4.5.4/tools/perf/perf stat -e instructions -e LLC-store-misses -e LLC-load-misses $1 2 | 3 | export PREFIX="/users/skannan/ssd/schedsp/linux-4.5.4/tools/perf/perf stat -e instructions -e LLC-store-misses -e LLC-load-misses" 4 | $1 5 | 6 | #/usr/bin/time -v $1 7 | #/opt/intel/vtune_amplifier_xe_2013/bin64/amplxe-cl -collect-with runsa -knob event-config=L2_LINES_IN.SELF.ANY,DATA_TLB_MISSES.DTLB_MISS,INST_RETIRED.ANY $1 8 | 9 | #LD_PRELOAD=/usr/lib/libhoard.so $1 10 | 11 | #echo "Enter application name and arguments as params for the script" 12 | #sudo chmod o+rw /dev/cpu/*/msr 13 | #sudo modprobe msr 14 | #sudo likwid-perfctr -C 0-3 -g INSTR_RETIRED_ANY:FIXC0,DTLB_LOAD_MISSES_ANY:PMC0,L2_LINES_IN_ANY:PMC1 $1 15 | #sudo likwid-perfctr -C 0-7 -g INSTR_RETIRED_ANY:FIXC0,MEM_UNCORE_RETIRED_LOCAL_DRAM:PMC0,MEM_UNCORE_RETIRED_REMOTE_DRAM:PMC1 $1 16 | #sudo likwid-perfctr -C 0-7 -g INSTR_RETIRED_ANY:FIXC0,MEM_UNCORE_RETIRED_LOCAL_DRAM:PMC0,MEM_INST_RETIRED_LOADS:PMC1,MEM_INST_RETIRED_STORES:PMC2,UNC_L3_MISS_ANY:UPMC0 $1 17 | #sudo likwid-perfctr -C 0-7 -g INSTR_RETIRED_ANY:FIXC0 $1 18 | #sudo likwid-powermeter -p $1 19 | #/usr/bin/time -v $1 20 | -------------------------------------------------------------------------------- /scripts/run_dbbench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | NUMTHREAD=1 5 | BENCHMARKS="fillrandom,readrandom" 6 | NUMKEYS="1000000" 7 | #NoveLSM specific parameters 8 | #NoveLSM uses memtable levels, always set to num_levels 2 9 | #write_buffer_size DRAM memtable size in MBs 10 | #write_buffer_size_2 specifies NVM memtable size; set it in few GBs for perfomance; 11 | OTHERPARAMS="--num_levels=2 --write_buffer_size=$DRAMBUFFSZ --nvm_buffer_size=$NVMBUFFSZ" 12 | NUMREADTHREADS="0" 13 | VALUSESZ=4096 14 | 15 | SETUP() { 16 | if [ -z "$TEST_TMPDIR" ] 17 | then 18 | echo "DB path empty. Run source scripts/setvars.sh from source parent dir" 19 | exit 20 | fi 21 | rm -rf $TEST_TMPDIR/* 22 | mkdir -p $TEST_TMPDIR 23 | } 24 | 25 | MAKE() { 26 | cd $NOVELSMSRC 27 | #make clean 28 | make -j8 29 | } 30 | 31 | SETUP 32 | MAKE 33 | $APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS \ 34 | --benchmarks=$BENCHMARKS --value_size=$VALUSESZ $OTHERPARAMS --num_read_threads=$NUMREADTHREADS 35 | SETUP 36 | 37 | #Run all benchmarks 38 | $APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --value_size=$VALUSESZ \ 39 | $OTHERPARAMS --num_read_threads=$NUMREADTHREADS 40 | 41 | -------------------------------------------------------------------------------- /table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /leveldb-1.20/table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /db/builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /leveldb-1.20/db/builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_BUILDER_H_ 6 | #define STORAGE_LEVELDB_DB_BUILDER_H_ 7 | 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | 12 | struct Options; 13 | struct FileMetaData; 14 | 15 | class Env; 16 | class Iterator; 17 | class TableCache; 18 | class VersionEdit; 19 | 20 | // Build a Table file from the contents of *iter. The generated file 21 | // will be named according to meta->number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /hoard/include/VERSION.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | // Hoard version X.Y.0 = X0Y00 29 | 30 | #define HOARD_MAJOR 3 31 | #define HOARD_MINOR 9 32 | #define HOARD_PATCH 0 33 | 34 | #define HOARD_VERSION_STRING "3.9.0" 35 | #define HOARD_VERSION_NUMBER (HOARD_MAJOR * 10000 + HOARD_MINOR * 100 + HOARD_PATCH) 36 | -------------------------------------------------------------------------------- /util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /leveldb-1.20/util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/debug/debugheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | 4 | #ifndef HL_DEBUGHEAP_H_ 5 | #define HL_DEBUGHEAP_H_ 6 | 7 | #include 8 | 9 | /** 10 | * 11 | * 12 | */ 13 | 14 | namespace HL { 15 | 16 | template 18 | class DebugHeap : public Super { 19 | private: 20 | 21 | enum { CANARY = 0xdeadbeef }; 22 | 23 | public: 24 | 25 | // Fill with A's. 26 | inline void * malloc (size_t sz) { 27 | // Add a guard area at the end. 28 | void * ptr; 29 | ptr = Super::malloc (sz + sizeof(unsigned long)); 30 | for (unsigned long i = 0; i < sz; i++) { 31 | ((char *) ptr)[i] = 'A'; 32 | } 33 | *((unsigned long *) ((char *) ptr + sz)) = (unsigned long) CANARY; 34 | assert (Super::getSize(ptr) >= sz); 35 | return ptr; 36 | } 37 | 38 | // Fill with F's. 39 | inline void free (void * ptr) { 40 | char * b = (char *) ptr; 41 | size_t sz = Super::getSize(ptr); 42 | // Check for the canary. 43 | unsigned long storedCanary = *((unsigned long *) b + sz - sizeof(unsigned long)); 44 | if (storedCanary != CANARY) { 45 | abort(); 46 | } 47 | for (unsigned int i = 0; i < sz; i++) { 48 | ((char *) ptr)[i] = freeChar; 49 | } 50 | Super::free (ptr); 51 | } 52 | }; 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /leveldb-1.20/table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/istrue.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_ISTRUE_H 4 | #define HL_ISTRUE_H 5 | 6 | /* 7 | 8 | Heap Layers: An Extensible Memory Allocation Infrastructure 9 | 10 | Copyright (C) 2000-2012 by Emery Berger 11 | http://www.cs.umass.edu/~emery 12 | emery@cs.umass.edu 13 | 14 | This program is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU General Public License as published by 16 | the Free Software Foundation; either version 2 of the License, or 17 | (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | 28 | */ 29 | 30 | namespace HL { 31 | 32 | template 33 | class IsTrue; 34 | 35 | template<> 36 | class IsTrue { 37 | public: 38 | enum { value = true }; 39 | }; 40 | 41 | template<> 42 | class IsTrue { 43 | public: 44 | enum { value = false }; 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /scripts/run_cachekv_dbbench.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | NUMTHREAD=1 5 | BENCHMARKS="fillrandom,readrandom" 6 | NUMKEYS="10000000" 7 | #NoveLSM specific parameters 8 | #NoveLSM uses memtable levels, always set to num_levels 2 9 | #write_buffer_size DRAM memtable size in MBs 10 | #write_buffer_size_2 specifies NVM memtable size; set it in few GBs for perfomance; 11 | OTHERPARAMS="--num_levels=2 --write_buffer_size=$DRAMBUFFSZ --nvm_buffer_size=$NVMBUFFSZ" 12 | CACHEKVPARAMS="--dlock_way=4 --dlock_size=12582912 --skiplistSync_threshold=65536 --compactImm_threshold=10 --subImm_partition=0 --subImm_thread=1" 13 | NUMREADTHREADS="0" 14 | VALUSESZ=64 15 | 16 | SETUP() { 17 | if [ -z "$TEST_TMPDIR" ] 18 | then 19 | echo "DB path empty. Run source scripts/setvars.sh from source parent dir" 20 | exit 21 | fi 22 | rm -rf $TEST_TMPDIR/* 23 | mkdir -p $TEST_TMPDIR 24 | } 25 | 26 | MAKE() { 27 | cd $NOVELSMSRC 28 | #make clean 29 | make -j8 30 | } 31 | 32 | SETUP 33 | MAKE 34 | modprobe msr 35 | ulimit -Sn 10240 36 | $APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS \ 37 | --benchmarks=$BENCHMARKS --value_size=$VALUSESZ $OTHERPARAMS $CACHEKVPARAMS --num_read_threads=$NUMREADTHREADS 38 | SETUP 39 | 40 | #Run all benchmarks 41 | #$APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --value_size=$VALUSESZ \ 42 | #$OTHERPARAMS --num_read_threads=$NUMREADTHREADS -------------------------------------------------------------------------------- /hoard/heaplayers/utility/freesllist.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef _FREESLLIST_H_ 4 | #define _FREESLLIST_H_ 5 | 6 | #include 7 | 8 | /** 9 | * @class FreeSLList 10 | * @brief A "memory neutral" singly-linked list, 11 | * 12 | * Uses the free space in objects to store 13 | * the pointers. 14 | */ 15 | 16 | 17 | class FreeSLList { 18 | public: 19 | 20 | inline void clear (void) { 21 | head.next = NULL; 22 | } 23 | 24 | class Entry; 25 | 26 | /// Get the head of the list. 27 | inline Entry * get (void) { 28 | const Entry * e = head.next; 29 | if (e == NULL) { 30 | return NULL; 31 | } 32 | head.next = e->next; 33 | return const_cast(e); 34 | } 35 | 36 | inline Entry * remove (void) { 37 | const Entry * e = head.next; 38 | if (e == NULL) { 39 | return NULL; 40 | } 41 | head.next = e->next; 42 | return const_cast(e); 43 | } 44 | 45 | inline void insert (void * e) { 46 | Entry * entry = reinterpret_cast(e); 47 | entry->next = head.next; 48 | head.next = entry; 49 | } 50 | 51 | class Entry { 52 | public: 53 | Entry (void) 54 | : next (NULL) 55 | {} 56 | Entry * next; 57 | private: 58 | Entry (const Entry&); 59 | Entry& operator=(const Entry&); 60 | }; 61 | 62 | private: 63 | Entry head; 64 | }; 65 | 66 | 67 | #endif 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /hoard/include/util/conformantheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_CONFORMANTHEAP_H 29 | #define HOARD_CONFORMANTHEAP_H 30 | 31 | namespace Hoard { 32 | 33 | // more concise than double declarations when the parent is complex 34 | // and we need the SuperHeap declaration. 35 | template 36 | class ConformantHeap : public Parent { 37 | public: 38 | typedef Parent SuperHeap; 39 | }; 40 | 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/guard.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_GUARD_H 28 | #define HL_GUARD_H 29 | 30 | namespace HL { 31 | 32 | template 33 | class Guard { 34 | public: 35 | inline Guard (LockType& l) 36 | : _lock (l) 37 | { 38 | _lock.lock(); 39 | } 40 | 41 | inline ~Guard (void) { 42 | _lock.unlock(); 43 | } 44 | private: 45 | LockType& _lock; 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /util/BloomFilter.cc: -------------------------------------------------------------------------------- 1 | #include "BloomFilter.h" 2 | #include "MurmurHash3.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | BloomFilter::BloomFilter(uint64_t size, uint8_t numHashes) 14 | : m_bits(size), 15 | m_numHashes(numHashes) {} 16 | 17 | BloomFilter::BloomFilter(){ 18 | } 19 | 20 | std::array hash(const uint8_t *data, 21 | size_t len) { 22 | std::array hashValue; 23 | MurmurHash3_x64_128(data, len, 0, hashValue.data()); 24 | 25 | return hashValue; 26 | } 27 | 28 | inline uint64_t nthHash(uint8_t n, 29 | uint64_t hashA, 30 | uint64_t hashB, 31 | uint64_t filterSize) { 32 | return (hashA + n * hashB) % filterSize; 33 | } 34 | 35 | void BloomFilter::add(const uint8_t *data, size_t len) { 36 | auto hashValues = hash(data, len); 37 | 38 | for (int n = 0; n < m_numHashes; n++) { 39 | m_bits[nthHash(n, hashValues[0], hashValues[1], m_bits.size())] = true; 40 | } 41 | } 42 | 43 | bool BloomFilter::possiblyContains(const uint8_t *data, size_t len) const { 44 | auto hashValues = hash(data, len); 45 | 46 | for (int n = 0; n < m_numHashes; n++) { 47 | if (!m_bits[nthHash(n, hashValues[0], hashValues[1], m_bits.size())]) { 48 | return false; 49 | } 50 | } 51 | 52 | return true; 53 | } 54 | -------------------------------------------------------------------------------- /hoard/README: -------------------------------------------------------------------------------- 1 | This directory contains all source code required to build Hoard. 2 | 3 | heaplayers/ - Heap Layers (heaplayers.org), an infrastructure for building memory allocators 4 | include/ - all Hoard-specific header files (the bulk of Hoard's functionality) 5 | source/ - all .cpp files required to use Hoard 6 | 7 | ** Building Hoard: ** 8 | 9 | To compile Hoard on any platform, use "make" (or on Windows, "nmake"). 10 | Just type 11 | 12 | make 13 | 14 | to see all possible options. 15 | 16 | ** Using Hoard with Windows: ** 17 | 18 | First, build the libhoard.dll ("nmake windows"). 19 | Then, link your executable with 'source\uselibhoard.cpp' and 'libhoard.lib'. 20 | You must use the /MD flag. 21 | 22 | Example: 23 | C:\hoard\src> cl /Ox /MD yourapp.cpp source\uselibhoard.cpp libhoard.lib 24 | 25 | To run yourapp.exe, you will need to have libhoard.dll in your path. 26 | 27 | 28 | ** Using Hoard with other systems: ** 29 | 30 | You can use Hoard by linking it with your executable, or by setting a 31 | single environment variable. For UNIX systems, this is the LD_PRELOAD 32 | environment variable: 33 | 34 | % export LD_PRELOAD=/path/to/libhoard.so 35 | 36 | in Solaris: 37 | 38 | % export LD_PRELOAD="/path/to/libhoard_32.so:/usr/lib/libCrun.so.1" 39 | (32-bit version) 40 | 41 | % export LD_PRELOAD="/path/to/libhoard_64.so:/usr/lib/64/libCrun.so.1" 42 | (64-bit version) 43 | 44 | in Mac OS X, use DYLD_INSERT_LIBRARIES. 45 | 46 | % export DYLD_INSERT_LIBRARIES=/path/to/libhoard.dylib 47 | -------------------------------------------------------------------------------- /scripts/run_read_parallel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #set -x 3 | 4 | NUMTHREAD=1 5 | BENCHMARKS="fillrandom,readrandom,stats" 6 | NUMKEYS="1000000" 7 | #NoveLSM specific parameters 8 | #NoveLSM uses memtable levels, always set to num_levels 2 9 | #write_buffer_size DRAM memtable size in MBs 10 | #write_buffer_size_2 specifies NVM memtable size; set it in few GBs for perfomance; 11 | OTHERPARAMS="--num_levels=2 --write_buffer_size=$DRAMBUFFSZ --nvm_buffer_size=$NVMBUFFSZ" 12 | NUMREADTHREADS="1" 13 | VALUSESZ=16384 14 | 15 | SETUP() { 16 | source $NOVELSMSCRIPT/setvars.sh 17 | if [ ! -z "$TEST_TMPDIR" ]; then 18 | rm -rf $TEST_TMPDIR/* 19 | fi 20 | } 21 | 22 | MAKE() { 23 | cd $NOVELSMSRC 24 | #make clean 25 | make -j8 26 | } 27 | 28 | 29 | SETUP 30 | MAKE 31 | 32 | echo " " 33 | echo "**************************************" 34 | echo " Without Read Threading " 35 | echo "**************************************" 36 | echo " " 37 | 38 | $APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --benchmarks=$BENCHMARKS \ 39 | --value_size=$VALUSESZ $OTHERPARAMS --num_read_threads=0 40 | SETUP 41 | 42 | #Run all benchmarks 43 | echo " " 44 | echo "**************************************" 45 | echo " With Read Threading " 46 | echo "**************************************" 47 | echo " " 48 | $APP_PREFIX $DBBENCH/db_bench --threads=$NUMTHREAD --num=$NUMKEYS --benchmarks=$BENCHMARKS \ 49 | --value_size=$VALUSESZ $OTHERPARAMS --num_read_threads=$NUMREADTHREADS 50 | 51 | set +x 52 | -------------------------------------------------------------------------------- /doc/doc.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin-left: 0.5in; 3 | margin-right: 0.5in; 4 | background: white; 5 | color: black; 6 | } 7 | 8 | h1 { 9 | margin-left: -0.2in; 10 | font-size: 14pt; 11 | } 12 | h2 { 13 | margin-left: -0in; 14 | font-size: 12pt; 15 | } 16 | h3 { 17 | margin-left: -0in; 18 | } 19 | h4 { 20 | margin-left: -0in; 21 | } 22 | hr { 23 | margin-left: -0in; 24 | } 25 | 26 | /* Definition lists: definition term bold */ 27 | dt { 28 | font-weight: bold; 29 | } 30 | 31 | address { 32 | text-align: center; 33 | } 34 | code,samp,var { 35 | color: blue; 36 | } 37 | kbd { 38 | color: #600000; 39 | } 40 | div.note p { 41 | float: right; 42 | width: 3in; 43 | margin-right: 0%; 44 | padding: 1px; 45 | border: 2px solid #6060a0; 46 | background-color: #fffff0; 47 | } 48 | 49 | ul { 50 | margin-top: -0em; 51 | margin-bottom: -0em; 52 | } 53 | 54 | ol { 55 | margin-top: -0em; 56 | margin-bottom: -0em; 57 | } 58 | 59 | UL.nobullets { 60 | list-style-type: none; 61 | list-style-image: none; 62 | margin-left: -1em; 63 | } 64 | 65 | p { 66 | margin: 1em 0 1em 0; 67 | padding: 0 0 0 0; 68 | } 69 | 70 | pre { 71 | line-height: 1.3em; 72 | padding: 0.4em 0 0.8em 0; 73 | margin: 0 0 0 0; 74 | border: 0 0 0 0; 75 | color: blue; 76 | } 77 | 78 | .datatable { 79 | margin-left: auto; 80 | margin-right: auto; 81 | margin-top: 2em; 82 | margin-bottom: 2em; 83 | border: 1px solid; 84 | } 85 | 86 | .datatable td,th { 87 | padding: 0 0.5em 0 0.5em; 88 | text-align: right; 89 | } 90 | -------------------------------------------------------------------------------- /hoard/source/uselibhoard.cpp: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | /* 4 | The Hoard Multiprocessor Memory Allocator 5 | www.hoard.org 6 | 7 | Author: Emery Berger, http://www.cs.umass.edu/~emery 8 | 9 | Copyright (c) 1998-2012 Emery Berger 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | // Link this code with your executable to use winhoard. 28 | 29 | #if defined(_WIN32) 30 | 31 | #include 32 | #if defined(_WIN64) 33 | #pragma comment(linker, "/include:ReferenceHoard") 34 | #else 35 | #pragma comment(linker, "/include:_ReferenceHoard") 36 | #endif 37 | 38 | extern "C" { 39 | 40 | __declspec(dllimport) int ReferenceWinWrapperStub; 41 | 42 | void ReferenceHoard (void) 43 | { 44 | LoadLibraryA ("libhoard.dll"); 45 | ReferenceWinWrapperStub = 1; 46 | } 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /port/cache_flush.h: -------------------------------------------------------------------------------- 1 | #ifndef CACHE_FLUSH_H 2 | #define CACHE_FLUSH_H 3 | 4 | #include 5 | #include 6 | 7 | #ifdef _ENABLE_PMEMIO 8 | #include "pmdk/src/include/libpmem.h" 9 | #endif 10 | 11 | //Cacheline size 12 | //TODO: Make it configurable 13 | #define CACHE_LINE_SIZE 64 14 | #define ASMFLUSH(dest) __asm__ __volatile__ ("clflush %0" : : "m"(*(volatile char *)dest)) 15 | 16 | static inline void clflush(volatile char* __p) 17 | { 18 | asm volatile("clflush %0" : "+m" (*__p)); 19 | } 20 | 21 | static inline void mfence() 22 | { 23 | asm volatile("mfence":::"memory"); 24 | return; 25 | } 26 | 27 | static inline void flush_cache(void *ptr, size_t size){ 28 | /* 29 | #ifdef _ENABLE_PMEMIO 30 | pmem_persist((const void*)ptr, size); 31 | #else 32 | unsigned int i=0; 33 | uint64_t addr = (uint64_t)ptr; 34 | 35 | mfence(); 36 | for (i =0; i < size; i=i+CACHE_LINE_SIZE) { 37 | clflush((volatile char*)addr); 38 | addr += CACHE_LINE_SIZE; 39 | } 40 | mfence(); 41 | #endif 42 | */ 43 | } 44 | 45 | static inline void memcpy_persist 46 | (void *dest, void *src, size_t size){ 47 | 48 | #ifdef _ENABLE_PMEMIO 49 | pmem_memcpy_persist(dest, (const void *)src, size); 50 | #else 51 | //unsigned int i=0; 52 | //uint64_t addr = (uint64_t)dest; 53 | memcpy(dest, src, size); 54 | 55 | //mfence(); 56 | //for (i =0; i < size; i=i+CACHE_LINE_SIZE) { 57 | // clflush((volatile char*)addr); 58 | // addr += CACHE_LINE_SIZE; 59 | //} 60 | //mfence(); 61 | #endif 62 | 63 | } 64 | #endif 65 | -------------------------------------------------------------------------------- /leveldb-1.20/db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /hoard/include/util/array.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_ARRAY_H 29 | #define HOARD_ARRAY_H 30 | 31 | #include 32 | 33 | namespace Hoard { 34 | 35 | template 36 | class Array { 37 | public: 38 | 39 | inline T& operator()(unsigned long index) { 40 | assert (index < N); 41 | return _item[index]; 42 | } 43 | 44 | inline const T& operator()(unsigned long index) const { 45 | assert (index < N); 46 | return _item[index]; 47 | } 48 | 49 | private: 50 | 51 | T _item[N]; 52 | 53 | }; 54 | 55 | } 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /hoard/include/util/lockmallocheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | 29 | #ifndef HOARD_LOCKMALLOCHEAP_H 30 | #define HOARD_LOCKMALLOCHEAP_H 31 | 32 | // Just lock malloc (unlike LockedHeap, which locks both malloc and 33 | // free). Meant to be combined with something like RedirectFree, which will 34 | // implement free. 35 | 36 | namespace Hoard { 37 | 38 | template 39 | class LockMallocHeap : public Heap { 40 | public: 41 | MALLOC_FUNCTION INLINE void * malloc (size_t sz) { 42 | HL::Guard l (*this); 43 | return Heap::malloc (sz); 44 | } 45 | }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /leveldb-1.20/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/combining/tryheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_TRYHEAP_H 28 | #define HL_TRYHEAP_H 29 | 30 | namespace HL { 31 | 32 | template 33 | class TryHeap : public Heap2 { 34 | public: 35 | 36 | TryHeap (void) 37 | {} 38 | 39 | inline void * malloc (size_t sz) { 40 | void * ptr = heap1.malloc (sz); 41 | if (ptr == NULL) 42 | ptr = Heap2::malloc (sz); 43 | return ptr; 44 | } 45 | 46 | inline void free (void * ptr) { 47 | heap1.free (ptr); 48 | } 49 | 50 | private: 51 | Heap1 heap1; 52 | }; 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /leveldb-1.20/util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += static_cast(data[2]) << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += static_cast(data[1]) << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += static_cast(data[0]); 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /hoard/heaplayers/arch-specific/mallocinfo.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_MALLOCINFO_H 28 | #define HL_MALLOCINFO_H 29 | 30 | #include 31 | 32 | namespace HL { 33 | 34 | class MallocInfo { 35 | public: 36 | // Prevent integer overflows by restricting allocation size (usually 2GB). 37 | enum { MaxSize = UINT_MAX / 2 }; 38 | 39 | #if defined(__LP64__) || defined(_LP64) || defined(__APPLE__) || defined(_WIN64) 40 | enum { MinSize = 16 }; 41 | enum { Alignment = 16 }; 42 | #else 43 | enum { MinSize = sizeof(double) }; 44 | enum { Alignment = sizeof(double) }; 45 | #endif 46 | }; 47 | 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/utility/nullheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_NULLHEAP_H 28 | #define HL_NULLHEAP_H 29 | 30 | #include 31 | 32 | /** 33 | * @class NullHeap 34 | * @brief A source heap that does nothing. 35 | */ 36 | 37 | namespace HL { 38 | 39 | template 40 | class NullHeap : public SuperHeap { 41 | public: 42 | inline void * malloc (size_t) const { return 0; } 43 | inline void free (void *) const {} 44 | inline int remove (void *) const { return 0; } 45 | inline void clear (void) const {} 46 | inline size_t getSize (void *) const { return 0; } 47 | }; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /hoard/include/util/fixedrequestheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_FIXEDREQUESTHEAP_H 29 | #define HOARD_FIXEDREQUESTHEAP_H 30 | 31 | /** 32 | * @class FixedRequestHeap 33 | * @brief Always grabs the same size, regardless of the request size. 34 | */ 35 | 36 | namespace Hoard { 37 | 38 | template 40 | class FixedRequestHeap : public SuperHeap { 41 | public: 42 | inline void * malloc (size_t) { 43 | return SuperHeap::malloc (RequestSize); 44 | } 45 | inline static size_t getSize (void *) { 46 | return RequestSize; 47 | } 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /hoard/include/util/mmapalloc.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_MMAPALLOC_H 29 | #define HOARD_MMAPALLOC_H 30 | 31 | #include "mmapwrapper.h" 32 | 33 | /** 34 | * @class MmapAlloc 35 | * @brief Obtains memory from Mmap but doesn't allow it to be freed. 36 | * @author Emery Berger 37 | */ 38 | 39 | namespace Hoard { 40 | 41 | class MmapAlloc { 42 | public: 43 | 44 | enum { Alignment = HL::MmapWrapper::Alignment }; 45 | 46 | static void * malloc (size_t sz) { 47 | void * ptr = HL::MmapWrapper::map (sz); 48 | return ptr; 49 | } 50 | 51 | }; 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /hoard/include/util/exactlyoneheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HL_EXACTLYONEHEAP_H 29 | #define HL_EXACTLYONEHEAP_H 30 | 31 | #include "exactlyone.h" 32 | 33 | namespace Hoard { 34 | 35 | template 36 | class ExactlyOneHeap : public Hoard::ExactlyOne { 37 | public: 38 | 39 | enum { Alignment = Heap::Alignment }; 40 | 41 | inline void * malloc (size_t sz) { 42 | return (*this)().malloc (sz); 43 | } 44 | inline void free (void * ptr) { 45 | (*this)().free (ptr); 46 | } 47 | inline size_t getSize (void * ptr) { 48 | return (*this)().getSize (ptr); 49 | } 50 | }; 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /leveldb-1.20/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // Parse a human-readable number from "*in" into *value. On success, 36 | // advances "*in" past the consumed number and sets "*val" to the 37 | // numeric value. Otherwise, returns false and leaves *in in an 38 | // unspecified state. 39 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 40 | 41 | } // namespace leveldb 42 | 43 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 44 | -------------------------------------------------------------------------------- /leveldb-1.20/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 6 | #define STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 7 | 8 | // Some environments provide custom macros to aid in static thread-safety 9 | // analysis. Provide empty definitions of such macros unless they are already 10 | // defined. 11 | 12 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 13 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 14 | #endif 15 | 16 | #ifndef SHARED_LOCKS_REQUIRED 17 | #define SHARED_LOCKS_REQUIRED(...) 18 | #endif 19 | 20 | #ifndef LOCKS_EXCLUDED 21 | #define LOCKS_EXCLUDED(...) 22 | #endif 23 | 24 | #ifndef LOCK_RETURNED 25 | #define LOCK_RETURNED(x) 26 | #endif 27 | 28 | #ifndef LOCKABLE 29 | #define LOCKABLE 30 | #endif 31 | 32 | #ifndef SCOPED_LOCKABLE 33 | #define SCOPED_LOCKABLE 34 | #endif 35 | 36 | #ifndef EXCLUSIVE_LOCK_FUNCTION 37 | #define EXCLUSIVE_LOCK_FUNCTION(...) 38 | #endif 39 | 40 | #ifndef SHARED_LOCK_FUNCTION 41 | #define SHARED_LOCK_FUNCTION(...) 42 | #endif 43 | 44 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 45 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 46 | #endif 47 | 48 | #ifndef SHARED_TRYLOCK_FUNCTION 49 | #define SHARED_TRYLOCK_FUNCTION(...) 50 | #endif 51 | 52 | #ifndef UNLOCK_FUNCTION 53 | #define UNLOCK_FUNCTION(...) 54 | #endif 55 | 56 | #ifndef NO_THREAD_SAFETY_ANALYSIS 57 | #define NO_THREAD_SAFETY_ANALYSIS 58 | #endif 59 | 60 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H_ 61 | -------------------------------------------------------------------------------- /hoard/include/hoard/hoardconstants.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | 29 | #ifndef HOARD_HOARDCONSTANTS_H 30 | #define HOARD_HOARDCONSTANTS_H 31 | 32 | namespace Hoard { 33 | 34 | /// The maximum amount of memory that each TLAB may hold, in bytes. 35 | enum { MAX_MEMORY_PER_TLAB = 256 * 1024 }; 36 | 37 | /// The maximum number of threads supported (sort of). 38 | enum { MaxThreads = 2048 }; 39 | 40 | /// The maximum number of heaps supported. 41 | enum { NumHeaps = 128 }; 42 | 43 | /// Size, in bytes, of the largest object we will cache on a 44 | /// thread-local allocation buffer. 45 | enum { LargestSmallObject = 256 }; 46 | 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/debug/checkheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_CHECKHEAP_H_ 4 | #define HL_CHECKHEAP_H_ 5 | 6 | #include 7 | 8 | /** 9 | * @class CheckHeap 10 | * @brief Performs simple checks on memory allocations. 11 | * 12 | **/ 13 | 14 | namespace HL { 15 | 16 | template 17 | class CheckHeap : public SuperHeap { 18 | private: 19 | 20 | enum { RECEIVED_A_NULL_OBJECT_FROM_MALLOC = 0 }; 21 | enum { RECEIVED_AN_UNALIGNED_OBJECT_FROM_MALLOC = 0 }; 22 | 23 | public: 24 | 25 | inline void * malloc (size_t sz) { 26 | void * addr = SuperHeap::malloc (sz); 27 | #if !defined(NDEBUG) 28 | 29 | // Check for null (this should in general not happen). 30 | if (addr == NULL) { 31 | assert (RECEIVED_A_NULL_OBJECT_FROM_MALLOC); 32 | printf ("RECEIVED_A_NULL_OBJECT_FROM_MALLOC\n"); 33 | abort(); 34 | } 35 | // Ensure object size is correct. 36 | assert (SuperHeap::getSize(addr) >= sz); 37 | 38 | // Check alignment. 39 | if ((unsigned long) addr % SuperHeap::Alignment != 0) { 40 | assert (RECEIVED_AN_UNALIGNED_OBJECT_FROM_MALLOC); 41 | printf ("RECEIVED_AN_UNALIGNED_OBJECT_FROM_MALLOC\n"); 42 | abort(); 43 | } 44 | 45 | // Wipe out the old contents. 46 | std::memset (addr, 0, SuperHeap::getSize(addr)); 47 | #endif 48 | return addr; 49 | } 50 | 51 | inline void free (void * ptr) { 52 | #if !defined(NDEBUG) 53 | // Wipe out the old contents. 54 | std::memset (ptr, 0, SuperHeap::getSize(ptr)); 55 | #endif 56 | SuperHeap::free (ptr); 57 | } 58 | 59 | }; 60 | 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace port { 13 | 14 | static void PthreadCall(const char* label, int result) { 15 | if (result != 0) { 16 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 17 | abort(); 18 | } 19 | } 20 | 21 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 22 | 23 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 24 | 25 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 26 | 27 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 28 | 29 | CondVar::CondVar(Mutex* mu) 30 | : mu_(mu) { 31 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 32 | } 33 | 34 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 35 | 36 | void CondVar::Wait() { 37 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 38 | } 39 | 40 | void CondVar::Signal() { 41 | PthreadCall("signal", pthread_cond_signal(&cv_)); 42 | } 43 | 44 | void CondVar::SignalAll() { 45 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 46 | } 47 | 48 | void InitOnce(OnceType* once, void (*initializer)()) { 49 | PthreadCall("once", pthread_once(once, initializer)); 50 | } 51 | 52 | } // namespace port 53 | } // namespace leveldb 54 | -------------------------------------------------------------------------------- /util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /leveldb-1.20/port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace port { 13 | 14 | static void PthreadCall(const char* label, int result) { 15 | if (result != 0) { 16 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 17 | abort(); 18 | } 19 | } 20 | 21 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 22 | 23 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 24 | 25 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 26 | 27 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 28 | 29 | CondVar::CondVar(Mutex* mu) 30 | : mu_(mu) { 31 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 32 | } 33 | 34 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 35 | 36 | void CondVar::Wait() { 37 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 38 | } 39 | 40 | void CondVar::Signal() { 41 | PthreadCall("signal", pthread_cond_signal(&cv_)); 42 | } 43 | 44 | void CondVar::SignalAll() { 45 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 46 | } 47 | 48 | void InitOnce(OnceType* once, void (*initializer)()) { 49 | PthreadCall("once", pthread_once(once, initializer)); 50 | } 51 | 52 | } // namespace port 53 | } // namespace leveldb 54 | -------------------------------------------------------------------------------- /leveldb-1.20/util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/threads/sizethreadheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | #ifndef _SIZETHREADHEAP_H_ 4 | #define _SIZETHREADHEAP_H_ 5 | 6 | #include 7 | #include "cpuinfo.h" 8 | 9 | template 10 | class SizeThreadHeap : public Super { 11 | public: 12 | 13 | inline void * malloc (size_t sz) { 14 | 15 | fprintf(stdout,"CALLING MALLOC %zu \n",sz); 16 | // Add room for a size field & a thread field. 17 | // Both of these must fit in a double. 18 | assert (sizeof(st) <= sizeof(double)); 19 | st * ptr = (st *) Super::malloc (sz + sizeof(double)); 20 | // Store the requested size. 21 | ptr->size = sz; 22 | assert (getOrigPtr(ptr + 1) == ptr); 23 | return (void *) (ptr + 1); 24 | } 25 | 26 | inline void free (void * ptr) { 27 | fprintf(stdout,"sizethreadheap.h: CALLING FREE %zu\n", size (ptr)); 28 | void * origPtr = (void *) getOrigPtr(ptr); 29 | Super::free (origPtr); 30 | } 31 | 32 | static inline size_t& size (void * ptr) { 33 | return getOrigPtr(ptr)->size; 34 | } 35 | 36 | static inline int& thread (void * ptr) { 37 | return getOrigPtr(ptr)->tid; 38 | } 39 | 40 | private: 41 | 42 | typedef struct _st { 43 | size_t size; 44 | int tid; 45 | } st; 46 | 47 | static inline st * getOrigPtr (void * ptr) { 48 | return (st *) ((double *) ptr - 1); 49 | } 50 | 51 | }; 52 | 53 | 54 | 55 | // A platform-dependent way to get a thread id. 56 | 57 | // Include the necessary platform-dependent crud. 58 | #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) 59 | #ifndef WIN32 60 | #define WIN32 1 61 | #endif 62 | #include 63 | #include 64 | #endif 65 | 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /leveldb-1.20/util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | size_t len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /hoard/heaplayers/utility/bins4k.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #if !defined(_BINS4K_H_) 4 | #define _BINS4K_H_ 5 | 6 | #include "bins.h" 7 | #include "sassert.h" 8 | 9 | namespace HL { 10 | 11 | template 12 | class bins { 13 | 14 | public: 15 | bins (void) {} 16 | 17 | enum { NUM_BINS = 33 }; 18 | enum { BIG_OBJECT = 4096 - sizeof(Header) }; 19 | 20 | static const size_t _bins[NUM_BINS]; 21 | 22 | static inline int getSizeClass (size_t sz) { 23 | assert (sz <= BIG_OBJECT); 24 | if (sz < 8) { 25 | return 0; 26 | } else if (sz <= 128) { 27 | return ((sz + 7) >> 3) - 1; 28 | } else { 29 | return slowLookupSizeClass (sz); 30 | } 31 | } 32 | 33 | static inline size_t getClassSize (const int i) { 34 | assert (i >= 0); 35 | assert (i < NUM_BINS); 36 | return _bins[i]; 37 | } 38 | 39 | private: 40 | 41 | static int slowLookupSizeClass (const size_t sz) { 42 | // Find the size class for a given object size 43 | // (the smallest i such that _bins[i] >= sz). 44 | int sizeclass = 0; 45 | while (_bins[sizeclass] < sz) 46 | { 47 | sizeclass++; 48 | assert (sizeclass < NUM_BINS); 49 | } 50 | return sizeclass; 51 | } 52 | 53 | sassert<(BIG_OBJECT > 0)> verifyHeaderSize; 54 | 55 | }; 56 | } 57 | 58 | template 59 | const size_t HL::bins::_bins[NUM_BINS] = {8UL, 16UL, 24UL, 32UL, 40UL, 48UL, 56UL, 64UL, 72UL, 80UL, 88UL, 96UL, 104UL, 112UL, 120UL, 128UL, 152UL, 176UL, 208UL, 248UL, 296UL, 352UL, 416UL, 496UL, 592UL, 704UL, 856UL, 1024UL, 1224UL, 1712UL, 2048UL, 3416UL, 4096UL - sizeof(Header)}; 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/buildingblock/boundedfreelistheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | #ifndef _BOUNDEDFREELISTHEAP_H_ 4 | #define _BOUNDEDFREELISTHEAP_H_ 5 | 6 | // Beware -- this is for one "size class" only!! 7 | 8 | template 9 | class BoundedFreeListHeap : public Super { 10 | public: 11 | 12 | BoundedFreeListHeap (void) 13 | : nObjects (0), 14 | myFreeList (NULL) 15 | {} 16 | 17 | ~BoundedFreeListHeap (void) 18 | { 19 | clear(); 20 | } 21 | 22 | inline void * malloc (size_t sz) { 23 | 24 | fprintf(stdout,"CALLING MALLOC %zu \n",sz); 25 | // Check the free list first. 26 | void * ptr = myFreeList; 27 | if (ptr == NULL) { 28 | ptr = Super::malloc (sz); 29 | } else { 30 | myFreeList = myFreeList->next; 31 | } 32 | return ptr; 33 | } 34 | 35 | inline void free (void * ptr) { 36 | 37 | fprintf(stdout,"CALLING FREE %zu \n",nObjects); 38 | 39 | if (nObjects < numObjects) { 40 | // Add this object to the free list. 41 | ((freeObject *) ptr)->next = myFreeList; 42 | myFreeList = (freeObject *) ptr; 43 | nObjects++; 44 | } else { 45 | clear(); 46 | // Super::free (ptr); 47 | } 48 | } 49 | 50 | inline void clear (void) { 51 | // Delete everything on the free list. 52 | void * ptr = myFreeList; 53 | while (ptr != NULL) { 54 | void * oldptr = ptr; 55 | ptr = (void *) ((freeObject *) ptr)->next; 56 | Super::free (oldptr); 57 | } 58 | myFreeList = NULL; 59 | nObjects = 0; 60 | } 61 | 62 | private: 63 | 64 | class freeObject { 65 | public: 66 | freeObject * next; 67 | }; 68 | 69 | int nObjects; 70 | freeObject * myFreeList; 71 | }; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /hoard/include/util/exactlyone.h: -------------------------------------------------------------------------------- 1 | #ifndef HOARD_EXACTLYONE_H 2 | #define HOARD_EXACTLYONE_H 3 | 4 | /* 5 | 6 | The Hoard Multiprocessor Memory Allocator 7 | www.hoard.org 8 | 9 | Author: Emery Berger, http://www.cs.umass.edu/~emery 10 | 11 | Copyright (c) 1998-2012 Emery Berger 12 | 13 | This program is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program; if not, write to the Free Software 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | 27 | */ 28 | 29 | /** 30 | * @class ExactlyOne 31 | * @brief Creates a singleton of type CLASS, accessed through (). 32 | * @author Emery Berger 33 | */ 34 | 35 | namespace Hoard { 36 | 37 | template 38 | class ExactlyOne { 39 | public: 40 | 41 | virtual ~ExactlyOne() {} 42 | 43 | inline CLASS& operator() (void) { 44 | // We store the singleton in a double buffer to force alignment. 45 | static double buf[(sizeof(CLASS) + sizeof(double) - 1) / sizeof(double)]; 46 | static CLASS * theOneTrueInstancePtr = new (buf) CLASS; 47 | return *theOneTrueInstancePtr; 48 | } 49 | 50 | }; 51 | 52 | } 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /leveldb-1.20/db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | 26 | // Create a writer that will append data to "*dest". 27 | // "*dest" must have initial length "dest_length". 28 | // "*dest" must remain live while this Writer is in use. 29 | Writer(WritableFile* dest, uint64_t dest_length); 30 | 31 | ~Writer(); 32 | 33 | Status AddRecord(const Slice& slice); 34 | 35 | private: 36 | WritableFile* dest_; 37 | int block_offset_; // Current offset in block 38 | 39 | // crc32c values for all supported record types. These are 40 | // pre-computed to reduce the overhead of computing the crc of the 41 | // record type stored in the header. 42 | uint32_t type_crc_[kMaxRecordType + 1]; 43 | 44 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 45 | 46 | // No copying allowed 47 | Writer(const Writer&); 48 | void operator=(const Writer&); 49 | }; 50 | 51 | } // namespace log 52 | } // namespace leveldb 53 | 54 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 55 | -------------------------------------------------------------------------------- /util/affinity.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int setaffinity(int cpuid) 5 | { 6 | int s; 7 | cpu_set_t cpuset; 8 | pthread_t thread; 9 | 10 | thread = pthread_self(); 11 | CPU_ZERO(&cpuset); 12 | CPU_SET(cpuid, &cpuset); 13 | s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); 14 | if (s != 0) 15 | return -1; 16 | return 0; 17 | } 18 | 19 | int setaffinity_arr(int *arr, int count, int index) 20 | { 21 | int s = 0, i = 0; 22 | cpu_set_t cpuset; 23 | pthread_t thread; 24 | 25 | thread = pthread_self(); 26 | CPU_ZERO(&cpuset); 27 | 28 | for (i = 0; i < count; i++) 29 | CPU_SET(arr[index+i], &cpuset); 30 | 31 | s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); 32 | if (s != 0) 33 | return -1; 34 | 35 | return 0; 36 | } 37 | 38 | int getaffinity() 39 | { 40 | int s, j; 41 | cpu_set_t cpuset; 42 | pthread_t thread; 43 | 44 | thread = pthread_self(); 45 | 46 | /* Set affinity mask to include CPUs 0 to 7 */ 47 | CPU_ZERO(&cpuset); 48 | //for (j = 0; j < 8; j++) 49 | //CPU_SET(j, &cpuset); 50 | //s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); 51 | //if (s != 0) 52 | //handle_error_en(s, "pthread_setaffinity_np"); 53 | 54 | /* Check the actual affinity mask assigned to the thread */ 55 | s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset); 56 | if (s != 0) 57 | perror("pthread_getaffinity_np"); 58 | 59 | //printf("Set returned by pthread_getaffinity_np() contained:\n"); 60 | for (j = 0; j < CPU_SETSIZE; j++) 61 | if (CPU_ISSET(j, &cpuset)) 62 | printf(" CPU %d\n", j); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /hoard/include/hoard/statistics.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_STATISTICS_H 29 | #define HOARD_STATISTICS_H 30 | 31 | namespace Hoard { 32 | 33 | class Statistics { 34 | public: 35 | Statistics (void) 36 | : _inUse (0), 37 | _allocated (0) 38 | {} 39 | 40 | inline unsigned int getInUse (void) const { return _inUse; } 41 | inline unsigned int getAllocated (void) const { return _allocated; } 42 | inline void setInUse (unsigned int u) { _inUse = u; } 43 | inline void setAllocated (unsigned int a) { _allocated = a; } 44 | 45 | private: 46 | 47 | /// The number of objects in use. 48 | unsigned int _inUse; 49 | 50 | /// The number of objects allocated. 51 | unsigned int _allocated; 52 | }; 53 | 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /leveldb-1.20/db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/write_batch.h" 10 | 11 | namespace leveldb { 12 | 13 | class MemTable; 14 | 15 | // WriteBatchInternal provides static methods for manipulating a 16 | // WriteBatch that we don't want in the public WriteBatch interface. 17 | class WriteBatchInternal { 18 | public: 19 | // Return the number of entries in the batch. 20 | static int Count(const WriteBatch* batch); 21 | 22 | // Set the count for the number of entries in the batch. 23 | static void SetCount(WriteBatch* batch, int n); 24 | 25 | // Return the sequence number for the start of this batch. 26 | static SequenceNumber Sequence(const WriteBatch* batch); 27 | 28 | // Store the specified number as the sequence number for the start of 29 | // this batch. 30 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 31 | 32 | static Slice Contents(const WriteBatch* batch) { 33 | return Slice(batch->rep_); 34 | } 35 | 36 | static size_t ByteSize(const WriteBatch* batch) { 37 | return batch->rep_.size(); 38 | } 39 | 40 | static void SetContents(WriteBatch* batch, const Slice& contents); 41 | 42 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 43 | 44 | static void Append(WriteBatch* dst, const WriteBatch* src); 45 | }; 46 | 47 | } // namespace leveldb 48 | 49 | 50 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 51 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/general/leamallocheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2003 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef _LEAMALLOCHEAP_H_ 28 | #define _LEAMALLOCHEAP_H_ 29 | 30 | #include 31 | 32 | /** 33 | * @class LeaMallocHeap 34 | * @brief A "source heap" that uses the Lea allocator. 35 | */ 36 | 37 | extern "C" void * dlmalloc (size_t); 38 | extern "C" void dlfree (void *); 39 | extern "C" size_t dlmalloc_usable_size (void *); 40 | 41 | namespace HL { 42 | 43 | class LeaMallocHeap { 44 | public: 45 | inline void * malloc (size_t sz) { 46 | void * ptr = dlmalloc (sz); 47 | return ptr; 48 | } 49 | 50 | inline void free (void * p) { 51 | dlfree (p); 52 | } 53 | 54 | inline size_t getSize (const void * p) { 55 | return dlmalloc_usable_size ((void *) p); 56 | } 57 | }; 58 | 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /hoard/heaplayers/locks/maclock.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_MACLOCK_H 28 | #define HL_MACLOCK_H 29 | 30 | #if !defined(__APPLE__) 31 | #error "This file is for Mac only." 32 | #endif 33 | 34 | #include 35 | 36 | /** 37 | * @class MacLockType 38 | * @brief Locking using OS X spin locks. 39 | */ 40 | 41 | namespace HL { 42 | 43 | class MacLockType { 44 | public: 45 | 46 | MacLockType (void) 47 | : mutex (0) 48 | {} 49 | 50 | ~MacLockType (void) 51 | { 52 | mutex = 0; 53 | } 54 | 55 | inline void lock (void) { 56 | OSSpinLockLock (&mutex); 57 | } 58 | 59 | inline void unlock (void) { 60 | OSSpinLockUnlock (&mutex); 61 | } 62 | 63 | private: 64 | 65 | OSSpinLock mutex; 66 | 67 | }; 68 | 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your code patches! However, before we can take them, we 4 | have to jump a couple of legal hurdles. 5 | 6 | ## Contributor License Agreements 7 | 8 | Please fill out either the individual or corporate Contributor License 9 | Agreement as appropriate. 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. 18 | 19 | ## Submitting a Patch 20 | 21 | 1. Sign the contributors license agreement above. 22 | 2. Decide which code you want to submit. A submission should be a set of changes 23 | that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues). 24 | Please don't mix more than one logical change per submission, because it makes 25 | the history hard to follow. If you want to make a change 26 | (e.g. add a sample or feature) that doesn't have a corresponding issue in the 27 | issue tracker, please create one. 28 | 3. **Submitting**: When you are ready to submit, send us a Pull Request. Be 29 | sure to include the issue number you fixed and the name you used to sign 30 | the CLA. 31 | 32 | ## Writing Code ## 33 | 34 | If your contribution contains code, please make sure that it follows 35 | [the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 36 | Otherwise we will have to ask you to make changes, and that's no fun for anyone. 37 | -------------------------------------------------------------------------------- /leveldb-1.20/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love to accept your code patches! However, before we can take them, we 4 | have to jump a couple of legal hurdles. 5 | 6 | ## Contributor License Agreements 7 | 8 | Please fill out either the individual or corporate Contributor License 9 | Agreement as appropriate. 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. 18 | 19 | ## Submitting a Patch 20 | 21 | 1. Sign the contributors license agreement above. 22 | 2. Decide which code you want to submit. A submission should be a set of changes 23 | that addresses one issue in the [issue tracker](https://github.com/google/leveldb/issues). 24 | Please don't mix more than one logical change per submission, because it makes 25 | the history hard to follow. If you want to make a change 26 | (e.g. add a sample or feature) that doesn't have a corresponding issue in the 27 | issue tracker, please create one. 28 | 3. **Submitting**: When you are ready to submit, send us a Pull Request. Be 29 | sure to include the issue number you fixed and the name you used to sign 30 | the CLA. 31 | 32 | ## Writing Code ## 33 | 34 | If your contribution contains code, please make sure that it follows 35 | [the style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml). 36 | Otherwise we will have to ask you to make changes, and that's no fun for anyone. 37 | -------------------------------------------------------------------------------- /db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | }; 23 | 24 | bool HandleDumpCommand(Env* env, char** files, int num) { 25 | StdoutPrinter printer; 26 | bool ok = true; 27 | for (int i = 0; i < num; i++) { 28 | Status s = DumpFile(env, files[i], &printer); 29 | if (!s.ok()) { 30 | fprintf(stderr, "%s\n", s.ToString().c_str()); 31 | ok = false; 32 | } 33 | } 34 | return ok; 35 | } 36 | 37 | } // namespace 38 | } // namespace leveldb 39 | 40 | static void Usage() { 41 | fprintf( 42 | stderr, 43 | "Usage: leveldbutil command...\n" 44 | " dump files... -- dump contents of specified files\n" 45 | ); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | leveldb::Env* env = leveldb::Env::Default(); 50 | bool ok = true; 51 | if (argc < 2) { 52 | Usage(); 53 | ok = false; 54 | } else { 55 | std::string command = argv[1]; 56 | if (command == "dump") { 57 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 58 | } else { 59 | Usage(); 60 | ok = false; 61 | } 62 | } 63 | return (ok ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /leveldb-1.20/db/leveldbutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "leveldb/dumpfile.h" 7 | #include "leveldb/env.h" 8 | #include "leveldb/status.h" 9 | 10 | namespace leveldb { 11 | namespace { 12 | 13 | class StdoutPrinter : public WritableFile { 14 | public: 15 | virtual Status Append(const Slice& data) { 16 | fwrite(data.data(), 1, data.size(), stdout); 17 | return Status::OK(); 18 | } 19 | virtual Status Close() { return Status::OK(); } 20 | virtual Status Flush() { return Status::OK(); } 21 | virtual Status Sync() { return Status::OK(); } 22 | }; 23 | 24 | bool HandleDumpCommand(Env* env, char** files, int num) { 25 | StdoutPrinter printer; 26 | bool ok = true; 27 | for (int i = 0; i < num; i++) { 28 | Status s = DumpFile(env, files[i], &printer); 29 | if (!s.ok()) { 30 | fprintf(stderr, "%s\n", s.ToString().c_str()); 31 | ok = false; 32 | } 33 | } 34 | return ok; 35 | } 36 | 37 | } // namespace 38 | } // namespace leveldb 39 | 40 | static void Usage() { 41 | fprintf( 42 | stderr, 43 | "Usage: leveldbutil command...\n" 44 | " dump files... -- dump contents of specified files\n" 45 | ); 46 | } 47 | 48 | int main(int argc, char** argv) { 49 | leveldb::Env* env = leveldb::Env::Default(); 50 | bool ok = true; 51 | if (argc < 2) { 52 | Usage(); 53 | ok = false; 54 | } else { 55 | std::string command = argv[1]; 56 | if (command == "dump") { 57 | ok = leveldb::HandleDumpCommand(env, argv+2, argc-2); 58 | } else { 59 | Usage(); 60 | ok = false; 61 | } 62 | } 63 | return (ok ? 0 : 1); 64 | } 65 | -------------------------------------------------------------------------------- /util/hash_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /leveldb-1.20/util/hash_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/hash.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | class HASH { }; 11 | 12 | TEST(HASH, SignedUnsignedIssue) { 13 | const unsigned char data1[1] = {0x62}; 14 | const unsigned char data2[2] = {0xc3, 0x97}; 15 | const unsigned char data3[3] = {0xe2, 0x99, 0xa5}; 16 | const unsigned char data4[4] = {0xe1, 0x80, 0xb9, 0x32}; 17 | const unsigned char data5[48] = { 18 | 0x01, 0xc0, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 20 | 0x00, 0x00, 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x14, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x04, 0x00, 24 | 0x00, 0x00, 0x00, 0x14, 25 | 0x00, 0x00, 0x00, 0x18, 26 | 0x28, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 28 | 0x02, 0x00, 0x00, 0x00, 29 | 0x00, 0x00, 0x00, 0x00, 30 | }; 31 | 32 | ASSERT_EQ(Hash(0, 0, 0xbc9f1d34), 0xbc9f1d34); 33 | ASSERT_EQ( 34 | Hash(reinterpret_cast(data1), sizeof(data1), 0xbc9f1d34), 35 | 0xef1345c4); 36 | ASSERT_EQ( 37 | Hash(reinterpret_cast(data2), sizeof(data2), 0xbc9f1d34), 38 | 0x5b663814); 39 | ASSERT_EQ( 40 | Hash(reinterpret_cast(data3), sizeof(data3), 0xbc9f1d34), 41 | 0x323c078f); 42 | ASSERT_EQ( 43 | Hash(reinterpret_cast(data4), sizeof(data4), 0xbc9f1d34), 44 | 0xed21633a); 45 | ASSERT_EQ( 46 | Hash(reinterpret_cast(data5), sizeof(data5), 0x12345678), 47 | 0xf333dabb); 48 | } 49 | 50 | } // namespace leveldb 51 | 52 | int main(int argc, char** argv) { 53 | return leveldb::test::RunAllTests(); 54 | } 55 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/utility/exceptionheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_EXCEPTIONHEAP_H 28 | #define HL_EXCEPTIONHEAP_H 29 | 30 | #include 31 | #include 32 | 33 | class std::bad_alloc; 34 | 35 | namespace HL { 36 | 37 | template 38 | class ExceptionHeap : public Super { 39 | public: 40 | inline void * malloc (size_t sz) throw (std::bad_alloc) { 41 | void * ptr = Super::malloc (sz); 42 | if (ptr == NULL) { 43 | throw new std::bad_alloc; 44 | } 45 | return ptr; 46 | } 47 | }; 48 | 49 | 50 | template 51 | class CatchExceptionHeap : public Super { 52 | public: 53 | inline void * malloc (size_t sz) { 54 | void * ptr; 55 | try { 56 | ptr = Super::malloc (sz); 57 | } catch (std::bad_alloc) { 58 | ptr = NULL; 59 | } 60 | return ptr; 61 | } 62 | }; 63 | 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /hoard/include/hoard/emptyhoardmanager.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | 4 | /* 5 | 6 | The Hoard Multiprocessor Memory Allocator 7 | www.hoard.org 8 | 9 | Author: Emery Berger, http://www.cs.umass.edu/~emery 10 | 11 | Copyright (c) 1998-2012 Emery Berger 12 | 13 | This program is free software; you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation; either version 2 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program; if not, write to the Free Software 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 | 27 | */ 28 | 29 | #ifndef HOARD_EMPTYHOARDMANAGER_H 30 | #define HOARD_EMPTYHOARDMANAGER_H 31 | 32 | #include "basehoardmanager.h" 33 | #include "sassert.h" 34 | 35 | namespace Hoard { 36 | 37 | template 38 | class EmptyHoardManager : public BaseHoardManager { 39 | public: 40 | 41 | EmptyHoardManager (void) 42 | : _magic (0x1d2d3d40) 43 | {} 44 | 45 | int isValid (void) const { 46 | return (_magic == 0x1d2d3d40); 47 | } 48 | 49 | typedef SuperblockType_ SuperblockType; 50 | 51 | void free (void *) { abort(); } 52 | void lock (void) {} 53 | void unlock (void) {} 54 | 55 | SuperblockType * get (size_t, EmptyHoardManager *) { abort(); return NULL; } 56 | void put (SuperblockType *, size_t) { abort(); } 57 | 58 | private: 59 | 60 | unsigned long _magic; 61 | 62 | }; 63 | 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /hoard/heaplayers/locks/posixlock.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_POSIXLOCK_H 28 | #define HL_POSIXLOCK_H 29 | 30 | #if !defined(_WIN32) 31 | 32 | #include 33 | 34 | /** 35 | * @class PosixLockType 36 | * @brief Locking using POSIX mutex objects. 37 | */ 38 | 39 | namespace HL { 40 | 41 | class PosixLockType { 42 | public: 43 | 44 | PosixLockType (void) 45 | { 46 | int r = pthread_mutex_init (&mutex, NULL); 47 | if (r) { 48 | throw 0; 49 | } 50 | } 51 | 52 | ~PosixLockType (void) 53 | { 54 | pthread_mutex_destroy (&mutex); 55 | } 56 | 57 | void lock (void) { 58 | pthread_mutex_lock (&mutex); 59 | } 60 | 61 | void unlock (void) { 62 | pthread_mutex_unlock (&mutex); 63 | } 64 | 65 | private: 66 | union { 67 | pthread_mutex_t mutex; 68 | double _dummy[sizeof(pthread_mutex_t)/sizeof(double) + 1]; 69 | }; 70 | }; 71 | 72 | } 73 | 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /leveldb-1.20/issues/issue200_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2013 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // Test for issue 200: when iterator switches direction from backward 6 | // to forward, the current key can be yielded unexpectedly if a new 7 | // mutation has been added just before the current key. 8 | 9 | #include "leveldb/db.h" 10 | #include "util/testharness.h" 11 | 12 | namespace leveldb { 13 | 14 | class Issue200 { }; 15 | 16 | TEST(Issue200, Test) { 17 | // Get rid of any state from an old run. 18 | std::string dbpath = test::TmpDir() + "/leveldb_issue200_test"; 19 | DestroyDB(dbpath, Options()); 20 | 21 | DB *db; 22 | Options options; 23 | options.create_if_missing = true; 24 | ASSERT_OK(DB::Open(options, dbpath, &db)); 25 | 26 | WriteOptions write_options; 27 | ASSERT_OK(db->Put(write_options, "1", "b")); 28 | ASSERT_OK(db->Put(write_options, "2", "c")); 29 | ASSERT_OK(db->Put(write_options, "3", "d")); 30 | ASSERT_OK(db->Put(write_options, "4", "e")); 31 | ASSERT_OK(db->Put(write_options, "5", "f")); 32 | 33 | ReadOptions read_options; 34 | Iterator *iter = db->NewIterator(read_options); 35 | 36 | // Add an element that should not be reflected in the iterator. 37 | ASSERT_OK(db->Put(write_options, "25", "cd")); 38 | 39 | iter->Seek("5"); 40 | ASSERT_EQ(iter->key().ToString(), "5"); 41 | iter->Prev(); 42 | ASSERT_EQ(iter->key().ToString(), "4"); 43 | iter->Prev(); 44 | ASSERT_EQ(iter->key().ToString(), "3"); 45 | iter->Next(); 46 | ASSERT_EQ(iter->key().ToString(), "4"); 47 | iter->Next(); 48 | ASSERT_EQ(iter->key().ToString(), "5"); 49 | 50 | delete iter; 51 | delete db; 52 | DestroyDB(dbpath, options); 53 | } 54 | 55 | } // namespace leveldb 56 | 57 | int main(int argc, char** argv) { 58 | return leveldb::test::RunAllTests(); 59 | } 60 | -------------------------------------------------------------------------------- /util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /leveldb-1.20/db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "db/dbformat.h" 9 | #include "leveldb/db.h" 10 | 11 | namespace leveldb { 12 | 13 | class SnapshotList; 14 | 15 | // Snapshots are kept in a doubly-linked list in the DB. 16 | // Each SnapshotImpl corresponds to a particular sequence number. 17 | class SnapshotImpl : public Snapshot { 18 | public: 19 | SequenceNumber number_; // const after creation 20 | 21 | private: 22 | friend class SnapshotList; 23 | 24 | // SnapshotImpl is kept in a doubly-linked circular list 25 | SnapshotImpl* prev_; 26 | SnapshotImpl* next_; 27 | 28 | SnapshotList* list_; // just for sanity checks 29 | }; 30 | 31 | class SnapshotList { 32 | public: 33 | SnapshotList() { 34 | list_.prev_ = &list_; 35 | list_.next_ = &list_; 36 | } 37 | 38 | bool empty() const { return list_.next_ == &list_; } 39 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 40 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 41 | 42 | const SnapshotImpl* New(SequenceNumber seq) { 43 | SnapshotImpl* s = new SnapshotImpl; 44 | s->number_ = seq; 45 | s->list_ = this; 46 | s->next_ = &list_; 47 | s->prev_ = list_.prev_; 48 | s->prev_->next_ = s; 49 | s->next_->prev_ = s; 50 | return s; 51 | } 52 | 53 | void Delete(const SnapshotImpl* s) { 54 | assert(s->list_ == this); 55 | s->prev_->next_ = s->next_; 56 | s->next_->prev_ = s->prev_; 57 | delete s; 58 | } 59 | 60 | private: 61 | // Dummy head of doubly-linked list of snapshots 62 | SnapshotImpl list_; 63 | }; 64 | 65 | } // namespace leveldb 66 | 67 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 68 | -------------------------------------------------------------------------------- /leveldb-1.20/util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (size_t b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (size_t i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (size_t b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /leveldb-1.20/table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/threads/lockedheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_LOCKEDHEAP_H 28 | #define HL_LOCKEDHEAP_H 29 | 30 | #include "guard.h" 31 | 32 | namespace HL { 33 | 34 | template 35 | class LockedHeap : public Super { 36 | public: 37 | 38 | enum { Alignment = Super::Alignment }; 39 | 40 | inline void * malloc (size_t sz) { 41 | Guard l (thelock); 42 | return Super::malloc (sz); 43 | } 44 | 45 | inline void free (void * ptr) { 46 | Guard l (thelock); 47 | Super::free (ptr); 48 | } 49 | 50 | inline size_t getSize (void * ptr) { 51 | Guard l (thelock); 52 | return Super::getSize (ptr); 53 | } 54 | 55 | inline void lock (void) { 56 | thelock.lock(); 57 | } 58 | 59 | inline void unlock (void) { 60 | thelock.unlock(); 61 | } 62 | 63 | private: 64 | // char dummy[128]; // an effort to avoid false sharing. 65 | LockType thelock; 66 | }; 67 | 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /hoard/heaplayers/threads/fred.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | #ifndef HL_FRED_H 4 | #define HL_FRED_H 5 | 6 | /// A thread-wrapper of childlike simplicity :). 7 | 8 | #if defined(_WIN32) 9 | 10 | #include 11 | #include 12 | 13 | #elif defined(__SVR4) 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #else 20 | 21 | #include 22 | #include 23 | 24 | #endif 25 | 26 | namespace HL { 27 | 28 | extern "C" typedef void * (*ThreadFunctionType) (void *); 29 | 30 | class Fred { 31 | public: 32 | 33 | Fred (void) { 34 | #if !defined(_WIN32) 35 | pthread_attr_init (&attr); 36 | #endif 37 | } 38 | 39 | ~Fred (void) { 40 | #if !defined(_WIN32) 41 | pthread_attr_destroy (&attr); 42 | #endif 43 | } 44 | 45 | void create (ThreadFunctionType function, void * arg) { 46 | #if defined(_WIN32) 47 | t = CreateThread (0, 0, (LPTHREAD_START_ROUTINE) *function, (LPVOID) arg, 0, 0); 48 | #else 49 | pthread_create (&t, &attr, function, arg); 50 | #endif 51 | } 52 | 53 | void join (void) { 54 | #if defined(_WIN32) 55 | WaitForSingleObject (t, INFINITE); 56 | #else 57 | pthread_join (t, NULL); 58 | #endif 59 | } 60 | 61 | static void yield (void) { 62 | #if defined(_WIN32) 63 | Sleep (0); 64 | #elif defined(__SVR4) 65 | thr_yield(); 66 | #else 67 | sched_yield(); 68 | #endif 69 | } 70 | 71 | 72 | static void setConcurrency (int n) { 73 | #if defined(_WIN32) 74 | #elif defined(__SVR4) 75 | thr_setconcurrency (n); 76 | #else 77 | pthread_setconcurrency (n); 78 | #endif 79 | } 80 | 81 | 82 | private: 83 | 84 | Fred (const Fred&); 85 | Fred& operator=(const Fred&); 86 | 87 | #if defined(_WIN32) 88 | typedef HANDLE FredType; 89 | #else 90 | typedef pthread_t FredType; 91 | pthread_attr_t attr; 92 | #endif 93 | 94 | FredType t; 95 | }; 96 | 97 | } 98 | 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /leveldb-1.20/table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been called since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /leveldb-1.20/util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (size_t i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /leveldb-1.20/util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 49 | uint64_t v = 0; 50 | int digits = 0; 51 | while (!in->empty()) { 52 | char c = (*in)[0]; 53 | if (c >= '0' && c <= '9') { 54 | ++digits; 55 | const int delta = (c - '0'); 56 | static const uint64_t kMaxUint64 = ~static_cast(0); 57 | if (v > kMaxUint64/10 || 58 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 59 | // Overflow 60 | return false; 61 | } 62 | v = (v * 10) + delta; 63 | in->remove_prefix(1); 64 | } else { 65 | break; 66 | } 67 | } 68 | *val = v; 69 | return (digits > 0); 70 | } 71 | 72 | } // namespace leveldb 73 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/utility/oneheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2003 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | #ifndef HL_ONEHEAP_H 28 | #define HL_ONEHEAP_H 29 | 30 | // 31 | // Wrap a single instance of a heap. 32 | // 33 | 34 | namespace HL { 35 | 36 | template 37 | class OneHeap { 38 | public: 39 | OneHeap (void) 40 | : theHeap (getHeap()) 41 | {} 42 | 43 | inline void * malloc (const size_t sz) { 44 | return theHeap->malloc (sz); 45 | } 46 | inline void free (void * ptr) { 47 | theHeap->free (ptr); 48 | } 49 | inline int remove (void * ptr) { 50 | return theHeap->remove (ptr); 51 | } 52 | inline void clear (void) { 53 | theHeap->clear(); 54 | } 55 | inline size_t getSize (void * ptr) { 56 | return theHeap->getSize (ptr); 57 | } 58 | 59 | enum { Alignment = SuperHeap::Alignment }; 60 | 61 | private: 62 | 63 | SuperHeap * theHeap; 64 | 65 | inline static SuperHeap * getHeap (void) { 66 | static SuperHeap theHeap; 67 | return &theHeap; 68 | } 69 | }; 70 | 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /leveldb-1.20/util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /leveldb-1.20/util/arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "port/port.h" 13 | 14 | namespace leveldb { 15 | 16 | class Arena { 17 | public: 18 | Arena(); 19 | ~Arena(); 20 | 21 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 22 | char* Allocate(size_t bytes); 23 | 24 | // Allocate memory with the normal alignment guarantees provided by malloc 25 | char* AllocateAligned(size_t bytes); 26 | 27 | // Returns an estimate of the total memory usage of data allocated 28 | // by the arena. 29 | size_t MemoryUsage() const { 30 | return reinterpret_cast(memory_usage_.NoBarrier_Load()); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Total memory usage of the arena. 45 | port::AtomicPointer memory_usage_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /hoard/include/util/releaseheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_RELEASEHEAP_H 29 | #define HOARD_RELEASEHEAP_H 30 | 31 | #if defined(_WIN32) 32 | #include 33 | #else 34 | // Assume UNIX 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #endif 41 | 42 | #include "sassert.h" 43 | 44 | namespace Hoard { 45 | 46 | template 47 | class ReleaseHeap : public SuperHeap { 48 | public: 49 | 50 | enum { Alignment = SuperHeap::Alignment }; 51 | 52 | ReleaseHeap() { 53 | // This heap is only safe for use when its superheap delivers 54 | // page-aligned memory. Otherwise, it would run the risk of 55 | // releasing memory that is still in use. 56 | sassert<(Alignment % 4096 == 0)> ObjectsMustBePageAligned; 57 | } 58 | 59 | inline void free (void * ptr) { 60 | // Tell the OS it can release memory associated with this object. 61 | MmapWrapper::release (ptr, SuperHeap::getSize(ptr)); 62 | // Now give it to the superheap. 63 | SuperHeap::free (ptr); 64 | } 65 | 66 | }; 67 | 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/top/staticheap.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | Heap Layers: An Extensible Memory Allocation Infrastructure 6 | 7 | Copyright (C) 2000-2012 by Emery Berger 8 | http://www.cs.umass.edu/~emery 9 | emery@cs.umass.edu 10 | 11 | This program is free software; you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation; either version 2 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | 25 | */ 26 | 27 | /* 28 | 29 | StaticHeap: manage a fixed range of memory. 30 | 31 | */ 32 | 33 | #ifndef HL_STATICHEAP_H 34 | #define HL_STATICHEAP_H 35 | 36 | namespace HL { 37 | 38 | template 39 | class StaticHeap { 40 | public: 41 | 42 | StaticHeap (void) 43 | : ptr (&buf[0]), 44 | remaining (MemorySize) 45 | {} 46 | 47 | enum { Alignment = 1 }; 48 | 49 | inline void * malloc (size_t sz) { 50 | if (remaining < sz) { 51 | return NULL; 52 | } 53 | void * p = ptr; 54 | ptr += sz; 55 | remaining -= sz; 56 | return p; 57 | } 58 | 59 | void free (void *) {} 60 | int remove (void *) { return 0; } 61 | 62 | int isValid (void * ptr) { 63 | return (((size_t) ptr >= (size_t) buf) && 64 | ((size_t) ptr < (size_t) buf)); 65 | } 66 | 67 | private: 68 | 69 | // Disable copying and assignment. 70 | StaticHeap (const StaticHeap& treap); 71 | StaticHeap& operator= (const StaticHeap& treap); 72 | 73 | char buf[MemorySize]; 74 | char * ptr; 75 | size_t remaining; 76 | }; 77 | 78 | }; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 55 | 56 | 57 | 58 | private: 59 | friend class WriteBatchInternal; 60 | 61 | // Intentionally copyable 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 67 | -------------------------------------------------------------------------------- /leveldb-1.20/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /hoard/heaplayers/heaps/objectrep/addheap.h: -------------------------------------------------------------------------------- 1 | /* -*- C++ -*- */ 2 | 3 | #ifndef HL_ADDHEAP_H 4 | #define HL_ADDHEAP_H 5 | 6 | /* 7 | 8 | Heap Layers: An Extensible Memory Allocation Infrastructure 9 | 10 | Copyright (C) 2000-2012 by Emery Berger 11 | http://www.cs.umass.edu/~emery 12 | emery@cs.umass.edu 13 | 14 | This program is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU General Public License as published by 16 | the Free Software Foundation; either version 2 of the License, or 17 | (at your option) any later version. 18 | 19 | This program is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | 24 | You should have received a copy of the GNU General Public License 25 | along with this program; if not, write to the Free Software 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 | 28 | */ 29 | 30 | // Reserve space for a class in the head of every allocated object. 31 | 32 | #include 33 | #include "lcm.h" 34 | 35 | namespace HL { 36 | 37 | template 38 | class AddHeap : public SuperHeap { 39 | public: 40 | 41 | inline void * malloc (size_t sz) { 42 | void * ptr = SuperHeap::malloc (sz + HeaderSize); 43 | void * newPtr = (char *) ptr + HeaderSize; 44 | return newPtr; 45 | } 46 | 47 | inline void free (void * ptr) { 48 | SuperHeap::free (getOriginal(ptr)); 49 | } 50 | 51 | inline size_t getSize (void * ptr) { 52 | return SuperHeap::getSize (getOriginal(ptr)); 53 | } 54 | 55 | private: 56 | 57 | inline void * getOriginal (void * ptr) { 58 | void * origPtr = (void *) ((char *) ptr - HeaderSize); 59 | return origPtr; 60 | } 61 | 62 | // A size that preserves existing alignment restrictions. 63 | // Beware: can seriously increase size requirements. 64 | enum { HeaderSize = lcm<(int) SuperHeap::Alignment, sizeof(Add)>::value }; 65 | 66 | }; 67 | 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /hoard/include/util/check.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | 3 | /* 4 | 5 | The Hoard Multiprocessor Memory Allocator 6 | www.hoard.org 7 | 8 | Author: Emery Berger, http://www.cs.umass.edu/~emery 9 | 10 | Copyright (c) 1998-2012 Emery Berger 11 | 12 | This program is free software; you can redistribute it and/or modify 13 | it under the terms of the GNU General Public License as published by 14 | the Free Software Foundation; either version 2 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program; if not, write to the Free Software 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 | 26 | */ 27 | 28 | #ifndef HOARD_CHECK_H 29 | #define HOARD_CHECK_H 30 | 31 | /** 32 | * @class Check 33 | * @brief Checks preconditions and postconditions on construction and destruction. 34 | * 35 | * Example usage: 36 | * 37 | * in a method of ThisClass: 38 | * 39 | * void foo() { 40 | * Check t (this); 41 | * .... 42 | * } 43 | * 44 | * and defined in ThisClass: 45 | * 46 | * class ThisClassChecker { 47 | * public: 48 | * static void precondition (ThisClass * obj) { ... } 49 | * static void postcondition (ThisClass * obj) { ... } 50 | * 51 | **/ 52 | 53 | namespace Hoard { 54 | 55 | template 56 | class Check { 57 | public: 58 | Check (TYPE * t) 59 | #ifndef NDEBUG 60 | : _object (t) 61 | #endif 62 | { 63 | #ifndef NDEBUG 64 | CHECK::precondition (_object); 65 | #endif 66 | } 67 | 68 | ~Check (void) { 69 | #ifndef NDEBUG 70 | CHECK::postcondition (_object); 71 | #endif 72 | } 73 | 74 | private: 75 | Check (const Check&); 76 | Check& operator=(const Check&); 77 | 78 | #ifndef NDEBUG 79 | TYPE * _object; 80 | #endif 81 | 82 | }; 83 | 84 | } 85 | #endif 86 | --------------------------------------------------------------------------------