Fix ‘MADV_HUGEPAGE’ undeclared compilation error (#1012)

In some Linux systems whose kernel version is smaller than 2.6.38, the macro
MADV_HUGEPAGE isn't introduced yet which causes compilation error.
Add macro control to fix the compilation error.
This commit is contained in:
Namhyeon Go 2022-02-18 12:25:06 +09:00 committed by GitHub
parent 9fc124b06f
commit 0d1060b3cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ static size_t total_size_munmapped = 0;
#define HUGE_PAGE_SIZE (2 * 1024 * 1024)
#if !defined(__APPLE__) && !defined(__NuttX__)
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
static inline uintptr_t
round_up(uintptr_t v, uintptr_t b)
{
@ -44,7 +44,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
page_size = (uint64)getpagesize();
request_size = (size + page_size - 1) & ~(page_size - 1);
#if !defined(__APPLE__) && !defined(__NuttX__)
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
/* huge page isn't supported on MacOS and NuttX */
if (request_size >= HUGE_PAGE_SIZE)
/* apply one extra huge page */
@ -148,7 +148,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
addr, request_size, total_size_mmapped, total_size_munmapped);
#endif
#if !defined(__APPLE__) && !defined(__NuttX__)
#if !defined(__APPLE__) && !defined(__NuttX__) && defined(MADV_HUGEPAGE)
/* huge page isn't supported on MacOS and NuttX */
if (request_size > HUGE_PAGE_SIZE) {
uintptr_t huge_start, huge_end;
@ -200,7 +200,7 @@ os_mmap(void *hint, size_t size, int prot, int flags)
}
}
}
#endif /* end of __APPLE__ || __NuttX__ */
#endif /* end of __APPLE__ || __NuttX__ || !MADV_HUGEPAGE */
return addr;
}