Bug 1477512: Part 4 - Add memory reporter for thread kernel stack sizes. r?erahm
We don't have a way to determine these at runtime, but for Windows and Linux,
the values are known and predictable.
MozReview-Commit-ID: 57LMJLzl762
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -1428,18 +1428,20 @@ public:
nsCString mName;
uint32_t mThreadId;
size_t mPrivateSize;
};
AutoTArray<ThreadData, 32> threads;
size_t eventQueueSizes = 0;
size_t wrapperSizes = 0;
+ size_t threadCount = 0;
for (auto* thread : nsThread::Enumerate()) {
+ threadCount++;
eventQueueSizes += thread->SizeOfEventQueues(MallocSizeOf);
wrapperSizes += thread->ShallowSizeOfIncludingThis(MallocSizeOf);
if (!thread->StackBase()) {
continue;
}
#if defined(XP_LINUX)
@@ -1524,16 +1526,39 @@ public:
eventQueueSizes,
"The sizes of nsThread event queues and observers.");
MOZ_COLLECT_REPORT(
"explicit/threads/overhead/wrappers", KIND_HEAP, UNITS_BYTES,
wrapperSizes,
"The sizes of nsThread/PRThread wrappers.");
+#if defined(XP_WIN)
+ // Each thread on Windows has a fixed kernel overhead. For 32 bit Windows,
+ // that's 12K. For 64 bit, it's 24K.
+ constexpr size_t kKernelSize = (sizeof(void*) == 8 ? 24 : 12) * 1024;
+#elif defined(XP_LINUX)
+ // On Linux, kernel stacks are usually 8K. However, on x86, they are
+ // allocated virtually, and start out at 4K. They may grow to 8K, but we
+ // have no way of knowing which ones do. So all we can do is guess.
+#if defined(__x86_64__) || defined(__i386__)
+ constexpr size_t kKernelSize = 4 * 1024;
+#else
+ constexpr size_t kKernelSize = 8 * 1024;
+#endif
+#else
+ // Elsewhere, just assume that kernel stacks require at least 8K.
+ constexpr size_t kKernelSize = 8 * 1024;
+#endif
+
+ MOZ_COLLECT_REPORT(
+ "explicit/threads/overhead/kernel", KIND_NONHEAP, UNITS_BYTES,
+ threadCount * kKernelSize,
+ "The total kernel overhead for all active threads.");
+
return NS_OK;
}
};
NS_IMPL_ISUPPORTS(ThreadsReporter, nsIMemoryReporter)
#ifdef DEBUG
// Ideally, this would be implemented in BlockingResourceBase.cpp.