2012-06-07 12:41:59 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
#ifndef MOZ_JEMALLOC3
|
|
|
|
# error Should only compile this file when building with jemalloc 3
|
|
|
|
#endif
|
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
#define MOZ_JEMALLOC_IMPL
|
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
#include "mozmemory_wrap.h"
|
2012-06-07 12:41:59 +04:00
|
|
|
#include "jemalloc_types.h"
|
2012-12-07 12:32:24 +04:00
|
|
|
#include "mozilla/Types.h"
|
2012-06-07 12:41:59 +04:00
|
|
|
|
2012-10-17 18:36:49 +04:00
|
|
|
#if defined(MOZ_NATIVE_JEMALLOC)
|
2012-12-07 12:32:24 +04:00
|
|
|
|
|
|
|
MOZ_IMPORT_API int
|
|
|
|
je_(mallctl)(const char*, void*, size_t*, void*, size_t);
|
|
|
|
MOZ_IMPORT_API int
|
|
|
|
je_(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp);
|
|
|
|
MOZ_IMPORT_API int
|
|
|
|
je_(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
|
|
|
|
MOZ_IMPORT_API int
|
|
|
|
je_(nallocm)(size_t *rsize, size_t size, int flags);
|
|
|
|
|
2012-10-17 18:36:49 +04:00
|
|
|
#else
|
2012-12-07 12:32:24 +04:00
|
|
|
# include "jemalloc/jemalloc.h"
|
2012-10-17 18:36:49 +04:00
|
|
|
#endif
|
2012-06-07 12:41:59 +04:00
|
|
|
|
2012-10-18 18:09:07 +04:00
|
|
|
/*
|
|
|
|
* CTL_* macros are from memory/jemalloc/src/src/stats.c with changes:
|
|
|
|
* - drop `t' argument to avoid redundancy in calculating type size
|
|
|
|
* - require `i' argument for arena number explicitly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CTL_GET(n, v) do { \
|
|
|
|
size_t sz = sizeof(v); \
|
2012-12-07 12:32:24 +04:00
|
|
|
je_(mallctl)(n, &v, &sz, NULL, 0); \
|
2012-10-18 18:09:07 +04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CTL_I_GET(n, v, i) do { \
|
|
|
|
size_t mib[6]; \
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(mib[0]); \
|
|
|
|
size_t sz = sizeof(v); \
|
2012-12-07 12:32:24 +04:00
|
|
|
je_(mallctlnametomib)(n, mib, &miblen); \
|
2012-10-18 18:09:07 +04:00
|
|
|
mib[2] = i; \
|
2012-12-07 12:32:24 +04:00
|
|
|
je_(mallctlbymib)(mib, miblen, &v, &sz, NULL, 0); \
|
2012-10-18 18:09:07 +04:00
|
|
|
} while (0)
|
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
MOZ_MEMORY_API size_t
|
|
|
|
malloc_good_size_impl(size_t size)
|
|
|
|
{
|
|
|
|
size_t ret;
|
|
|
|
/* je_nallocm crashes when given a size of 0. As
|
|
|
|
* malloc_usable_size(malloc(0)) and malloc_usable_size(malloc(1))
|
|
|
|
* return the same value, use a size of 1. */
|
|
|
|
if (size == 0)
|
|
|
|
size = 1;
|
|
|
|
if (!je_(nallocm)(&ret, size, 0))
|
|
|
|
return ret;
|
|
|
|
return size;
|
|
|
|
}
|
2012-10-17 18:36:49 +04:00
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
MOZ_JEMALLOC_API void
|
|
|
|
jemalloc_stats_impl(jemalloc_stats_t *stats)
|
2012-06-07 12:41:59 +04:00
|
|
|
{
|
2012-10-18 18:09:07 +04:00
|
|
|
unsigned narenas;
|
|
|
|
size_t active, allocated, mapped, page, pdirty;
|
2014-05-24 14:41:00 +04:00
|
|
|
size_t lg_chunk;
|
2012-10-18 18:09:07 +04:00
|
|
|
|
|
|
|
CTL_GET("arenas.narenas", narenas);
|
|
|
|
CTL_GET("arenas.page", page);
|
|
|
|
CTL_GET("stats.active", active);
|
|
|
|
CTL_GET("stats.allocated", allocated);
|
|
|
|
CTL_GET("stats.mapped", mapped);
|
2014-05-24 14:41:00 +04:00
|
|
|
CTL_GET("opt.lg_chunk", lg_chunk);
|
2012-10-18 18:09:07 +04:00
|
|
|
|
|
|
|
/* get the summation for all arenas, i == narenas */
|
|
|
|
CTL_I_GET("stats.arenas.0.pdirty", pdirty, narenas);
|
|
|
|
|
2014-05-24 14:41:00 +04:00
|
|
|
stats->chunksize = 1 << lg_chunk;
|
2012-10-18 18:09:07 +04:00
|
|
|
stats->mapped = mapped;
|
2013-08-02 03:37:54 +04:00
|
|
|
stats->allocated = allocated;
|
|
|
|
stats->waste = active - allocated;
|
|
|
|
stats->page_cache = pdirty * page;
|
|
|
|
|
|
|
|
// We could get this value out of base.c::base_pages, but that really should
|
|
|
|
// be an upstream change, so don't worry about it for now.
|
|
|
|
stats->bookkeeping = 0;
|
2014-05-24 14:41:00 +04:00
|
|
|
stats->bin_unused = 0;
|
2012-06-07 12:41:59 +04:00
|
|
|
}
|
2012-12-07 12:32:24 +04:00
|
|
|
|
|
|
|
MOZ_JEMALLOC_API void
|
|
|
|
jemalloc_purge_freed_pages_impl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_JEMALLOC_API void
|
|
|
|
jemalloc_free_dirty_pages_impl()
|
|
|
|
{
|
|
|
|
je_(mallctl)("arenas.purge", NULL, 0, NULL, 0);
|
|
|
|
}
|