fatal error: runtime: out of memory
runtime stack:
runtime.throw(0x70b4a5, 0x16)
/usr/local/go/src/runtime/panic.go:774 +0x72 fp=0x7ffe9d546078 sp=0x7ffe9d546048 pc=0x42ec12
runtime.sysMap(0xc000000000, 0x4000000, 0x95d6d8)
/usr/local/go/src/runtime/mem_linux.go:169 +0xc5 fp=0x7ffe9d5460b8 sp=0x7ffe9d546078 pc=0x419375
runtime.(*mheap).sysAlloc(0x9452c0, 0x2000, 0x0, 0x0)
/usr/local/go/src/runtime/malloc.go:701 +0x1cd fp=0x7ffe9d546160 sp=0x7ffe9d5460b8 pc=0x40c68d
runtime.(*mheap).grow(0x9452c0, 0x1, 0xffffffff)
/usr/local/go/src/runtime/mheap.go:1255 +0xa3 fp=0x7ffe9d5461b0 sp=0x7ffe9d546160 pc=0x4272b3
runtime.(*mheap).allocSpanLocked(0x9452c0, 0x1, 0x95d6e8, 0x1)
/usr/local/go/src/runtime/mheap.go:1170 +0x266 fp=0x7ffe9d546230 sp=0x7ffe9d5461b0 pc=0x427146
runtime.(*mheap).alloc_m(0x9452c0, 0x1, 0x45002a, 0x0)
/usr/local/go/src/runtime/mheap.go:1022 +0xc2 fp=0x7ffe9d546280 sp=0x7ffe9d546230 pc=0x4269e2
runtime.(*mheap).alloc.func1()
/usr/local/go/src/runtime/mheap.go:1093 +0x4c fp=0x7ffe9d5462b8 sp=0x7ffe9d546280 pc=0x456bdc
runtime.(*mheap).alloc(0x9452c0, 0x1, 0x1002a, 0x40000)
/usr/local/go/src/runtime/mheap.go:1092 +0x8a fp=0x7ffe9d546308 sp=0x7ffe9d5462b8 pc=0x426cca
runtime.(*mcentral).grow(0x9460f8, 0x0)
/usr/local/go/src/runtime/mcentral.go:255 +0x7b fp=0x7ffe9d546348 sp=0x7ffe9d546308 pc=0x418d9b
runtime.(*mcentral).cacheSpan(0x9460f8, 0x7f31f72fd000)
/usr/local/go/src/runtime/mcentral.go:106 +0x2fe fp=0x7ffe9d5463a8 sp=0x7ffe9d546348 pc=0x4188be
runtime.(*mcache).refill(0x7f31f72fd008, 0x2a)
/usr/local/go/src/runtime/mcache.go:138 +0x85 fp=0x7ffe9d5463c8 sp=0x7ffe9d5463a8 pc=0x418365
runtime.(*mcache).nextFree(0x7f31f72fd008, 0x95d72a, 0x7f31f72fd008, 0x8, 0xfffffffffffffff8)
/usr/local/go/src/runtime/malloc.go:854 +0x87 fp=0x7ffe9d546400 sp=0x7ffe9d5463c8 pc=0x40ceb7
runtime.mallocgc(0x180, 0x704580, 0x1, 0x95d740)
/usr/local/go/src/runtime/malloc.go:1022 +0x793 fp=0x7ffe9d5464a0 sp=0x7ffe9d546400 pc=0x40d7f3
runtime.newobject(0x704580, 0x4000)
/usr/local/go/src/runtime/malloc.go:1151 +0x38 fp=0x7ffe9d5464d0 sp=0x7ffe9d5464a0 pc=0x40dbe8
runtime.malg(0xf75a700008000, 0x947968)
/usr/local/go/src/runtime/proc.go:3232 +0x31 fp=0x7ffe9d546510 sp=0x7ffe9d5464d0 pc=0x437d71
runtime.mpreinit(...)
/usr/local/go/src/runtime/os_linux.go:324
runtime.mcommoninit(0x93fd80)
/usr/local/go/src/runtime/proc.go:626 +0xc2 fp=0x7ffe9d546548 sp=0x7ffe9d546510 pc=0x4319d2
runtime.schedinit()
/usr/local/go/src/runtime/proc.go:543 +0x72 fp=0x7ffe9d5465a0 sp=0x7ffe9d546548 pc=0x431632
runtime.rt0_go(0x7ffe9d5465d8, 0x5, 0x7ffe9d5465d8, 0x0, 0x7f31f7125c6a, 0x5, 0x7ffe9d548631, 0x7ffe9d548643, 0x7ffe9d548652, 0x7ffe9d54866d, ...)
/usr/local/go/src/runtime/asm_amd64.s:214 +0x125 fp=0x7ffe9d5465a8 sp=0x7ffe9d5465a0 pc=0x458b05
```
用 top命令行一看,KiB Swap为0,free为0
用 free -m 一看,交换分区也为0
mkdir /swap
cd /swap
sudo dd if=/dev/zero of=swapfile bs=1024 count=2000000
sudo mkswap -f swapfile
.激活 Swap 文件
sudo swapon swapfile
如果需要卸载这个 swap 文件,可以进入建立的 swap 文件目录。执行下列命令。
sudo swapoff swapfile
箬需要一直保持这个 swap ,可以把它写入 /etc/fstab 文件。
/swap/swapfile /swap swap defaults 0 0