当Linux机器有更多内存时,为什么我的高内存需要代码可以在MacOS上运行,而不能在Linux上运行?

所以我有一个需要大量内存的程序,需要分配一个(稀疏的)600 000 x 600 000 整数数组。虽然我相信这可以在空间和内存要求方面得到改善,但我无法在我的机器 (Manjaro Linux x86_64) 上运行它 40gb 内存而我的上司能够在他的机器上运行它 16gb 内存和在 MacOS(64 位)上。在我的机器上运行时,程序会一直运行,直到它尝试访问malloc该数组,然后程序被终止。

至于更多信息,我已经仔细检查过,这是完全相同的代码,我们正在以完全相同的方式编译它。话虽如此,gcc -v对我来说的输出是:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-werror gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC) 

相比之下,我上级计算机上的输出是:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode/app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.2)
Target: x86_64-apple-darwin19.5.0
Thread mode: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

如果我可以提供更多相关信息,请告诉我。


相关线路是:

回答

强调过量使用的Linux 文档:

Linux 内核支持以下过载处理模式

0 - 启发式过量使用处理。明显的地址空间过度使用被拒绝。用于典型系统。它确保严重的疯狂分配失败,同时允许过度使用以减少交换使用。在这种模式下允许 root 分配更多的内存。这是默认设置。

1 - 总是过量使用。适用于某些科学应用。经典示例是使用稀疏数组的代码,
并且仅依赖几乎完全由零页组成的虚拟内存。

(……)

您可以更改为模式 #1 sudo sysctl vm.overcommit_memory=1


以上是当Linux机器有更多内存时,为什么我的高内存需要代码可以在MacOS上运行,而不能在Linux上运行?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>