Set max_alloc to 95%,reduce by 1% on fail

Prevents OOM-Killer trigger,if all physical and swap mem gets fully used

Change-Id: I70d558fa9c06fe6217e62d57e11aec6a089aa0bb


[ROCm/ROCR-Runtime commit: 13800cc6d5]
This commit is contained in:
Shweta Khatri
2024-02-05 12:55:13 -05:00
committed by David Yat Sin
parent 1f38927b0d
commit 7a310f2e91
@@ -233,7 +233,10 @@ void MemoryTest::MaxSingleAllocationTest(hsa_agent_t ag,
std::min(pool_sz, info.totalram / gran_sz) :
pool_sz;
uint64_t upper_bound = pool_sz;
// Reduce upper_bound by 5% for system-RAM. Otherwise Linux OOM-Killer app can be triggered,
// if system has allocated all available physical memory and swap space, and so killing this
// process.
uint64_t upper_bound = (ag_type == HSA_DEVICE_TYPE_CPU) ? (pool_sz * 0.95) : pool_sz;
uint64_t lower_bound = 0;
auto max_alloc_size = upper_bound;
@@ -247,7 +250,8 @@ void MemoryTest::MaxSingleAllocationTest(hsa_agent_t ag,
} else if (err == HSA_STATUS_ERROR_OUT_OF_RESOURCES ||
err == HSA_STATUS_ERROR_INVALID_ALLOCATION) {
upper_bound = max_alloc_size;
max_alloc_size -= 1;
max_alloc_size =
static_cast<uint64_t>(max_alloc_size * 0.99); // Reduce by 1% in each iteration
}
ASSERT_GT(upper_bound, lower_bound);