mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Revert "Enable thp(transparent huge pages) for buffer sizes >=2MB (#95963)"
This reverts commit 3bb16a084298ed8b9a1e59622afd80418ff4a2f1. Reverted https://github.com/pytorch/pytorch/pull/95963 on behalf of https://github.com/izaitsevfb due to Breaks internal android builds: unused function c10_compute_alignment [-Werror,-Wunused-function]
This commit is contained in:
@ -14,8 +14,4 @@ constexpr size_t gAlignment = 16;
|
||||
constexpr size_t gAlignment = 64;
|
||||
#endif
|
||||
|
||||
constexpr size_t gPagesize = 4096;
|
||||
// since the default thp pagesize is 2MB, enable thp only
|
||||
// for buffers of size 2MB or larger to avoid memory bloating
|
||||
constexpr size_t gAlloc_threshold_thp = 2 * 1024 * 1024;
|
||||
} // namespace c10
|
||||
|
@ -41,35 +41,6 @@ void memset_junk(void* data, size_t num) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
static inline bool is_thp_alloc_enabled() {
|
||||
static bool value = [&] {
|
||||
const char* ptr = std::getenv("THP_MEM_ALLOC_ENABLE");
|
||||
return ptr != nullptr ? std::atoi(ptr) : 0;
|
||||
}();
|
||||
return value;
|
||||
}
|
||||
|
||||
inline size_t c10_compute_alignment(size_t nbytes) {
|
||||
static const auto pagesize = sysconf(_SC_PAGESIZE);
|
||||
// for kernels that don't provide page size, default it to 4K
|
||||
const size_t thp_alignment = (gPagesize < 0 ? gPagesize : pagesize);
|
||||
return (is_thp_alloc_enabled() ? thp_alignment : gAlignment);
|
||||
}
|
||||
|
||||
inline bool is_thp_alloc(size_t nbytes) {
|
||||
// enable thp (transparent huge pages) for larger buffers
|
||||
return (is_thp_alloc_enabled() && (nbytes >= gAlloc_threshold_thp));
|
||||
}
|
||||
#elif !defined(__ANDROID__) && !defined(_MSC_VER)
|
||||
constexpr size_t c10_compute_alignment(C10_UNUSED size_t nbytes) {
|
||||
return gAlignment;
|
||||
}
|
||||
|
||||
constexpr bool is_thp_alloc(C10_UNUSED size_t nbytes) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
void* alloc_cpu(size_t nbytes) {
|
||||
@ -100,7 +71,7 @@ void* alloc_cpu(size_t nbytes) {
|
||||
nbytes,
|
||||
" bytes.");
|
||||
#else
|
||||
int err = posix_memalign(&data, c10_compute_alignment(nbytes), nbytes);
|
||||
int err = posix_memalign(&data, gAlignment, nbytes);
|
||||
CAFFE_ENFORCE(
|
||||
err == 0,
|
||||
"DefaultCPUAllocator: can't allocate memory: you tried to allocate ",
|
||||
@ -110,16 +81,6 @@ void* alloc_cpu(size_t nbytes) {
|
||||
" (",
|
||||
strerror(err),
|
||||
")");
|
||||
if (is_thp_alloc(nbytes)) {
|
||||
#ifdef __linux__
|
||||
// MADV_HUGEPAGE advise is available only for linux.
|
||||
// general posix compliant systems can check POSIX_MADV_SEQUENTIAL advise.
|
||||
int ret = madvise(data, nbytes, MADV_HUGEPAGE);
|
||||
if (ret != 0) {
|
||||
TORCH_WARN_ONCE("thp madvise for HUGEPAGE failed with ", strerror(errno));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// move data to a thread's NUMA node
|
||||
|
@ -4,11 +4,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace c10 {
|
||||
|
||||
C10_API void* alloc_cpu(size_t nbytes);
|
||||
|
Reference in New Issue
Block a user