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

HPCC-32912 Ensure the row manager peak pages is updated correctly #19251

Merged
merged 1 commit into from
Nov 4, 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
21 changes: 16 additions & 5 deletions roxie/roxiemem/roxiemem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5155,18 +5155,23 @@ class CChunkingRowManager : public CRowManager
unsigned pageLimit = getPageLimit();
if (totalPages <= pageLimit)
{
unsigned newHeapPages;
if (pageLimit != UNLIMITED_PAGES)
{
//Use compare_exchange so that only one thread can increase the number of pages at a time.
//(Don't use atomic_add because we need to check the limit hasn't been exceeded.)
if (!totalHeapPages.compare_exchange_weak(numHeapPages, numHeapPages + numRequested, std::memory_order_relaxed))
newHeapPages = numHeapPages + numRequested;
if (!totalHeapPages.compare_exchange_weak(numHeapPages, newHeapPages, std::memory_order_relaxed))
continue;
}
else
{
//Unlimited pages => just increment the total
totalHeapPages.fetch_add(numRequested, std::memory_order_relaxed);
newHeapPages = totalHeapPages.fetch_add(numRequested, std::memory_order_relaxed) + numRequested;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fetch_add(), should we be adding numRequested twice ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, no, its correct as is. fetch_add() returns value before increment

}

//Ensure the total is correct if two threads allocate big blocks of memory at the same time
totalPages = dataBuffPages + newHeapPages;
break;
}

Expand Down Expand Up @@ -5203,9 +5208,15 @@ class CChunkingRowManager : public CRowManager

if (totalPages > peakPages)
{
if (trackMemoryByActivity)
getPeakActivityUsage();
peakPages = totalPages;
unsigned value = totalPages;
//Atomically update the peak - this could temporarily reduce the value, but it will eventually be correct.
while (value > peakPages.load())
value = peakPages.exchange(value, std::memory_order_acq_rel);

//Check if this thread actually updated the peak value - or did another thread beat us to it.
if (totalPages == peakPages)
if (trackMemoryByActivity)
getPeakActivityUsage();
}
return totalPages;
}
Expand Down
Loading