michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozmemory_h michael@0: #define mozmemory_h michael@0: michael@0: /* michael@0: * This header is meant to be used when the following functions are michael@0: * necessary: michael@0: * - malloc_good_size (used to be called je_malloc_usable_in_advance) michael@0: * - jemalloc_stats michael@0: * - jemalloc_purge_freed_pages michael@0: * - jemalloc_free_dirty_pages michael@0: */ michael@0: michael@0: #ifndef MOZ_MEMORY michael@0: # error Should not include mozmemory.h when MOZ_MEMORY is not set michael@0: #endif michael@0: michael@0: #include "mozmemory_wrap.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/Types.h" michael@0: #include "jemalloc_types.h" michael@0: michael@0: MOZ_BEGIN_EXTERN_C michael@0: michael@0: /* michael@0: * On OSX, malloc/malloc.h contains the declaration for malloc_good_size, michael@0: * which will call back in jemalloc, through the zone allocator so just use it. michael@0: */ michael@0: #ifdef XP_DARWIN michael@0: # include michael@0: #else michael@0: MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size); michael@0: michael@0: /* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning michael@0: * the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API michael@0: * to use weak imports. */ michael@0: michael@0: static inline size_t _malloc_good_size(size_t size) { michael@0: # if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT) michael@0: if (!malloc_good_size) michael@0: return size; michael@0: # endif michael@0: return malloc_good_size_impl(size); michael@0: } michael@0: michael@0: # define malloc_good_size _malloc_good_size michael@0: #endif michael@0: michael@0: MOZ_JEMALLOC_API void jemalloc_stats(jemalloc_stats_t *stats); michael@0: michael@0: /* michael@0: * On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages michael@0: * back to the operating system. On Mac, the operating system doesn't take michael@0: * this memory back immediately; instead, the OS takes it back only when the michael@0: * machine is running out of physical memory. michael@0: * michael@0: * This is great from the standpoint of efficiency, but it makes measuring our michael@0: * actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count michael@0: * against our RSS. michael@0: * michael@0: * This function explicitly purges any MADV_FREE'd pages from physical memory, michael@0: * causing our reported RSS match the amount of memory we're actually using. michael@0: * michael@0: * Note that this call is expensive in two ways. First, it may be slow to michael@0: * execute, because it may make a number of slow syscalls to free memory. This michael@0: * function holds the big jemalloc locks, so basically all threads are blocked michael@0: * while this function runs. michael@0: * michael@0: * This function is also expensive in that the next time we go to access a page michael@0: * which we've just explicitly decommitted, the operating system has to attach michael@0: * to it a physical page! If we hadn't run this function, the OS would have michael@0: * less work to do. michael@0: * michael@0: * If MALLOC_DOUBLE_PURGE is not defined, this function does nothing. michael@0: */ michael@0: MOZ_JEMALLOC_API void jemalloc_purge_freed_pages(); michael@0: michael@0: /* michael@0: * Free all unused dirty pages in all arenas. Calling this function will slow michael@0: * down subsequent allocations so it is recommended to use it only when michael@0: * memory needs to be reclaimed at all costs (see bug 805855). This function michael@0: * provides functionality similar to mallctl("arenas.purge") in jemalloc 3. michael@0: */ michael@0: MOZ_JEMALLOC_API void jemalloc_free_dirty_pages(); michael@0: michael@0: MOZ_END_EXTERN_C michael@0: michael@0: #endif /* mozmemory_h */