Bug 693404 - Part 2: On Mac, purge MADV_FREE'd pages before reading RSS. r=khuey

This commit is contained in:
Justin Lebar 2011-10-24 13:24:02 -04:00
Родитель 674d6ceed2
Коммит cb37c277f1
2 изменённых файлов: 38 добавлений и 18 удалений

Просмотреть файл

@ -84,6 +84,9 @@ HISTOGRAM(MEMORY_STORAGE_SQLITE, 1024, 512 * 1024, 50, EXPONENTIAL, "Memory used
HISTOGRAM(MEMORY_IMAGES_CONTENT_USED_UNCOMPRESSED, 1024, 1024 * 1024, 50, EXPONENTIAL, "Memory used for uncompressed, in-use content images (KB)")
HISTOGRAM(MEMORY_HEAP_ALLOCATED, 1024, 1024 * 1024, 50, EXPONENTIAL, "Heap memory allocated (KB)")
HISTOGRAM(MEMORY_EXPLICIT, 1024, 1024 * 1024, 50, EXPONENTIAL, "Explicit memory allocations (KB)")
#if defined(XP_MACOSX)
HISTOGRAM(MEMORY_FREE_PURGED_PAGES_MS, 1, 1024, 10, EXPONENTIAL, "Time(ms) to purge MADV_FREE'd heap pages.")
#endif
#if defined(XP_WIN)
HISTOGRAM(EARLY_GLUESTARTUP_READ_OPS, 1, 100, 12, LINEAR, "ProcessIoCounters.ReadOperationCount before glue startup")
HISTOGRAM(EARLY_GLUESTARTUP_READ_TRANSFER, 1, 50 * 1024, 12, EXPONENTIAL, "ProcessIoCounters.ReadTransferCount before glue startup (KB)")

Просмотреть файл

@ -42,6 +42,27 @@
#include "nsMemoryReporterManager.h"
#include "nsArrayEnumerator.h"
#include "nsISimpleEnumerator.h"
#include "mozilla/Telemetry.h"
using namespace mozilla;
#if defined(MOZ_MEMORY)
# if defined(XP_WIN) || defined(SOLARIS) || defined(ANDROID) || defined(XP_MACOSX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc.h"
# elif defined(XP_LINUX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc_types.h"
// jemalloc is directly linked into firefox-bin; libxul doesn't link
// with it. So if we tried to use jemalloc_stats directly here, it
// wouldn't be defined. Instead, we don't include the jemalloc header
// and weakly link against jemalloc_stats.
extern "C" {
extern void jemalloc_stats(jemalloc_stats_t* stats)
NS_VISIBILITY_DEFAULT __attribute__((weak));
}
# endif // XP_LINUX
#endif // MOZ_MEMORY
#if defined(XP_LINUX) || defined(XP_MACOSX)
@ -125,6 +146,20 @@ static PRInt64 GetVsize()
static PRInt64 GetResident()
{
#ifdef HAVE_JEMALLOC_STATS
// If we're using jemalloc on Mac, we need to instruct jemalloc to purge
// the pages it has madvise(MADV_FREE)'d before we read our RSS. The OS
// will take away MADV_FREE'd pages when there's memory pressure, so they
// shouldn't count against our RSS.
//
// Purging these pages shouldn't take more than 10ms or so, but we want to
// keep an eye on it since GetResident() is called on each Telemetry ping.
{
Telemetry::AutoTimer<Telemetry::MEMORY_FREE_PURGED_PAGES_MS> timer;
jemalloc_purge_freed_pages();
}
#endif
task_basic_info ti;
return (PRInt64) (GetTaskBasicInfo(&ti) ? ti.resident_size : -1);
}
@ -255,24 +290,6 @@ NS_MEMORY_REPORTER_IMPLEMENT(Resident,
** at least -- on OSX, there are sometimes other zones in use).
**/
#if defined(MOZ_MEMORY)
# if defined(XP_WIN) || defined(SOLARIS) || defined(ANDROID) || defined(XP_MACOSX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc.h"
# elif defined(XP_LINUX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc_types.h"
// jemalloc is directly linked into firefox-bin; libxul doesn't link
// with it. So if we tried to use jemalloc_stats directly here, it
// wouldn't be defined. Instead, we don't include the jemalloc header
// and weakly link against jemalloc_stats.
extern "C" {
extern void jemalloc_stats(jemalloc_stats_t* stats)
NS_VISIBILITY_DEFAULT __attribute__((weak));
}
# endif // XP_LINUX
#endif // MOZ_MEMORY
#if HAVE_JEMALLOC_STATS
static PRInt64 GetHeapUnallocated()