Repository navigation
[AIPROFVIS-516] [AIPROFVIS-762] Fail the job instead of terminating when an exception is thrown, and handle failed memory pool allocations - #1150
dhingora-amd wants to merge 12 commits into
Conversation
…handle failed memory pool allocations.
Security scan found no critical or high findings on lines changed by this pull requestView the security scan run for complete reports. “New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta. |
|
My suspicion is that this fix will leave the track data in a "bad" state, without the view (User) being notified. Also if memory pressure is high enough that allocations are failing, I'm not sure that other parts of the system won't be falling apart too. In any case - this is probably better than out right crashing (current situation) but potentially silently leaving holes in the data is also not good. |
|
As suspected ... AI REVIEW The approach is sound, but I'd like a few changes before merging. Worker threads no longer die on an exception, and segments no longer stay stuck as "being fetched". However, for the most likely out-of-memory spot, allocating events during a track fetch, the error never reaches the job result. That case now turns into silently missing data instead of a failed job. There's also a new assert crash in Debug builds on the graph path. 1. Track fetch failures are overwritten by the segment walk In if(result != kRocProfVisResultCancelled)
{
result = GetSegments()->FetchSegments(start, end, user_ptr, future, func);
}So an out-of-memory or exception result from
Suggested fix: keep the first non-success result across the loop and don't let the walk replace a failure, the same way it already treats cancellation. 2.
ROCPROFVIS_ASSERT(result == kRocProfVisResultSuccess ||
result == kRocProfVisResultOutOfRange ||
result == kRocProfVisResultCancelled);
Suggested fix: drop the assert or allow those two result codes. 3. A failure in an earlier request or range is masked by a later success These lines are untouched, but the PR now relies on them:
Before this PR an allocation failure ended the process, so these paths never had to report one. Minor
SummaryIssues 1 and 2 are why I'm requesting changes. Issue 1 means an allocation failure on a graph fetch can leave wrong data cached and displayed with no error. Issue 2 is a crash in Debug builds. Both fixes are small and stay within the files this PR already changes. Recovering from memory pressure (evicting the cache and retrying with a cooldown) and showing the failure on the track in the View can be a follow-up. |
Clean up all of the downstream code that did special handling for kRocProfVisResultOutOfRange.
A range with 1M or more events is split into two read requests. If one failed to start, the fetch still reported success and the range was marked valid with part of its events missing. The fetch now fails with kRocProfVisResultUnknownError when fewer requests start than were asked for, unless it was cancelled. The requests that did start are still processed so their slices and futures are released.
Adds the "Graph Range With Empty LOD Segment" section. It finds an LOD segment of an event graph that covers no track segment, followed later by one with events, and fetches the segments between them first. A fetch across all of them is then split into an empty range and a range with events, and must succeed and return the events. Before empty ranges were treated as success, this fetch returned kRocProfVisResultOutOfRange with no entries, even though the segment with events had been generated. The section finds a layout like this in both sample traces and fails if neither has one.
…fVisResultOutOfRange (#1217) * Treat empty track areas as success, not kRocProfVisResultOutOfRange Clean up all of the downstream code that did special handling for kRocProfVisResultOutOfRange. * Fail a track fetch when only some of its read requests start A range with 1M or more events is split into two read requests. If one failed to start, the fetch still reported success and the range was marked valid with part of its events missing. The fetch now fails with kRocProfVisResultUnknownError when fewer requests start than were asked for, unless it was cancelled. The requests that did start are still processed so their slices and futures are released.
Passing a lambda converted it to a std::function at the call site, which can allocate for larger captures. A failed allocation threw before the try, so the cleanup the wrapper protects was skipped, such as clearing the processed flags on segments. The template takes the callable by reference, so nothing can throw before the try. The logging moves into out-of-line functions so the header doesn't need spdlog.
Track::FetchSegments and Graph::GenerateLOD mark segments processed while building their list of fetch ranges, and only clear the marks after the fetch. If push_back threw while growing the list, the exception was now caught, so the marks stayed set and later fetches of those segments waited forever. Reserving room for every segment in the request up front means push_back can't allocate.
…ot if the object constructor throws MemoryManager::Allocate created the pool with a raw new, then inserted it into m_object_pools. If either map operation threw, the pool leaked. Hold it in a unique_ptr until m_object_pools owns it. Allocate marks a slot as used before the object is constructed in it. If the constructor threw (SampleLOD copies its children vector), the slot stayed marked, and CleanUp later called ~Handle() on memory that was never constructed. Split the slot release out of Delete into FreeSlot, and call it without a destructor from NewEvent, NewSample and NewSampleLOD when construction throws.
…hrows and release a pool slot if the object constructor throws"): drop the try/catch it added around the placement new in NewEvent and NewSample. Also drop the unused iterator from the emplace in Allocate.
Motivation
An exception thrown inside a controller job (for example
std::bad_allocfrom the pool allocator) escaped its worker thread and terminated the app. Catching it alone isn't enough: an exception partway through a track or graph fetch left its segments marked as being fetched, so later fetches waited forever.Technical Details
CallCatchingExceptionsturns exceptions into failed results.Job::Executeuses it, and so do the track and graph fetch code, so fetch marks and model slices are always cleaned up.MemoryManager::Allocatereturnsnullptrinstead of throwing, and the graph's level-of-detail code now handles thatnullptr.This PR now includes the changes described here: #1217