git svn clone出现Out of memory, malloc failed报错

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010039418/article/details/86154339

背景

最近在迁移svn仓库到gitlab,小的工程很快就搞好了,偏偏有一个工程很大,十几个G,每次到最后就报out of memory,甚是郁闷。

Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 32040, done.
Compressing objects: 100% (30059/30059), done.
fatal: Out of memory, malloc failed  
error: failed to run repack
gc --auto: command returned error: 255

处理过程

1、增加内存

从错误上看,是内存不足,想到自己用的是虚拟机,于是果断加了1G,还是报错。再加内存怕是没那么多可以加的了,于是想到用swap,看了下报错时的内存和swap状态,看来确实要加点料。

[root@CentOS-6-5 /home]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda3                               partition       2031608 1119660 -1
[root@CentOS-6-5 /home]# free -m
             total       used       free     shared    buffers     cached
Mem:          2004       1918         86          0          0          4
-/+ buffers/cache:       1912         91
Swap:         1983       1093        890

2、增加swap

由于虚拟机没有多余磁盘分区,那就只能用文件来替代了。思想就是dd一个空文件,格式化成swap分区,然后挂载。

[root@CentOS-6-5 /home]# dd if=/dev/zero of=/root/swapfile bs=1M count=2048
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB) copied, 14.0209 s, 153 MB/s
[root@CentOS-6-5 /home]# ll -h /root/swapfile
-rw-r--r-- 1 root root 2.0G Jan  9 22:08 /root/swapfile
[root@CentOS-6-5 /home]# mkswap /root/swapfile
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=0651781c-5eca-4915-9684-fd56523e3803
[root@CentOS-6-5 /home]# swapon /root/swapfile
[root@CentOS-6-5 /home]# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda3                               partition	2031608	35316	-1
/root/swapfile                          file		2097144	0	-2

如果要保持重启不丢失,还需要将这个分区挂载信息加到/etc/fstab中,

echo "/root/swapfile swap swap defaults 0 0" >> /etc/fstab

再次执行git svn clone,顺利过关。

猜你喜欢

转载自blog.csdn.net/u010039418/article/details/86154339