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還是必要的!
- git?push時卡住的解決方法(長時間不報錯也不自動退出)
- git本地分支和stash內容報錯消失的問題
- 關于提交項目到gitee報錯Push to origin/master was rejected的問題
- 有關pycharm登錄github時有的時候會報錯connection reset的問題
- Git發(fā)現git push origin master 報錯的解決方法
- git pull時沖突的幾種解決方式(小結)
- idea+git合并分支解決沖突及詳解步驟
- git在idea中的沖突解決方法(非常重要)
- git 報錯:OpenSSL SSL_read: Connection was reset, errno 10054 解決方法
相關文章
iis7 iis8反向代理規(guī)則編寫、安裝與配置方法
這篇文章主要介紹了iis7 iis8反向代理規(guī)則編寫、安裝與配置方法,需要的朋友可以參考下2020-04-04詳解如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件
這篇文章主要介紹了詳解如何在IntelliJ IDEA中使用.ignore插件忽略不必要提交的文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11Git客戶端TortoiseGit(Windows系統(tǒng))的使用方法
這篇文章主要介紹了Git客戶端TortoiseGit(Windows系統(tǒng))的使用方法,需要的朋友可以參考下2014-09-09FileZilla Server搭建FTP服務器配置及425錯誤與TLS警告解決方法詳解
本文詳細講解了FileZilla Server搭建FTP服務器配置以及425 Can't open data,You appear to be behind a NAT router,FTP over TLS is not enabled等相關問題的解決方法2018-10-10