Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux]DGSW_2_3 fails CurrentHeapUsed is greater than CurrentHeapHighWatermark #33252

Merged
merged 4 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/platform/Linux/DiagnosticDataProviderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ enum class WiFiStatsCountType
kWiFiOverrunCount
};

// Static variable to store the maximum heap size
static size_t maxHeapHighWatermark = 0;

CHIP_ERROR GetEthernetStatsCount(EthernetStatsCountType type, uint64_t & count)
{
CHIP_ERROR err = CHIP_ERROR_READ_FAILED;
Expand Down Expand Up @@ -244,6 +247,11 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapUsed(uint64_t & currentHeap
// the current running program.
currentHeapUsed = mallocInfo.uordblks;

// Update the maximum heap high watermark if the current heap usage exceeds it.
if (currentHeapUsed > maxHeapHighWatermark)
{
maxHeapHighWatermark = currentHeapUsed;
}
return CHIP_NO_ERROR;
#endif
}
Expand All @@ -260,9 +268,15 @@ CHIP_ERROR DiagnosticDataProviderImpl::GetCurrentHeapHighWatermark(uint64_t & cu
// has been used by the Node.
// On Linux, since it uses virtual memory, whereby a page of memory could be copied to
// the hard disk, called swap space, and free up that page of memory. So it is impossible
// to know accurately peak physical memory it use. We just return the current heap memory
// being used by the current running program.
currentHeapHighWatermark = mallocInfo.uordblks;
// to know accurately peak physical memory it use.
// Update the maximum heap high watermark if the current heap usage exceeds it.
if (mallocInfo.uordblks > static_cast<int>(maxHeapHighWatermark))
{
maxHeapHighWatermark = mallocInfo.uordblks;
}

// Set the current heap high watermark.
currentHeapHighWatermark = maxHeapHighWatermark;

return CHIP_NO_ERROR;
#endif
Expand All @@ -275,6 +289,8 @@ CHIP_ERROR DiagnosticDataProviderImpl::ResetWatermarks()

// On Linux, the write operation is non-op since we always rely on the mallinfo system
// function to get the current heap memory.
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
struct mallinfo mallocInfo = mallinfo();
maxHeapHighWatermark = mallocInfo.uordblks;

return CHIP_NO_ERROR;
}
Expand Down
Loading