1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Some Linux kernels -- specifically, newer versions of Android and
8 // some B2G devices -- have a feature for assigning names to ranges of
9 // anonymous memory (i.e., memory that doesn't have a "name" in the
10 // form of an underlying mapped file). These names are reported in
11 // /proc/<pid>/smaps alongside system-level memory usage information
12 // such as Proportional Set Size (memory usage adjusted for sharing
13 // between processes), which allows reporting this information at a
14 // finer granularity than would otherwise be possible (e.g.,
15 // separating malloc() heap from JS heap).
17 // Existing memory can be tagged with MozTagAnonymousMemory(); it will
18 // tag the range of complete pages containing the given interval, so
19 // the results may be inexact if the range isn't page-aligned.
20 // MozTaggedAnonymousMmap() can be used like mmap() with an extra
21 // parameter, and will tag the returned memory if the mapping was
22 // successful (and if it was in fact anonymous).
24 // NOTE: The pointer given as the "tag" argument MUST remain valid as
25 // long as the mapping exists. The referenced string is read when
26 // /proc/<pid>/smaps or /proc/<pid>/maps is read, not when the tag is
27 // established, so freeing it or changing its contents will have
28 // unexpected results. Using a static string is probably best.
30 // Also note that this header can be used by both C and C++ code.
32 #ifndef mozilla_TaggedAnonymousMemory_h
33 #define mozilla_TaggedAnonymousMemory_h
37 #include <sys/types.h>
40 #include "mozilla/Types.h"
49 MozTagAnonymousMemory(const void* aPtr
, size_t aLength
, const char* aTag
);
52 MozTaggedAnonymousMmap(void* aAddr
, size_t aLength
, int aProt
, int aFlags
,
53 int aFd
, off_t aOffset
, const char* aTag
);
56 MozTaggedMemoryIsSupported(void);
65 MozTagAnonymousMemory(const void* aPtr
, size_t aLength
, const char* aTag
)
70 MozTaggedAnonymousMmap(void* aAddr
, size_t aLength
, int aProt
, int aFlags
,
71 int aFd
, off_t aOffset
, const char* aTag
)
73 return mmap(aAddr
, aLength
, aProt
, aFlags
, aFd
, aOffset
);
77 MozTaggedMemoryIsSupported(void)
86 #endif // mozilla_TaggedAnonymousMemory_h