wsl/hsakmt: Introduce WSL_CHECK_AVAIL_SYSRAM environment variable

By default, this variable is 0. Set it to 1 to compare available
system memory with the requested amount before allocation. It helps
identify system hangs caused by excessive memory allocation.

Signed-off-by: lyndonli <Lyndon.Li@amd.com>
Reviewed-by: Flora Cui <flora.cui@amd.com>
Part-of: <http://10.67.69.192/wsl/libhsakmt/-/merge_requests/32>
This commit is contained in:
lyndonli
2024-09-27 10:47:23 +08:00
committed by Frank Min
parent 7a67eb90e2
commit c898104228
4 changed files with 18 additions and 0 deletions
+10
View File
@@ -105,6 +105,13 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemory(HSAuint32 PreferredNode,
#define POWER_OF_2(x) ((x && (!(x & (x - 1)))) ? 1 : 0)
bool isSystemMemoryAvailable(HSAuint64 SizeInBytes) {
struct sysinfo info;
if (sysinfo(&info) != 0)
return false;
return SizeInBytes <= info.freeram;
}
HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemoryAlign(HSAuint32 PreferredNode,
HSAuint64 SizeInBytes,
HSAuint64 Alignment,
@@ -140,6 +147,9 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemoryAlign(HSAuint32 PreferredNode,
if (SizeInBytes > max_single_alloc_size)
return HSAKMT_STATUS_NO_MEMORY;
if (check_avail_sysram && !isSystemMemoryAvailable(SizeInBytes))
return HSAKMT_STATUS_NO_MEMORY;
/* If allocate VRAM under ZFB mode */
if (zfb_support && MemFlags.ui32.NonPaged == 1)
MemFlags.ui32.CoarseGrain = 1;