1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
9 * This header is meant to be used when the following functions are
11 * - malloc_good_size (used to be called je_malloc_usable_in_advance)
13 * - jemalloc_purge_freed_pages
14 * - jemalloc_free_dirty_pages
18 # error Should not include mozmemory.h when MOZ_MEMORY is not set
21 #include "mozmemory_wrap.h"
22 #include "mozilla/Attributes.h"
23 #include "mozilla/Types.h"
24 #include "jemalloc_types.h"
29 * On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
30 * which will call back in jemalloc, through the zone allocator so just use it.
33 # include <malloc/malloc.h>
35 MOZ_MEMORY_API
size_t malloc_good_size_impl(size_t size
);
37 /* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
38 * the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
39 * to use weak imports. */
41 static inline size_t _malloc_good_size(size_t size
) {
42 # if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
43 if (!malloc_good_size
)
46 return malloc_good_size_impl(size
);
49 # define malloc_good_size _malloc_good_size
52 MOZ_JEMALLOC_API
void jemalloc_stats(jemalloc_stats_t
*stats
);
55 * On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
56 * back to the operating system. On Mac, the operating system doesn't take
57 * this memory back immediately; instead, the OS takes it back only when the
58 * machine is running out of physical memory.
60 * This is great from the standpoint of efficiency, but it makes measuring our
61 * actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count
64 * This function explicitly purges any MADV_FREE'd pages from physical memory,
65 * causing our reported RSS match the amount of memory we're actually using.
67 * Note that this call is expensive in two ways. First, it may be slow to
68 * execute, because it may make a number of slow syscalls to free memory. This
69 * function holds the big jemalloc locks, so basically all threads are blocked
70 * while this function runs.
72 * This function is also expensive in that the next time we go to access a page
73 * which we've just explicitly decommitted, the operating system has to attach
74 * to it a physical page! If we hadn't run this function, the OS would have
77 * If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
79 MOZ_JEMALLOC_API
void jemalloc_purge_freed_pages();
82 * Free all unused dirty pages in all arenas. Calling this function will slow
83 * down subsequent allocations so it is recommended to use it only when
84 * memory needs to be reclaimed at all costs (see bug 805855). This function
85 * provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
87 MOZ_JEMALLOC_API
void jemalloc_free_dirty_pages();
91 #endif /* mozmemory_h */