我在一台内存较少的服务器上使用 gitosis,具体来说大约 512 MB。当我尝试推送一个大文件夹(恰好是来自 Android 手机的备份)时,我得到:
me@corellia:~/Configs/$ git push origin master
Counting objects: 18, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (14/14), done.
fatal: Out of memory, malloc failed MiB | 685 KiB/s
error: pack-objects died of signal 13
error: failed to push some refs to 'git@dagobah:Configs'
我一直在网上搜索,并特别发现了:http://www.mail-archive.com/[电子邮件保护]/msg01747.html也http://git.661346.n2.nabble.com/Out-of-memory-error-during-git-push-td5443705.html但这些似乎对我没有帮助,原因有二:1) 当我推送时,我实际上并没有内存不足。当我在推送过程中运行“top”时,我得到:
24262 git 18 0 16204 6084 1096 S 2 1.2 0:00.12 git-unpack-obje
另外,如果我在推送过程中运行 /head/meminfo,我会得到:
MemTotal: 524288 kB
MemFree: 289408 kB
Buffers: 0 kB
Cached: 0 kB
SwapCached: 0 kB
Active: 0 kB
Inactive: 0 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 524288 kB
因此,看起来我有足够的可用内存,但实际上它仍然失败了,而且我并不是一名 git 专家,无法弄清楚发生了什么。如果有人能在这里帮我一下,告诉我是什么原因导致了这个问题,以及我可以做些什么来解决它,我将不胜感激。
谢谢!
编辑:
运行命令的输出ulimit -a
:
scottj@dagobah:~$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 204800
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 204800
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
编辑:
git 对象和大小如下:
313796 .git/objects/88/7ce48679f885af4c466d4ddccef9a9954a9de6
224276 .git/objects/18/261f6a52926a756c7ecb453e025d1f25937026
6248 .git/objects/63/a0b4e622c893d3dcc162052b43301030d0c86d
5608 .git/objects/a2/0c65987656cba591171549752eb97f0207fec8
2608 .git/objects/pack/pack-3be8300f69b67fa8fa687df84bbd9b8c96e86c8e.pack
28 .git/objects/pack/pack-3be8300f69b67fa8fa687df84bbd9b8c96e86c8e.idx
24 .git/objects/c9/8909563ec60369d69ac2d317af25a44c9fc198
24 .git/objects/5d/1f74bd9bc4c575a7eeec08d59916d9829068d1
24 .git/objects/53/edad79cb051f5e7864d9d3339fa59990ccfe2d
8 .git/objects/80/dd50c7a314950e5a1f56c0210b0a91f48ee792
答案1
虽然有点牵强,但可以尝试一下
git -c core.packedGitWindowSize=32m -c core.packedGitLimit=256m push origin master
这会覆盖几个限制从文件映射的字节数的参数。这些是用于 32 位系统的默认值,64 位默认值要大得多。我猜你使用的是 64 位系统,这导致 git 使用非常大的默认值,但存在触发错误的资源限制(可能是在 VM 中运行)。
答案2
您使用的是哪种平台/发行版?Ubuntu、redhat、centos 等... 客户端和服务器都用过吗?您推送的客户端的内存使用量是多少?我以前推送包含大量修订版本时也遇到过这种情况。我知道一种解决方法是尽可能逐步将更改推送到服务器。另一种解决方案是增加内核内存使用量。在某些内核发行版中,有一些设置会阻止内核为单个进程分配最大内存:
Set Kernel Parameters
Modify the "/etc/sysctl.conf" file to include the lines appropriate to your operating system.
# Red Hat Enterprise Linux 3.0 and CentOS 3.x
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.shmmin = 1
kernel.shmseg = 10
# semaphores:
semmsl, semmns, semopm, semmni kernel.sem = 250 32000 100 128
fs.file-max = 65536
# Red Hat Enterprise Linux 4.0 and CentOS 4.x
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.shmall = 2097152
如果您的 git 进程超出限制,则尽管系统报告的可用内存最大,内核仍将终止该进程。
注意:请谨慎使用这些设置。您可能不想使用该示例中的设置,因为我从我们环境中的服务器中提取了它们。
还有几点需要提及:
To Update and test kernel settings with sysctl, use following commands:
List current settings: sysctl -A|grep shm
sysctl -w kernel.shmmax=<value> to write in sysctl.conf
sysctl -p /etc/sysctl.conf to read/reload the values from sysctl.conf
Disable secure linux by editing the "/etc/selinux/config" file, making sure the SELINUX flag is set as follows.
SELINUX=disabled