memory/build/mozmemory.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memory/build/mozmemory.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozmemory_h
     1.9 +#define mozmemory_h
    1.10 +
    1.11 +/*
    1.12 + * This header is meant to be used when the following functions are
    1.13 + * necessary:
    1.14 + *   - malloc_good_size (used to be called je_malloc_usable_in_advance)
    1.15 + *   - jemalloc_stats
    1.16 + *   - jemalloc_purge_freed_pages
    1.17 + *   - jemalloc_free_dirty_pages
    1.18 + */
    1.19 +
    1.20 +#ifndef MOZ_MEMORY
    1.21 +#  error Should not include mozmemory.h when MOZ_MEMORY is not set
    1.22 +#endif
    1.23 +
    1.24 +#include "mozmemory_wrap.h"
    1.25 +#include "mozilla/Attributes.h"
    1.26 +#include "mozilla/Types.h"
    1.27 +#include "jemalloc_types.h"
    1.28 +
    1.29 +MOZ_BEGIN_EXTERN_C
    1.30 +
    1.31 +/*
    1.32 + * On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
    1.33 + * which will call back in jemalloc, through the zone allocator so just use it.
    1.34 + */
    1.35 +#ifdef XP_DARWIN
    1.36 +#  include <malloc/malloc.h>
    1.37 +#else
    1.38 +MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
    1.39 +
    1.40 +/* Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
    1.41 + * the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
    1.42 + * to use weak imports. */
    1.43 +
    1.44 +static inline size_t _malloc_good_size(size_t size) {
    1.45 +#  if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
    1.46 +  if (!malloc_good_size)
    1.47 +    return size;
    1.48 +#  endif
    1.49 +  return malloc_good_size_impl(size);
    1.50 +}
    1.51 +
    1.52 +#  define malloc_good_size _malloc_good_size
    1.53 +#endif
    1.54 +
    1.55 +MOZ_JEMALLOC_API void jemalloc_stats(jemalloc_stats_t *stats);
    1.56 +
    1.57 +/*
    1.58 + * On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
    1.59 + * back to the operating system.  On Mac, the operating system doesn't take
    1.60 + * this memory back immediately; instead, the OS takes it back only when the
    1.61 + * machine is running out of physical memory.
    1.62 + *
    1.63 + * This is great from the standpoint of efficiency, but it makes measuring our
    1.64 + * actual RSS difficult, because pages which we've MADV_FREE'd shouldn't count
    1.65 + * against our RSS.
    1.66 + *
    1.67 + * This function explicitly purges any MADV_FREE'd pages from physical memory,
    1.68 + * causing our reported RSS match the amount of memory we're actually using.
    1.69 + *
    1.70 + * Note that this call is expensive in two ways.  First, it may be slow to
    1.71 + * execute, because it may make a number of slow syscalls to free memory.  This
    1.72 + * function holds the big jemalloc locks, so basically all threads are blocked
    1.73 + * while this function runs.
    1.74 + *
    1.75 + * This function is also expensive in that the next time we go to access a page
    1.76 + * which we've just explicitly decommitted, the operating system has to attach
    1.77 + * to it a physical page!  If we hadn't run this function, the OS would have
    1.78 + * less work to do.
    1.79 + *
    1.80 + * If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
    1.81 + */
    1.82 +MOZ_JEMALLOC_API void jemalloc_purge_freed_pages();
    1.83 +
    1.84 +/*
    1.85 + * Free all unused dirty pages in all arenas. Calling this function will slow
    1.86 + * down subsequent allocations so it is recommended to use it only when
    1.87 + * memory needs to be reclaimed at all costs (see bug 805855). This function
    1.88 + * provides functionality similar to mallctl("arenas.purge") in jemalloc 3.
    1.89 + */
    1.90 +MOZ_JEMALLOC_API void jemalloc_free_dirty_pages();
    1.91 +
    1.92 +MOZ_END_EXTERN_C
    1.93 +
    1.94 +#endif /* mozmemory_h */

mercurial