欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Git使用小坑 Out of memory錯誤的解決方法

 更新時間:2015年10月19日 13:13:44   作者:UndeadWraith  
這篇文章主要介紹了Git使用小坑 Out of memory錯誤的解決方法,需要的朋友可以參考下

最近公司將內部使用的代碼由svn遷到了git上,所以也必須學者使用Git命令。


雖說git的模式和svn區(qū)別很大,但想必也不是什么難事。但沒曾想在第一步git clone的時候就踩到了一個大坑……廢話不多提,先看錯誤代碼:

復制代碼 代碼如下:

Cloning into XXXX...
remote: Couting objects: 125627, done.
remote: Compressing objects: 100% (47061/47061), done.
fatal: Out of memory, malloc failed (tried to allocate 1941159936 bytes)

就這幾行錯誤碼,生生的把我給絆住了一天……

0x00 調內存

看到“Out of memory, malloc failed”,第一反應是內存不足。畢竟虛擬機內存太小,Debian的虛擬機只給了512M的內存,再加上自己沒事鼓搗著玩,自己裝了一堆亂七八糟的程序,free的只有幾十兆了。


于是果斷把亂七八糟的進程結束掉,服務停掉,沒用的東西全關了。最后又把虛擬機的內存調到了1G.

結果——fatal依然……

0x01 調配置

后來又看了下這句——“allocate 1941159936 bytes”——這是1.8G啊……這能有多大內存給他啊……調內存顯然不是辦法。于是上網搜了一下這個報錯,發(fā)現都是讓調配置的:

復制代碼 代碼如下:

git config --global pack.threads 1 git
config --global pack.deltaCacheSize = 128m
git config --global pack.windowMemory 50m

順便吐槽一句——國內博客全都在抄這個配置……還把Cache抄成了Chase……復制都不會么……


這樣一來,應該是可以減小資源的占用,但遺憾的是貌似git根本沒拾這茬,依然是義無反顧的申請了1.8個G的空間……

當然,結果——再一次的fatal依然……


另外,我還找了另一個哥們做了個試驗,他的虛擬機里就可以正常clone(1G內存,free不到100M),而我手上的兩個虛擬機則都無法正常clone(1G內存,free超過800M 和 2G內存,free將近1.3G)。看起來和內存沒什么關系了

0x02 調swap

最后終于看到了這篇:http://stackoverflow.com/questions/14038074/git-pull-fatal-out-of-memory-malloc-failed

讓我眼前一亮的是這個帖子里貼出的錯誤代碼和我的幾乎一模一樣,而且在一開始就寫明了上面的所謂配置方案都已經試過了,但依然無效——和我遇到的情況完全一樣。不過他最后的結果是:

In the end i had to kill old & create new repo.

貌似是沒找到什么好的解決方案……

但當我翻到最下面的時候眼前一亮——“To get around this I temporarily created a large swap drive...”。“a large swap”……醍醐灌頂啊……我立馬問了下能正常clone的那個哥們的虛擬機給了多少swap空間,得到的答復是2G,而我手里的——1G和0……和0……和……0……0……0……

原來我需要的是一個大的swap!

雖然我的swap已經是劃分好了的,但還是可以添加的,具體方法這篇帖子中也給出了鏈接:http://www.thegeekstuff.com/2010/08/how-to-add-swap-space/

使用Method2,完美解決。

Method 2: 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

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

復制代碼 代碼如下:

# chmod 600 /root/myswapfile

Make this file as a swap file using mkswap command.

復制代碼 代碼如下:

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

Enable the newly created swapfile.

復制代碼 代碼如下:

# swapon /root/myswapfile

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

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

Note: In the output of swapon -s command, the Type column will say “file” if the swap space is created from a swap file.

If you don't want to reboot to verify whether the system takes all the swap space mentioned in the /etc/fstab, you can do the following, which will disable and enable all the swap partition mentioned in the /etc/fstab

復制代碼 代碼如下:

# swapoff -a
# swapon -a

說實在的我一直不太關心swap的大小,總覺得沒啥用處。這一次就讓我長記性了——swap還是必要的!

相關文章

最新評論