wsl/hsakmt: Remove pre-allocation free memory check
This change removes the check for sufficient free memory before allocation. The previous check could cause performance degradation. Reserving a portion of system memory helps prevent system hangs due to insufficient memory. However, if free memory is still insufficient, memory allocation may still lead to system hangs. 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/10>
This commit is contained in:
+3
-1
@@ -44,4 +44,6 @@ bool is_svm_api_supported;
|
||||
/* zfb is mainly used during emulation */
|
||||
int zfb_support;
|
||||
/* handle vendor specific packet */
|
||||
int vendor_packet_support;
|
||||
int vendor_packet_support;
|
||||
|
||||
size_t max_single_alloc_size = 0;
|
||||
@@ -43,6 +43,7 @@ extern bool is_dgpu;
|
||||
extern bool is_svm_api_supported;
|
||||
extern int zfb_support;
|
||||
extern int vendor_packet_support;
|
||||
extern size_t max_single_alloc_size;
|
||||
|
||||
#undef HSAKMTAPI
|
||||
#define HSAKMTAPI __attribute__((visibility ("default")))
|
||||
|
||||
+3
-16
@@ -105,18 +105,6 @@ 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;
|
||||
}
|
||||
|
||||
bool isLocalMemoryAvailable(wsl::thunk::WDDMDevice *dev,
|
||||
HSAuint64 SizeInBytes) {
|
||||
return SizeInBytes <= dev->VramAvail();
|
||||
}
|
||||
|
||||
HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemoryAlign(HSAuint32 PreferredNode,
|
||||
HSAuint64 SizeInBytes,
|
||||
HSAuint64 Alignment,
|
||||
@@ -149,17 +137,16 @@ HSAKMT_STATUS HSAKMTAPI hsaKmtAllocMemoryAlign(HSAuint32 PreferredNode,
|
||||
create_info.va_hint = reinterpret_cast<gpusize>(*MemoryAddress);
|
||||
if ((PreferredNode == 0 && !MemFlags.ui32.NonPaged)
|
||||
|| zfb_support || MemFlags.ui32.GTTAccess) {
|
||||
if (SizeInBytes > max_single_alloc_size)
|
||||
return HSAKMT_STATUS_NO_MEMORY;
|
||||
|
||||
/* If allocate VRAM under ZFB mode */
|
||||
if (zfb_support && MemFlags.ui32.NonPaged == 1)
|
||||
MemFlags.ui32.CoarseGrain = 1;
|
||||
|
||||
create_info.domain = rocr_proxy::AllocDomain::kSystem;
|
||||
if (!MemFlags.ui32.OnlyAddress && !isSystemMemoryAvailable(SizeInBytes))
|
||||
return HSAKMT_STATUS_NO_MEMORY;
|
||||
} else {
|
||||
create_info.domain = rocr_proxy::AllocDomain::kLocal;
|
||||
if (!MemFlags.ui32.OnlyAddress && !isLocalMemoryAvailable(dev, SizeInBytes))
|
||||
return HSAKMT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
if (!MemFlags.ui32.CoarseGrain)
|
||||
|
||||
@@ -750,6 +750,11 @@ static HSAKMT_STATUS topology_sysfs_get_mem_props(uint32_t node_id,
|
||||
sysinfo(&info);
|
||||
props->SizeInBytes = info.totalram;
|
||||
|
||||
/* props->SizeInBytes is the actual physical system
|
||||
* memory size. Reserve 1/16th for WSL system usage.
|
||||
*/
|
||||
max_single_alloc_size = info.totalram - (info.totalram >> 4);
|
||||
|
||||
props->Flags.MemoryProperty = 0;
|
||||
props->Width = 64;
|
||||
props->MemoryClockMax = 2133;
|
||||
|
||||
Reference in New Issue
Block a user