Skip to content

Commit 23a6210

Browse files
[ARRISEOS-47214] Video memory footprint in MemoryPressure
1 parent 9c815b5 commit 23a6210

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

Source/WTF/wtf/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ set(WTF_LIBRARIES
575575
ICU::data
576576
ICU::i18n
577577
ICU::uc
578+
gpumem
578579
)
579580

580581
if (NOT USE_SYSTEM_MALLOC)

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "config.h"
2727
#include <wtf/MemoryPressureHandler.h>
28+
#include <gpumem.h>
2829

2930
#if OS(LINUX)
3031
#include <unistd.h>
@@ -91,21 +92,11 @@ static bool isWebProcess()
9192

9293
static size_t memoryFootprintVideo()
9394
{
94-
if (!isWebProcess() || s_GPUMemoryFile.isEmpty())
95-
return 0;
96-
97-
FILE* file = fopen(s_GPUMemoryFile.utf8().data(), "r");
98-
if (!file)
99-
return 0;
100-
101-
char* buffer = nullptr;
102-
size_t size = 0;
95+
uint32_t totalMemory = 0, availableMemory = 0;
10396
size_t footprint = 0;
104-
if (getline(&buffer, &size, file) != -1)
105-
sscanf(buffer, "%u", &footprint);
106-
107-
free(buffer);
108-
fclose(file);
97+
if (gpumem_video_memory_total(&totalMemory) == 0 && gpumem_video_memory_available(0, &availableMemory) == 0) {
98+
footprint = (totalMemory - availableMemory);
99+
}
109100

110101
return footprint;
111102
}
@@ -322,7 +313,10 @@ void MemoryPressureHandler::measurementTimerFired()
322313
static size_t footprintPeak = 0;
323314
if (footprintPeak < footprint)
324315
footprintPeak = footprint;
325-
RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB, video footprint: %zu MB", footprint / MB, footprintPeak / MB, footprintVideo / MB);
316+
if (isWebProcess())
317+
RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB, video footprint: %zu MB", footprint / MB, footprintPeak / MB, footprintVideo / MB);
318+
else
319+
RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB", footprint / MB, footprintPeak / MB);
326320
auto killThreshold = thresholdForMemoryKill(MemoryType::Normal);
327321
auto killThresholdVideo = thresholdForMemoryKill(MemoryType::Video);
328322
if ((killThreshold && footprint >= *killThreshold) || (killThresholdVideo && footprintVideo >= *killThresholdVideo)) {

0 commit comments

Comments
 (0)