diff --git a/rocclr/os/os_posix.cpp b/rocclr/os/os_posix.cpp index f48678b026..739795e0cb 100644 --- a/rocclr/os/os_posix.cpp +++ b/rocclr/os/os_posix.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2008 - 2021 Advanced Micro Devices, Inc. +/* Copyright (c) 2008 - 2023 Advanced Micro Devices, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -233,6 +233,17 @@ address Os::reserveMemory(address start, size_t size, size_t alignment, MemProt } } + // Hint to enable THP for large host allocations which can help in performance gain + constexpr size_t kLargePageSize = 2 * Mi; + if (size >= kLargePageSize) { + int status = madvise(aligned, size, MADV_HUGEPAGE); + if (status) { + ClPrint(amd::LOG_DEBUG, amd::LOG_CODE, "madvise with advice MADV_HUGEPAGE" + " starting at address %p and page size 0x%zx, returned %d, errno: %s", + aligned, size, status, strerror(errno)); + } + } + return aligned; }