memory/build/mozjemalloc_compat.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef MOZ_JEMALLOC3
michael@0 6 # error Should only compile this file when building with jemalloc 3
michael@0 7 #endif
michael@0 8
michael@0 9 #define MOZ_JEMALLOC_IMPL
michael@0 10
michael@0 11 #include "mozmemory_wrap.h"
michael@0 12 #include "jemalloc_types.h"
michael@0 13 #include "mozilla/Types.h"
michael@0 14
michael@0 15 #if defined(MOZ_NATIVE_JEMALLOC)
michael@0 16
michael@0 17 MOZ_IMPORT_API int
michael@0 18 je_(mallctl)(const char*, void*, size_t*, void*, size_t);
michael@0 19 MOZ_IMPORT_API int
michael@0 20 je_(mallctlnametomib)(const char *name, size_t *mibp, size_t *miblenp);
michael@0 21 MOZ_IMPORT_API int
michael@0 22 je_(mallctlbymib)(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
michael@0 23 MOZ_IMPORT_API int
michael@0 24 je_(nallocm)(size_t *rsize, size_t size, int flags);
michael@0 25
michael@0 26 #else
michael@0 27 # include "jemalloc/jemalloc.h"
michael@0 28 #endif
michael@0 29
michael@0 30 /*
michael@0 31 * CTL_* macros are from memory/jemalloc/src/src/stats.c with changes:
michael@0 32 * - drop `t' argument to avoid redundancy in calculating type size
michael@0 33 * - require `i' argument for arena number explicitly
michael@0 34 */
michael@0 35
michael@0 36 #define CTL_GET(n, v) do { \
michael@0 37 size_t sz = sizeof(v); \
michael@0 38 je_(mallctl)(n, &v, &sz, NULL, 0); \
michael@0 39 } while (0)
michael@0 40
michael@0 41 #define CTL_I_GET(n, v, i) do { \
michael@0 42 size_t mib[6]; \
michael@0 43 size_t miblen = sizeof(mib) / sizeof(mib[0]); \
michael@0 44 size_t sz = sizeof(v); \
michael@0 45 je_(mallctlnametomib)(n, mib, &miblen); \
michael@0 46 mib[2] = i; \
michael@0 47 je_(mallctlbymib)(mib, miblen, &v, &sz, NULL, 0); \
michael@0 48 } while (0)
michael@0 49
michael@0 50 MOZ_MEMORY_API size_t
michael@0 51 malloc_good_size_impl(size_t size)
michael@0 52 {
michael@0 53 size_t ret;
michael@0 54 /* je_nallocm crashes when given a size of 0. As
michael@0 55 * malloc_usable_size(malloc(0)) and malloc_usable_size(malloc(1))
michael@0 56 * return the same value, use a size of 1. */
michael@0 57 if (size == 0)
michael@0 58 size = 1;
michael@0 59 if (!je_(nallocm)(&ret, size, 0))
michael@0 60 return ret;
michael@0 61 return size;
michael@0 62 }
michael@0 63
michael@0 64 MOZ_JEMALLOC_API void
michael@0 65 jemalloc_stats_impl(jemalloc_stats_t *stats)
michael@0 66 {
michael@0 67 unsigned narenas;
michael@0 68 size_t active, allocated, mapped, page, pdirty;
michael@0 69
michael@0 70 CTL_GET("arenas.narenas", narenas);
michael@0 71 CTL_GET("arenas.page", page);
michael@0 72 CTL_GET("stats.active", active);
michael@0 73 CTL_GET("stats.allocated", allocated);
michael@0 74 CTL_GET("stats.mapped", mapped);
michael@0 75
michael@0 76 /* get the summation for all arenas, i == narenas */
michael@0 77 CTL_I_GET("stats.arenas.0.pdirty", pdirty, narenas);
michael@0 78
michael@0 79 stats->mapped = mapped;
michael@0 80 stats->allocated = allocated;
michael@0 81 stats->waste = active - allocated;
michael@0 82 stats->page_cache = pdirty * page;
michael@0 83
michael@0 84 // We could get this value out of base.c::base_pages, but that really should
michael@0 85 // be an upstream change, so don't worry about it for now.
michael@0 86 stats->bookkeeping = 0;
michael@0 87 }
michael@0 88
michael@0 89 MOZ_JEMALLOC_API void
michael@0 90 jemalloc_purge_freed_pages_impl()
michael@0 91 {
michael@0 92 }
michael@0 93
michael@0 94 MOZ_JEMALLOC_API void
michael@0 95 jemalloc_free_dirty_pages_impl()
michael@0 96 {
michael@0 97 je_(mallctl)("arenas.purge", NULL, 0, NULL, 0);
michael@0 98 }

mercurial