mozga-intel commented on a change in pull request #20412:
URL: https://github.com/apache/incubator-mxnet/pull/20412#discussion_r754989260
##########
File path: src/common/utils.h
##########
@@ -983,9 +986,21 @@ inline bool AlignedMemAlloc(void** ptr, size_t size,
size_t alignment) {
if (*ptr == nullptr)
return false;
#else
- int res = posix_memalign(ptr, alignment, size);
- if (res != 0)
+ int res = posix_memalign(ptr, alignment, size);
+#if __linux__
+ constexpr size_t gHugePage2MB = 1 << 21;
+ if (size >= gHugePage2MB) {
Review comment:
Of course, we can replace N with some suitable number, but it is not
easy! Depending on the processor architecture, there are at least two different
huge page size. On the 86_64 architecture: there is available 2MB and 1GB. This
`grep pse /proc/cpuinfo | uniq` if this command returns a string and a string
is non-empty; then either 2MB pages are supported or maybe 1GB is supported
`grep pdpe1gb /proc/cpuinfo | uniq` (The 1GiB THP is supported only on the
processors with the pdpeg1b CPU flag). Well, the default page size is equal to
4KiB ~ in my scenario I had only possibility to check max: ~2MB THP.
##########
File path: src/common/utils.h
##########
@@ -983,9 +986,21 @@ inline bool AlignedMemAlloc(void** ptr, size_t size,
size_t alignment) {
if (*ptr == nullptr)
return false;
#else
- int res = posix_memalign(ptr, alignment, size);
- if (res != 0)
+ int res = posix_memalign(ptr, alignment, size);
+#if __linux__
+ constexpr size_t gHugePage2MB = 1 << 21;
+ if (size >= gHugePage2MB) {
+ // TODO(mozga-intel): Enable MacOS Huge Pages if desired
+ res = posix_memalign(ptr, gHugePage2MB, size);
+ if (res == 0) {
+ madvise(ptr, size, MADV_HUGEPAGE);
Review comment:
Yeah, by default THP is `madvise` in which case it’s necessary to call
`madvise(...MADV_HUGEPAGE)`. It gives opportunity to specifically enable THP
for a range of memory. Well, Linux (THP) support does not guarantee that HP
will be allocated. It means that it works only if THP support is enabled (the
status of THP can be checked under /sys/kernel/). Hence, madvise should sets a
flag for all the memory mapping corresponding to the a region that is passed
directly to it ~ which will be the case in most Linux distribution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]