memory/build/mozmemory.h

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 mozmemory_h
michael@0 6 #define mozmemory_h
michael@0 7
michael@0 8 /*
michael@0 9 * This header is meant to be used when the following functions are
michael@0 10 * necessary:
michael@0 11 * - malloc_good_size (used to be called je_malloc_usable_in_advance)
michael@0 12 * - jemalloc_stats
michael@0 13 * - jemalloc_purge_freed_pages
michael@0 14 * - jemalloc_free_dirty_pages
michael@0 15 */
michael@0 16
michael@0 17 #ifndef MOZ_MEMORY
michael@0 18 # error Should not include mozmemory.h when MOZ_MEMORY is not set
michael@0 19 #endif
michael@0 20
michael@0 21 #include "mozmemory_wrap.h"
michael@0 22 #include "mozilla/Attributes.h"
michael@0 23 #include "mozilla/Types.h"
michael@0 24 #include "jemalloc_types.h"
michael@0 25
michael@0 26 MOZ_BEGIN_EXTERN_C
michael@0 27
michael@0 28 /*
michael@0 29 * On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
michael@0 30 * which will call back in jemalloc, through the zone allocator so just use it.
michael@0 31 */
michael@0 32 #ifdef XP_DARWIN
michael@0 33 # include <malloc/malloc.h>
michael@0 34 #else
michael@0 35 MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
michael@0 36
michael@0 37 /* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
michael@0 38 * the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
michael@0 39 * to use weak imports. */
michael@0 40
michael@0 41 static inline size_t _malloc_good_size(size_t size) {
michael@0 42 # if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
michael@0 43 if (!malloc_good_size)
michael@0 44 return size;
michael@0 45 # endif
michael@0 46 return malloc_good_size_impl(size);
michael@0 47 }
michael@0 48
michael@0 49 # define malloc_good_size _malloc_good_size
michael@0 50 #endif
michael@0 51
michael@0 52 MOZ_JEMALLOC_API void jemalloc_stats(jemalloc_stats_t *stats);
michael@0 53
michael@0 54 /*
michael@0 55 * On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
michael@0 56 * back to the operating system. On Mac, the operating system doesn't take
michael@0 57 * this memory back immediately; instead, the OS takes it back only when the
michael@0 58 * machine is running out of physical memory.
michael@0 59 *
michael@0 60 * This is great from the standpoint of efficiency, but it makes measuring our
michael@0 61 * actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count
michael@0 62 * against our RSS.
michael@0 63 *
michael@0 64 * This function explicitly purges any MADV_FREE'd pages from physical memory,
michael@0 65 * causing our reported RSS match the amount of memory we're actually using.
michael@0 66 *
michael@0 67 * Note that this call is expensive in two ways. First, it may be slow to
michael@0 68 * execute, because it may make a number of slow syscalls to free memory. This
michael@0 69 * function holds the big jemalloc locks, so basically all threads are blocked
michael@0 70 * while this function runs.
michael@0 71 *
michael@0 72 * This function is also expensive in that the next time we go to access a page
michael@0 73 * which we've just explicitly decommitted, the operating system has to attach
michael@0 74 * to it a physical page! If we hadn't run this function, the OS would have
michael@0 75 * less work to do.
michael@0 76 *
michael@0 77 * If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
michael@0 78 */
michael@0 79 MOZ_JEMALLOC_API void jemalloc_purge_freed_pages();
michael@0 80
michael@0 81 /*
michael@0 82 * Free all unused dirty pages in all arenas. Calling this function will slow
michael@0 83 * down subsequent allocations so it is recommended to use it only when
michael@0 84 * memory needs to be reclaimed at all costs (see bug 805855). This function
michael@0 85 * provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
michael@0 86 */
michael@0 87 MOZ_JEMALLOC_API void jemalloc_free_dirty_pages();
michael@0 88
michael@0 89 MOZ_END_EXTERN_C
michael@0 90
michael@0 91 #endif /* mozmemory_h */

mercurial