Git USES pit Out of memory wrong solution

  • 2020-05-14 05:43:36
  • OfStack

The company recently moved the code for internal use from svn to git, so you must also learn to use the Git command.


Although the model of git is quite different from that of svn, it should not be difficult. But I didn't want to step into a big hole in step 1 of git clone... Without further ado, let's look at the error code:


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)

Just a few lines of the error code, and I was stuck for a day...

0 x00 memory

When you see "Out of memory, malloc failed", the first reaction is out of memory. After all, the virtual machine memory is too small, Debian virtual machine only gave 512M memory, plus they have nothing to play with, own installed a pile of mess 78 bad program, free only a few 10 megabytes.


So decisively put a mess 78 bad process over, the service stopped, useless things all off. Finally, the virtual machine memory to 1G.

The result -- fatal still...

0 x01 configuration

Then I read this -- "allocate 1941159936 bytes" -- this is 1.8G ah... How much memory is there for him... Adjusting memory is obviously not the way. So the Internet search 1 under the error report, found that the configuration is to adjust:


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

Make fun of 1 sentence by the way -- domestic blogs are all copying this configuration... I also copied Cache into Chase... Can't copy...


In this way, it should be able to reduce the occupation of resources, but unfortunately, it seems that git did not pick up this problem at all, but still applied for 1.8 G space without hesitation...

Of course, the result -- once again, fatal is still...


In addition, I also found another friend to do an experiment, and his virtual machine can be normal clone (1G memory, free less than 100M), but neither of my two virtual machines can be normal clone (1G memory, free more than 800M and 2G memory, free nearly 1.3G). Doesn't seem to have anything to do with memory

0 x02 swap

Finally saw this article: http: / / stackoverflow com/questions / 14038074 / git - pull - fatal - out - of - memory malloc -- failed

What really stood out to me was that the error code in this post was almost exactly the same as mine, and that it stated at the beginning of 1 that the above so-called configuration scheme had been tried and still didn't work -- exactly the same as in my case. But what he ended up with was:

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

There seems to be no good solution...

But when I get to the bottom of the page, I see a bright light -- "To get around this I temporarily a large swap drive..." . "a large swap"... I was inspired... I immediately asked how much space swap had been given to the virtual machine of the guy who was working on clone. I got 2G, and I got -- 1G and 0... And zero... And... 0... 0... 0...

What I need is a big swap!

Although my swap was divided into good, but it can be added, the specific methods in this post also links are given: http: / / www thegeekstuff. com / 2010/08 / how to - add - swap - space /

Use Method2, perfect solution.

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 command creates swap name myswapfile swap with under


# 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 will say if file if the is from 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

To be honest, I don't really care about the size of swap. This once let me long memory - swap is still necessary!


Related articles: