亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Git使用小坑 Out of memory錯(cuò)誤的解決方法

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

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


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

復(fù)制代碼 代碼如下:

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)

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

0x00 調(diào)內(nèi)存

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


于是果斷把亂七八糟的進(jìn)程結(jié)束掉,服務(wù)停掉,沒(méi)用的東西全關(guān)了。最后又把虛擬機(jī)的內(nèi)存調(diào)到了1G.

結(jié)果——fatal依然……

0x01 調(diào)配置

后來(lái)又看了下這句——“allocate 1941159936 bytes”——這是1.8G啊……這能有多大內(nèi)存給他啊……調(diào)內(nèi)存顯然不是辦法。于是上網(wǎng)搜了一下這個(gè)報(bào)錯(cuò),發(fā)現(xiàn)都是讓調(diào)配置的:

復(fù)制代碼 代碼如下:

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

順便吐槽一句——國(guó)內(nèi)博客全都在抄這個(gè)配置……還把Cache抄成了Chase……復(fù)制都不會(huì)么……


這樣一來(lái),應(yīng)該是可以減小資源的占用,但遺憾的是貌似git根本沒(méi)拾這茬,依然是義無(wú)反顧的申請(qǐng)了1.8個(gè)G的空間……

當(dāng)然,結(jié)果——再一次的fatal依然……


另外,我還找了另一個(gè)哥們做了個(gè)試驗(yàn),他的虛擬機(jī)里就可以正常clone(1G內(nèi)存,free不到100M),而我手上的兩個(gè)虛擬機(jī)則都無(wú)法正常clone(1G內(nèi)存,free超過(guò)800M 和 2G內(nèi)存,free將近1.3G)??雌饋?lái)和內(nèi)存沒(méi)什么關(guān)系了

0x02 調(diào)swap

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

讓我眼前一亮的是這個(gè)帖子里貼出的錯(cuò)誤代碼和我的幾乎一模一樣,而且在一開(kāi)始就寫(xiě)明了上面的所謂配置方案都已經(jīng)試過(guò)了,但依然無(wú)效——和我遇到的情況完全一樣。不過(guò)他最后的結(jié)果是:

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

貌似是沒(méi)找到什么好的解決方案……

但當(dāng)我翻到最下面的時(shí)候眼前一亮——“To get around this I temporarily created a large swap drive...”?!癮 large swap”……醍醐灌頂啊……我立馬問(wèn)了下能正常clone的那個(gè)哥們的虛擬機(jī)給了多少swap空間,得到的答復(fù)是2G,而我手里的——1G和0……和0……和……0……0……0……

原來(lái)我需要的是一個(gè)大的swap!

雖然我的swap已經(jīng)是劃分好了的,但還是可以添加的,具體方法這篇帖子中也給出了鏈接: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).

復(fù)制代碼 代碼如下:

# 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.

復(fù)制代碼 代碼如下:

# chmod 600 /root/myswapfile

Make this file as a swap file using mkswap command.

復(fù)制代碼 代碼如下:

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

Enable the newly created swapfile.

復(fù)制代碼 代碼如下:

# 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.

復(fù)制代碼 代碼如下:

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

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

復(fù)制代碼 代碼如下:

# 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

復(fù)制代碼 代碼如下:

# swapoff -a
# swapon -a

說(shuō)實(shí)在的我一直不太關(guān)心swap的大小,總覺(jué)得沒(méi)啥用處。這一次就讓我長(zhǎng)記性了——swap還是必要的!

相關(guān)文章

最新評(píng)論