我要评分
获取效率
正确性
完整性
易理解

"Cannot allocate memory" Displayed When Compiling RocksDB

Symptom

The error message "Cannot allocate memory" is displayed when compiling RocksDB.

Key Process and Cause Analysis

When make -j is executed for RocksDB compilation, all CPU cores are used. As a result, the memory becomes insufficient.

Conclusion and Solution

  1. Delete all files and subdirectories in the current directory.
    rm -rf *
  2. Use the CMake tool to compile and install RocksDB and specify the installation path, for example, /usr/local/rocksdb.
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rocksdb -DWITH_SNAPPY=1 -DWITH_ZLIB=1 -DWITH_LZ4=1 -DWITH_ZSTD=1 -DWITH_BZ2=1 ..
  3. Check the number of CPU cores.
    lscpu
  4. Run the compile command again. In the following command, the number of CPU cores to be used is reduced.
    make -j 8