From 94e70bee268f7471b4e628ee79cf0809f018fc13 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Fri, 25 Aug 2023 13:29:24 +0000 Subject: [PATCH] SWDEV-419034 - Use MADV_HUGEPAGE for large host allocations Change-Id: I80bb1839cdd47eb64a97467c8b01fcdf37195ad5 --- rocclr/os/os_posix.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; }