Commit a82a6c69 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

[t:4934] Get rid of 4934 stuff from main. Refs #4934.

git-svn-id: file:///svn/toku/tokudb@44659 c7de825b-a66e-492c-adef-691d508d4ae1
parent 715928f5
...@@ -51,16 +51,16 @@ int madvise (void *addr, size_t length, int advice) { ...@@ -51,16 +51,16 @@ int madvise (void *addr, size_t length, int advice) {
char *m=mem; char *m=mem;
if (counter==0) { if (counter==0) {
assert(m+4096==a); assert(m+4096==a);
assert(length==16*1024*1024-4096); assert(length=16*1024*1024-4096);
assert(advice==MADV_DONTNEED); assert(advice=MADV_DONTNEED);
} else if (counter==1) { } else if (counter==1) {
assert(m+2*1024*1024+4096==a); assert(m+2*1024*1024+4096==a);
assert(length==16*1024*1024-2*1024*1024-4096); assert(length=16*1024*1024-2*1024*1024-4096);
assert(advice==MADV_DONTNEED); assert(advice=MADV_DONTNEED);
} else if (counter==2) { } else if (counter==2) {
assert(m+4*1024*1024+4096==a); assert(m+4*1024*1024+4096==a);
assert(length==16*1024*1024-4*1024*1024-4096); assert(length=16*1024*1024-4*1024*1024-4096);
assert(advice==MADV_DONTNEED); assert(advice=MADV_DONTNEED);
} else { } else {
printf("madvise(%p, 0x%lx, %d)\n", addr, length, advice); printf("madvise(%p, 0x%lx, %d)\n", addr, length, advice);
abort(); abort();
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#endif #endif
#include <dlfcn.h> #include <dlfcn.h>
#include <valgrind/helgrind.h> #include <valgrind/helgrind.h>
#include <sys/mman.h>
#include "memory.h" #include "memory.h"
#include "toku_assert.h" #include "toku_assert.h"
...@@ -26,12 +25,9 @@ static free_fun_t t_free = 0; ...@@ -26,12 +25,9 @@ static free_fun_t t_free = 0;
static realloc_fun_t t_realloc = 0; static realloc_fun_t t_realloc = 0;
static realloc_fun_t t_xrealloc = 0; static realloc_fun_t t_xrealloc = 0;
enum which_mallocator { M_LIBC, M_JEMALLOC, M_DARWIN } which_mallocator;
static LOCAL_MEMORY_STATUS_S status; static LOCAL_MEMORY_STATUS_S status;
int toku_memory_do_stats = 0; int toku_memory_do_stats = 0;
static size_t pagesize = 0;
typedef size_t (*malloc_usable_size_fun_t)(const void *); typedef size_t (*malloc_usable_size_fun_t)(const void *);
static malloc_usable_size_fun_t malloc_usable_size_f; static malloc_usable_size_fun_t malloc_usable_size_f;
...@@ -44,8 +40,6 @@ toku_memory_startup(void) { ...@@ -44,8 +40,6 @@ toku_memory_startup(void) {
} }
memory_startup_complete = true; memory_startup_complete = true;
pagesize = sysconf(_SC_PAGESIZE);
int result = 0; int result = 0;
#if defined(HAVE_M_MMAP_THRESHOLD) #if defined(HAVE_M_MMAP_THRESHOLD)
...@@ -55,7 +49,6 @@ toku_memory_startup(void) { ...@@ -55,7 +49,6 @@ toku_memory_startup(void) {
if (success) { if (success) {
status.mallocator_version = "libc"; status.mallocator_version = "libc";
status.mmap_threshold = mmap_threshold; status.mmap_threshold = mmap_threshold;
which_mallocator = M_LIBC;
} else } else
result = EINVAL; result = EINVAL;
#else #else
...@@ -71,7 +64,6 @@ toku_memory_startup(void) { ...@@ -71,7 +64,6 @@ toku_memory_startup(void) {
mallctl_fun_t mallctl_f; mallctl_fun_t mallctl_f;
mallctl_f = (mallctl_fun_t) dlsym(RTLD_DEFAULT, "mallctl"); mallctl_f = (mallctl_fun_t) dlsym(RTLD_DEFAULT, "mallctl");
if (mallctl_f) { // jemalloc is loaded if (mallctl_f) { // jemalloc is loaded
which_mallocator = M_JEMALLOC;
size_t version_length = sizeof status.mallocator_version; size_t version_length = sizeof status.mallocator_version;
result = mallctl_f("version", &status.mallocator_version, &version_length, NULL, 0); result = mallctl_f("version", &status.mallocator_version, &version_length, NULL, 0);
if (result == 0) { if (result == 0) {
...@@ -134,6 +126,7 @@ set_max(uint64_t sum_used, uint64_t sum_freed) { ...@@ -134,6 +126,7 @@ set_max(uint64_t sum_used, uint64_t sum_freed) {
size_t size_t
toku_memory_footprint(void * p, size_t touched) { toku_memory_footprint(void * p, size_t touched) {
static size_t pagesize = 0;
size_t rval = 0; size_t rval = 0;
if (!pagesize) if (!pagesize)
pagesize = sysconf(_SC_PAGESIZE); pagesize = sysconf(_SC_PAGESIZE);
...@@ -230,7 +223,8 @@ toku_free_n(void* p, size_t size __attribute__((unused))) { ...@@ -230,7 +223,8 @@ toku_free_n(void* p, size_t size __attribute__((unused))) {
void * void *
toku_xmalloc(size_t size) { toku_xmalloc(size_t size) {
void *p = t_xmalloc ? t_xmalloc(size) : os_malloc(size); void *p = t_xmalloc ? t_xmalloc(size) : os_malloc(size);
resource_assert(p); if (p == NULL) // avoid function call in common case
resource_assert(p);
ANNOTATE_NEW_MEMORY(p, size); // see #4671 and https://bugs.kde.org/show_bug.cgi?id=297147 ANNOTATE_NEW_MEMORY(p, size); // see #4671 and https://bugs.kde.org/show_bug.cgi?id=297147
if (toku_memory_do_stats) { if (toku_memory_do_stats) {
size_t used = my_malloc_usable_size(p); size_t used = my_malloc_usable_size(p);
...@@ -254,7 +248,8 @@ void * ...@@ -254,7 +248,8 @@ void *
toku_xrealloc(void *v, size_t size) { toku_xrealloc(void *v, size_t size) {
size_t used_orig = v ? my_malloc_usable_size(v) : 0; size_t used_orig = v ? my_malloc_usable_size(v) : 0;
void *p = t_xrealloc ? t_xrealloc(v, size) : os_realloc(v, size); void *p = t_xrealloc ? t_xrealloc(v, size) : os_realloc(v, size);
resource_assert(p); if (p == 0) // avoid function call in common case
resource_assert(p);
if (toku_memory_do_stats) { if (toku_memory_do_stats) {
size_t used = my_malloc_usable_size(p); size_t used = my_malloc_usable_size(p);
__sync_add_and_fetch(&status.realloc_count, 1); __sync_add_and_fetch(&status.realloc_count, 1);
...@@ -321,35 +316,6 @@ toku_set_func_free(free_fun_t f) { ...@@ -321,35 +316,6 @@ toku_set_func_free(free_fun_t f) {
t_free = f; t_free = f;
} }
#define HUGEPAGE_SIZE (2L*1024L*1024L)
void toku_memory_dontneed_after_but_i_touched(void *malloced_object, size_t malloced_size, size_t just_touched_start, size_t just_touched_length) {
if (which_mallocator==M_JEMALLOC) {
if ((just_touched_length>0) && (0==((long)malloced_object & (HUGEPAGE_SIZE-1)))) {
// If it's zero, then we didn't touch anything.
// jemalloc aligns all large objects on 4MB boundaries, so if it's not 2MB aligned, then don't bother to continue.
// Since we know that o is aligned, we can just do arithmetic on the offsets.
long prevhugepage = (just_touched_start -1)/HUGEPAGE_SIZE;
long thishugepage = (just_touched_start+just_touched_length-1)/HUGEPAGE_SIZE;
if (prevhugepage != thishugepage) {
// Crossed a hugepage boundary.
// Take the ceiling modulo page size of the first untouched byte:
long start_offset = (just_touched_start + just_touched_length + pagesize -1)&~(pagesize-1);
char *madvise_start = (char*)malloced_object + start_offset;
size_t usable = toku_malloc_usable_size(malloced_object);
assert(usable >= malloced_size);
if (usable%HUGEPAGE_SIZE == 0) { // We knew it was 2MB-aligned, and now we know that it's a big block
long madvise_len = usable-start_offset;
assert(madvise_len>=0);
if (madvise_len>0) {
int r = madvise(madvise_start, madvise_len, MADV_DONTNEED);
assert(r==0);
}
}
}
}
}
}
#include <valgrind/helgrind.h> #include <valgrind/helgrind.h>
void __attribute__((constructor)) toku_memory_helgrind_ignore(void); void __attribute__((constructor)) toku_memory_helgrind_ignore(void);
void void
......
#include <stdlib.h>
#include <assert.h>
#include "memory.h"
enum which_mallocator { M_LIBC, M_JEMALLOC, M_DARWIN } which_mallocator;
int main (int argc, const char *argv[] __attribute__((__unused__))) {
assert(argc==1);
void *p;
int r = posix_memalign(&p, 2L*1024L*1024L, 4096);
toku_memory_startup();
which_mallocator = M_JEMALLOC;
assert(r==0);
((char*)p)[0] = 'a';
toku_memory_dontneed_after_but_i_touched(p, 4096, 0, 1);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment