git clone: fatal: Out of memory

我最近在下拉代码的时候,突然莫名其妙的出现

remote: Compressing objects: 100% (9/9), done.
fatal: Out of memory, malloc failed (tried to allocate 6502336643 bytes)
fatal: unpack-objects failed

我就很奇怪,于是就更换了好几个Linux环境,几乎都有这个问题,当时我以为是内存太小,或是磁盘太小?But,仅有的一个能成功clone下来的那个电脑是N年前的一款,内存还没我几个出错的电脑内存的二分之一大。在网上找了很多解决方案都不靠谱。后来在一个脚本之家的网站上有个哥们调整了swap成功了。我也试着这个方法做了一下,也成功了,看来这个swap空间有时候也是很有用处的。以下是我从脚本之家搬运过来的操作过程。

脚本之家链接:https://www.jb51.net/article/73597.htm

step1.

Use a File for Additional Swap Space
If you don't have any additional disks, you can create a file somewhere on your filesystem, and use that file for swap space.

The following dd command example creates a swap file with the name “myswapfile” under /root directory with a size of 1024MB (1GB).

# dd if=/dev/zero of=/root/myswapfile bs=1M count=1024
1024+0 records in
1024+0 records out
# ls -l /root/myswapfile
-rw-r--r--    1 root     root     1073741824 Aug 14 23:47 /root/myswapfile

step2.

Change the permission of the swap file so that only root can access it.

# chmod 600 /root/myswapfile

step3.

Make this file as a swap file using mkswap command.

# mkswap /root/myswapfile
Setting up swapspace version 1, size = 1073737 kB

step4.

Enable the newly created swapfile.

# swapon /root/myswapfile

step5.

To make this swap file available as a swap area even after the reboot, add the following line to the /etc/fstab file.

# cat /etc/fstab
/root/myswapfile               swap                    swap    defaults        0 0

step6.

Verify whether the newly created swap area is available for your use.

# swapon -s
Filename                        Type            Size    Used    Priority
/dev/sda2                       partition       4192956 0       -1
/root/myswapfile                file            1048568 0       -2
# free -k
             total       used       free     shared    buffers     cached
Mem:       3082356    3022364      59992          0      52056    2646472
-/+ buffers/cache:     323836    2758520
Swap:      5241524          0    5241524

The end

swap on/off

# swapoff -a
# swapon -a

 

你可能感兴趣的:(git clone: fatal: Out of memory)