2017-11-01 10:56:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-12-07 12:32:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-11-01 10:56:27 +03:00
|
|
|
* 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
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// Helper header to declare all the supported malloc functions.
|
|
|
|
// MALLOC_DECL arguments are:
|
|
|
|
// - function name
|
|
|
|
// - return type
|
|
|
|
// - argument types
|
2012-12-07 12:32:24 +04:00
|
|
|
|
|
|
|
#ifndef malloc_decls_h
|
2017-11-01 11:20:54 +03:00
|
|
|
#define malloc_decls_h
|
|
|
|
|
|
|
|
#include "mozjemalloc_types.h"
|
|
|
|
|
|
|
|
#define MALLOC_FUNCS_MALLOC_BASE 1
|
|
|
|
#define MALLOC_FUNCS_MALLOC_EXTRA 2
|
|
|
|
#define MALLOC_FUNCS_MALLOC \
|
|
|
|
(MALLOC_FUNCS_MALLOC_BASE | MALLOC_FUNCS_MALLOC_EXTRA)
|
|
|
|
#define MALLOC_FUNCS_JEMALLOC 4
|
2017-11-24 10:36:29 +03:00
|
|
|
#define MALLOC_FUNCS_ARENA_BASE 8
|
|
|
|
#define MALLOC_FUNCS_ARENA_ALLOC 16
|
2017-11-01 11:20:54 +03:00
|
|
|
#define MALLOC_FUNCS_ARENA (MALLOC_FUNCS_ARENA_BASE | MALLOC_FUNCS_ARENA_ALLOC)
|
|
|
|
#define MALLOC_FUNCS_ALL \
|
2017-11-24 10:36:29 +03:00
|
|
|
(MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA)
|
2012-12-07 12:32:24 +04:00
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
#endif // malloc_decls_h
|
2012-12-07 12:32:24 +04:00
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
#ifndef MALLOC_FUNCS
|
2017-11-24 10:36:29 +03:00
|
|
|
#define MALLOC_FUNCS MALLOC_FUNCS_ALL
|
2012-12-07 12:32:24 +04:00
|
|
|
#endif
|
|
|
|
|
2012-12-07 12:32:24 +04:00
|
|
|
#ifdef MALLOC_DECL
|
2017-11-01 11:20:54 +03:00
|
|
|
#if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_BASE
|
|
|
|
MALLOC_DECL(malloc, void*, size_t)
|
|
|
|
MALLOC_DECL(calloc, void*, size_t, size_t)
|
|
|
|
MALLOC_DECL(realloc, void*, void*, size_t)
|
|
|
|
MALLOC_DECL(free, void, void*)
|
|
|
|
MALLOC_DECL(memalign, void*, size_t, size_t)
|
|
|
|
#endif
|
|
|
|
#if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_EXTRA
|
|
|
|
MALLOC_DECL(posix_memalign, int, void**, size_t, size_t)
|
|
|
|
MALLOC_DECL(aligned_alloc, void*, size_t, size_t)
|
|
|
|
MALLOC_DECL(valloc, void*, size_t)
|
2012-12-07 12:32:24 +04:00
|
|
|
MALLOC_DECL(malloc_usable_size, size_t, usable_ptr_t)
|
|
|
|
MALLOC_DECL(malloc_good_size, size_t, size_t)
|
2017-11-01 11:20:54 +03:00
|
|
|
#endif
|
|
|
|
#if MALLOC_FUNCS & MALLOC_FUNCS_JEMALLOC
|
|
|
|
MALLOC_DECL(jemalloc_stats, void, jemalloc_stats_t*)
|
2017-11-01 11:15:12 +03:00
|
|
|
|
|
|
|
// On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
|
|
|
|
// back to the operating system. On Mac, the operating system doesn't take
|
|
|
|
// this memory back immediately; instead, the OS takes it back only when the
|
|
|
|
// machine is running out of physical memory.
|
|
|
|
//
|
|
|
|
// This is great from the standpoint of efficiency, but it makes measuring our
|
|
|
|
// actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count
|
|
|
|
// against our RSS.
|
|
|
|
//
|
|
|
|
// This function explicitly purges any MADV_FREE'd pages from physical memory,
|
|
|
|
// causing our reported RSS match the amount of memory we're actually using.
|
|
|
|
//
|
|
|
|
// Note that this call is expensive in two ways. First, it may be slow to
|
|
|
|
// execute, because it may make a number of slow syscalls to free memory. This
|
|
|
|
// function holds the big jemalloc locks, so basically all threads are blocked
|
|
|
|
// while this function runs.
|
|
|
|
//
|
|
|
|
// This function is also expensive in that the next time we go to access a page
|
|
|
|
// which we've just explicitly decommitted, the operating system has to attach
|
|
|
|
// to it a physical page! If we hadn't run this function, the OS would have
|
|
|
|
// less work to do.
|
|
|
|
//
|
|
|
|
// If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
|
2017-09-21 09:27:12 +03:00
|
|
|
MALLOC_DECL(jemalloc_purge_freed_pages, void)
|
2017-09-14 12:28:12 +03:00
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// Free all unused dirty pages in all arenas. Calling this function will slow
|
|
|
|
// down subsequent allocations so it is recommended to use it only when
|
|
|
|
// memory needs to be reclaimed at all costs (see bug 805855). This function
|
|
|
|
// provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
|
2017-09-21 09:27:12 +03:00
|
|
|
MALLOC_DECL(jemalloc_free_dirty_pages, void)
|
2017-09-14 12:28:12 +03:00
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// Opt in or out of a thread local arena (bool argument is whether to opt-in
|
|
|
|
// (true) or out (false)).
|
2017-09-21 09:27:12 +03:00
|
|
|
MALLOC_DECL(jemalloc_thread_local_arena, void, bool)
|
2017-09-14 12:28:12 +03:00
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// Provide information about any allocation enclosing the given address.
|
2017-09-21 09:27:12 +03:00
|
|
|
MALLOC_DECL(jemalloc_ptr_info, void, const void*, jemalloc_ptr_info_t*)
|
2017-11-01 11:20:54 +03:00
|
|
|
#endif
|
2015-05-26 09:48:21 +03:00
|
|
|
|
2017-11-01 11:20:54 +03:00
|
|
|
#if MALLOC_FUNCS & MALLOC_FUNCS_ARENA_BASE
|
2017-11-01 11:15:12 +03:00
|
|
|
|
|
|
|
// Creates a separate arena, and returns its id, valid to use with moz_arena_*
|
2017-11-17 01:27:35 +03:00
|
|
|
// functions. A helper is provided in mozmemory.h that doesn't take any
|
|
|
|
// arena_params_t: moz_create_arena.
|
|
|
|
MALLOC_DECL(moz_create_arena_with_params, arena_id_t, arena_params_t*)
|
2017-09-22 01:22:38 +03:00
|
|
|
|
2017-11-08 11:43:47 +03:00
|
|
|
// Dispose of the given arena. Subsequent uses of the arena will crash.
|
|
|
|
// Passing an invalid id (inexistent or already disposed) to this function
|
|
|
|
// will crash.
|
2017-09-22 01:22:38 +03:00
|
|
|
MALLOC_DECL(moz_dispose_arena, void, arena_id_t)
|
2017-11-01 11:20:54 +03:00
|
|
|
#endif
|
2017-09-22 01:22:38 +03:00
|
|
|
|
2017-11-01 11:20:54 +03:00
|
|
|
#if MALLOC_FUNCS & MALLOC_FUNCS_ARENA_ALLOC
|
2017-11-01 11:15:12 +03:00
|
|
|
// Same as the functions without the moz_arena_ prefix, but using arenas
|
|
|
|
// created with moz_create_arena.
|
|
|
|
// The contract, even if not enforced at runtime in some configurations,
|
2017-11-08 11:43:47 +03:00
|
|
|
// is that moz_arena_realloc and moz_arena_free will crash if the given
|
|
|
|
// arena doesn't own the given pointer. All functions will crash if the
|
|
|
|
// arena id is invalid.
|
2017-11-01 11:15:12 +03:00
|
|
|
// Although discouraged, plain realloc and free can still be used on
|
|
|
|
// pointers allocated with these functions. Realloc will properly keep
|
|
|
|
// new pointers in the same arena as the original.
|
2017-09-22 01:22:38 +03:00
|
|
|
MALLOC_DECL(moz_arena_malloc, void*, arena_id_t, size_t)
|
|
|
|
MALLOC_DECL(moz_arena_calloc, void*, arena_id_t, size_t, size_t)
|
|
|
|
MALLOC_DECL(moz_arena_realloc, void*, arena_id_t, void*, size_t)
|
|
|
|
MALLOC_DECL(moz_arena_free, void, arena_id_t, void*)
|
|
|
|
MALLOC_DECL(moz_arena_memalign, void*, arena_id_t, size_t, size_t)
|
2017-11-01 11:20:54 +03:00
|
|
|
#endif
|
2017-09-22 01:22:38 +03:00
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
#endif // MALLOC_DECL
|
2012-12-07 12:32:24 +04:00
|
|
|
|
|
|
|
#undef MALLOC_DECL
|
2012-12-07 12:32:24 +04:00
|
|
|
#undef MALLOC_FUNCS
|