/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"mozilla/AvailableMemoryTracker.h"
#ifdefined(XP_WIN) # include <windows.h> # include "nsIMemoryReporter.h" #endif
# ifdefined(__MINGW32__) // Definitions for heap optimization that require the Windows SDK to target the // Windows 8.1 Update staticconst HEAP_INFORMATION_CLASS HeapOptimizeResources = static_cast<HEAP_INFORMATION_CLASS>(3);
class LowEventsReporter final : public nsIMemoryReporter {
~LowEventsReporter() {}
public:
NS_DECL_ISUPPORTS
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData, bool aAnonymize) override { // clang-format off
MOZ_COLLECT_REPORT( "low-memory-events/physical", KIND_OTHER, UNITS_COUNT_CUMULATIVE,
LowMemoryEventsPhysicalDistinguishedAmount(), "Number of low-physical-memory events fired since startup. We fire such an " "event when a windows low memory resource notification is signaled. The " "machine will start to page if it runs out of physical memory. This may " "cause it to run slowly, but it shouldn't cause it to crash."); // clang-format on
/** * This runnable is executed in response to a memory-pressure event; we spin * the event-loop when receiving the memory-pressure event in the hope that * other observers will synchronously free some memory that we'll be able to * purge here.
*/ class nsJemallocFreeDirtyPagesRunnable final : public Runnable {
~nsJemallocFreeDirtyPagesRunnable() = default;
/** * The memory pressure watcher is used for listening to memory-pressure events * and reacting upon them. We use one instance per process currently only for * cleaning up dirty unused pages held by jemalloc.
*/ class nsMemoryPressureWatcher final : public nsIObserver {
~nsMemoryPressureWatcher() = default;
/** * Initialize and subscribe to the memory-pressure events. We subscribe to the * observer service in this method and not in the constructor because we need * to hold a strong reference to 'this' before calling the observer service.
*/ void nsMemoryPressureWatcher::Init() {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
/** * Reacts to all types of memory-pressure events, launches a runnable to * free dirty pages held by jemalloc.
*/
NS_IMETHODIMP
nsMemoryPressureWatcher::Observe(nsISupports* aSubject, constchar* aTopic, const char16_t* aData) {
MOZ_ASSERT(!strcmp(aTopic, "memory-pressure"), "Unknown topic");
nsCOMPtr<nsIRunnable> runnable = new nsJemallocFreeDirtyPagesRunnable();
NS_DispatchToMainThread(runnable);
return NS_OK;
}
} // namespace
namespace mozilla { namespace AvailableMemoryTracker {
void Init() { // The watchers are held alive by the observer service.
RefPtr<nsMemoryPressureWatcher> watcher = new nsMemoryPressureWatcher();
watcher->Init();
} // namespace AvailableMemoryTracker
} // namespace mozilla
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.13Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.