Commit 50f66714 authored by Barry Perlman's avatar Barry Perlman Committed by Yoni Fogel

[t:3825] #3825 Do not call malloc_usable_size() with NULL. Add malloc_fail...

[t:3825] #3825 Do not call malloc_usable_size() with NULL.  Add malloc_fail and realloc_fail to engine status.

git-svn-id: file:///svn/toku/tokudb@33948 c7de825b-a66e-492c-adef-691d508d4ae1
parent c4e2d804
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -596,6 +596,8 @@ int main (int argc __attribute__((__unused__)), char *const argv[] __attribute__ ...@@ -596,6 +596,8 @@ int main (int argc __attribute__((__unused__)), char *const argv[] __attribute__
printf(" uint64_t malloc_count; /* number of malloc operations */ \n"); printf(" uint64_t malloc_count; /* number of malloc operations */ \n");
printf(" uint64_t free_count; /* number of free operations */ \n"); printf(" uint64_t free_count; /* number of free operations */ \n");
printf(" uint64_t realloc_count; /* number of realloc operations */ \n"); printf(" uint64_t realloc_count; /* number of realloc operations */ \n");
printf(" uint64_t malloc_fail; /* number of failed malloc operations */ \n");
printf(" uint64_t realloc_fail; /* number of failed realloc operations */ \n");
printf(" uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ \n"); printf(" uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ \n");
printf(" uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ \n"); printf(" uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ \n");
printf(" uint64_t mem_freed; /* number of bytes freed */ \n"); printf(" uint64_t mem_freed; /* number of bytes freed */ \n");
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status { ...@@ -202,6 +202,8 @@ typedef struct __toku_engine_status {
uint64_t malloc_count; /* number of malloc operations */ uint64_t malloc_count; /* number of malloc operations */
uint64_t free_count; /* number of free operations */ uint64_t free_count; /* number of free operations */
uint64_t realloc_count; /* number of realloc operations */ uint64_t realloc_count; /* number of realloc operations */
uint64_t malloc_fail; /* number of failed malloc operations */
uint64_t realloc_fail; /* number of failed realloc operations */
uint64_t mem_requested; /* number of bytes requested via malloc/realloc */ uint64_t mem_requested; /* number of bytes requested via malloc/realloc */
uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */ uint64_t mem_used; /* number of bytes used (obtained from malloc_usable_size()) */
uint64_t mem_freed; /* number of bytes freed */ uint64_t mem_freed; /* number of bytes freed */
......
...@@ -2021,6 +2021,8 @@ env_get_engine_status(DB_ENV * env, ENGINE_STATUS * engstat, char * env_panic_st ...@@ -2021,6 +2021,8 @@ env_get_engine_status(DB_ENV * env, ENGINE_STATUS * engstat, char * env_panic_st
engstat->malloc_count = memory_status.malloc_count; engstat->malloc_count = memory_status.malloc_count;
engstat->free_count = memory_status.free_count; engstat->free_count = memory_status.free_count;
engstat->realloc_count = memory_status.realloc_count; engstat->realloc_count = memory_status.realloc_count;
engstat->malloc_fail = memory_status.malloc_fail;
engstat->realloc_fail = memory_status.realloc_fail;
engstat->mem_requested = memory_status.requested; engstat->mem_requested = memory_status.requested;
engstat->mem_used = memory_status.used; engstat->mem_used = memory_status.used;
engstat->mem_freed = memory_status.freed; engstat->mem_freed = memory_status.freed;
...@@ -2197,6 +2199,8 @@ env_get_engine_status_text(DB_ENV * env, char * buff, int bufsiz) { ...@@ -2197,6 +2199,8 @@ env_get_engine_status_text(DB_ENV * env, char * buff, int bufsiz) {
n += snprintf(buff + n, bufsiz - n, "malloc_count %"PRIu64"\n", engstat.malloc_count); n += snprintf(buff + n, bufsiz - n, "malloc_count %"PRIu64"\n", engstat.malloc_count);
n += snprintf(buff + n, bufsiz - n, "free_count %"PRIu64"\n", engstat.free_count); n += snprintf(buff + n, bufsiz - n, "free_count %"PRIu64"\n", engstat.free_count);
n += snprintf(buff + n, bufsiz - n, "realloc_count %"PRIu64"\n", engstat.realloc_count); n += snprintf(buff + n, bufsiz - n, "realloc_count %"PRIu64"\n", engstat.realloc_count);
n += snprintf(buff + n, bufsiz - n, "malloc_fail %"PRIu64"\n", engstat.malloc_fail);
n += snprintf(buff + n, bufsiz - n, "realloc_fail %"PRIu64"\n", engstat.realloc_fail);
n += snprintf(buff + n, bufsiz - n, "mem_requested %"PRIu64"\n", engstat.mem_requested); n += snprintf(buff + n, bufsiz - n, "mem_requested %"PRIu64"\n", engstat.mem_requested);
n += snprintf(buff + n, bufsiz - n, "mem_used %"PRIu64"\n", engstat.mem_used); n += snprintf(buff + n, bufsiz - n, "mem_used %"PRIu64"\n", engstat.mem_used);
n += snprintf(buff + n, bufsiz - n, "mem_freed %"PRIu64"\n", engstat.mem_freed); n += snprintf(buff + n, bufsiz - n, "mem_freed %"PRIu64"\n", engstat.mem_freed);
......
...@@ -111,6 +111,8 @@ typedef struct memory_status { ...@@ -111,6 +111,8 @@ typedef struct memory_status {
uint64_t malloc_count; // number of malloc operations uint64_t malloc_count; // number of malloc operations
uint64_t free_count; // number of free operations uint64_t free_count; // number of free operations
uint64_t realloc_count; // number of realloc operations uint64_t realloc_count; // number of realloc operations
uint64_t malloc_fail; // number of malloc operations that failed
uint64_t realloc_fail; // number of realloc operations that failed
uint64_t requested; // number of bytes requested uint64_t requested; // number of bytes requested
uint64_t used; // number of bytes used (requested + overhead), obtained from malloc_usable_size() uint64_t used; // number of bytes used (requested + overhead), obtained from malloc_usable_size()
uint64_t freed; // number of bytes freed; uint64_t freed; // number of bytes freed;
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-2010 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007-2010 Tokutek Inc. All rights reserved."
#include <toku_portability.h> #include <toku_portability.h>
...@@ -27,10 +28,14 @@ toku_memory_get_status(MEMORY_STATUS s) { ...@@ -27,10 +28,14 @@ toku_memory_get_status(MEMORY_STATUS s) {
void *toku_malloc(size_t size) { void *toku_malloc(size_t size) {
void *p = t_malloc ? t_malloc(size) : os_malloc(size); void *p = t_malloc ? t_malloc(size) : os_malloc(size);
size_t used = malloc_usable_size(p); if (p) {
__sync_add_and_fetch(&status.malloc_count, 1L); size_t used = malloc_usable_size(p);
__sync_add_and_fetch(&status.requested, size); __sync_add_and_fetch(&status.malloc_count, 1L);
__sync_add_and_fetch(&status.used, used); __sync_add_and_fetch(&status.requested, size);
__sync_add_and_fetch(&status.used, used);
}
else
__sync_add_and_fetch(&status.malloc_fail, 1L);
return p; return p;
} }
...@@ -44,13 +49,17 @@ toku_calloc(size_t nmemb, size_t size) { ...@@ -44,13 +49,17 @@ toku_calloc(size_t nmemb, size_t size) {
void * void *
toku_realloc(void *p, size_t size) { toku_realloc(void *p, size_t size) {
size_t used_orig = malloc_usable_size(p); size_t used_orig = p ? malloc_usable_size(p) : 0;
void *q = t_realloc ? t_realloc(p, size) : os_realloc(p, size); void *q = t_realloc ? t_realloc(p, size) : os_realloc(p, size);
size_t used = malloc_usable_size(q); if (q) {
__sync_add_and_fetch(&status.realloc_count, 1L); size_t used = malloc_usable_size(q);
__sync_add_and_fetch(&status.requested, size); __sync_add_and_fetch(&status.realloc_count, 1L);
__sync_add_and_fetch(&status.used, used); __sync_add_and_fetch(&status.requested, size);
__sync_add_and_fetch(&status.freed, used_orig); __sync_add_and_fetch(&status.used, used);
__sync_add_and_fetch(&status.freed, used_orig);
}
else
__sync_add_and_fetch(&status.realloc_fail, 1L);
return q; return q;
} }
...@@ -68,7 +77,7 @@ toku_strdup(const char *s) { ...@@ -68,7 +77,7 @@ toku_strdup(const char *s) {
void void
toku_free(void *p) { toku_free(void *p) {
size_t used = malloc_usable_size(p); size_t used = p ? malloc_usable_size(p) : 0;
__sync_add_and_fetch(&status.free_count, 1L); __sync_add_and_fetch(&status.free_count, 1L);
__sync_add_and_fetch(&status.freed, used); __sync_add_and_fetch(&status.freed, used);
if (t_free) if (t_free)
......
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