mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
[t:4934] Get rid of 4934 stuff from main. Refs #4934.
git-svn-id: file:///svn/toku/tokudb@44659 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
parent
76d674aca8
commit
925f584468
3 changed files with 11 additions and 62 deletions
|
@ -51,16 +51,16 @@ int madvise (void *addr, size_t length, int advice) {
|
|||
char *m=mem;
|
||||
if (counter==0) {
|
||||
assert(m+4096==a);
|
||||
assert(length==16*1024*1024-4096);
|
||||
assert(advice==MADV_DONTNEED);
|
||||
assert(length=16*1024*1024-4096);
|
||||
assert(advice=MADV_DONTNEED);
|
||||
} else if (counter==1) {
|
||||
assert(m+2*1024*1024+4096==a);
|
||||
assert(length==16*1024*1024-2*1024*1024-4096);
|
||||
assert(advice==MADV_DONTNEED);
|
||||
assert(length=16*1024*1024-2*1024*1024-4096);
|
||||
assert(advice=MADV_DONTNEED);
|
||||
} else if (counter==2) {
|
||||
assert(m+4*1024*1024+4096==a);
|
||||
assert(length==16*1024*1024-4*1024*1024-4096);
|
||||
assert(advice==MADV_DONTNEED);
|
||||
assert(length=16*1024*1024-4*1024*1024-4096);
|
||||
assert(advice=MADV_DONTNEED);
|
||||
} else {
|
||||
printf("madvise(%p, 0x%lx, %d)\n", addr, length, advice);
|
||||
abort();
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#endif
|
||||
#include <dlfcn.h>
|
||||
#include <valgrind/helgrind.h>
|
||||
#include <sys/mman.h>
|
||||
#include "memory.h"
|
||||
#include "toku_assert.h"
|
||||
|
||||
|
@ -26,12 +25,9 @@ static free_fun_t t_free = 0;
|
|||
static realloc_fun_t t_realloc = 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;
|
||||
int toku_memory_do_stats = 0;
|
||||
|
||||
static size_t pagesize = 0;
|
||||
|
||||
typedef size_t (*malloc_usable_size_fun_t)(const void *);
|
||||
static malloc_usable_size_fun_t malloc_usable_size_f;
|
||||
|
||||
|
@ -44,8 +40,6 @@ toku_memory_startup(void) {
|
|||
}
|
||||
memory_startup_complete = true;
|
||||
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
|
||||
int result = 0;
|
||||
|
||||
#if defined(HAVE_M_MMAP_THRESHOLD)
|
||||
|
@ -55,7 +49,6 @@ toku_memory_startup(void) {
|
|||
if (success) {
|
||||
status.mallocator_version = "libc";
|
||||
status.mmap_threshold = mmap_threshold;
|
||||
which_mallocator = M_LIBC;
|
||||
} else
|
||||
result = EINVAL;
|
||||
#else
|
||||
|
@ -71,7 +64,6 @@ toku_memory_startup(void) {
|
|||
mallctl_fun_t mallctl_f;
|
||||
mallctl_f = (mallctl_fun_t) dlsym(RTLD_DEFAULT, "mallctl");
|
||||
if (mallctl_f) { // jemalloc is loaded
|
||||
which_mallocator = M_JEMALLOC;
|
||||
size_t version_length = sizeof status.mallocator_version;
|
||||
result = mallctl_f("version", &status.mallocator_version, &version_length, NULL, 0);
|
||||
if (result == 0) {
|
||||
|
@ -134,6 +126,7 @@ set_max(uint64_t sum_used, uint64_t sum_freed) {
|
|||
|
||||
size_t
|
||||
toku_memory_footprint(void * p, size_t touched) {
|
||||
static size_t pagesize = 0;
|
||||
size_t rval = 0;
|
||||
if (!pagesize)
|
||||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
|
@ -230,7 +223,8 @@ toku_free_n(void* p, size_t size __attribute__((unused))) {
|
|||
void *
|
||||
toku_xmalloc(size_t 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
|
||||
if (toku_memory_do_stats) {
|
||||
size_t used = my_malloc_usable_size(p);
|
||||
|
@ -254,7 +248,8 @@ void *
|
|||
toku_xrealloc(void *v, size_t size) {
|
||||
size_t used_orig = v ? my_malloc_usable_size(v) : 0;
|
||||
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) {
|
||||
size_t used = my_malloc_usable_size(p);
|
||||
__sync_add_and_fetch(&status.realloc_count, 1);
|
||||
|
@ -321,35 +316,6 @@ toku_set_func_free(free_fun_t 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>
|
||||
void __attribute__((constructor)) toku_memory_helgrind_ignore(void);
|
||||
void
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Reference in a new issue