By Patryk


2019-02-10 10:26:49 8 Comments

I've recently noticed that even though there's a lot of memory on my system:

# free -m
             total       used       free     shared    buffers     cached
Mem:         15965       9680       6284         35       1754       2560
-/+ buffers/cache:       5365      10599
Swap:         2047        258       1789

I cannot swapoff -a with my 2G swapfile

-rw-r----- 1 root root 2.0G Feb  9 21:34 /2GB.swap

I've changed the following kernel parameters via sysctl but that should be the cause:

vm.swappiness = 5
vm.vfs_cache_pressure = 200

Any reason for:

# swapoff -a
swapoff: /2GB.swap: swapoff failed: Cannot allocate memory

? dmesg doesn't log anything when swapoff fails. I'm using linux kernel 4.19.20-041920-generic.


Another example including /proc/meminfo

# cat /proc/meminfo
MemTotal:       16348296 kB
MemFree:         6673788 kB
MemAvailable:   11233052 kB
Buffers:          525048 kB
Cached:          2837788 kB
SwapCached:       362556 kB
Active:          4728244 kB
Inactive:        2758260 kB
Active(anon):    3132940 kB
Inactive(anon):  1043676 kB
Active(file):    1595304 kB
Inactive(file):  1714584 kB
Unevictable:        2396 kB
Mlocked:            2396 kB
SwapTotal:       2097148 kB
SwapFree:        1124272 kB
Dirty:               336 kB
Writeback:             0 kB
AnonPages:       3786868 kB
Mapped:           699944 kB
Shmem:             53116 kB
Slab:            1770268 kB
SReclaimable:    1578564 kB
SUnreclaim:       191704 kB
KernelStack:       47216 kB
PageTables:        82968 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    10271296 kB
Committed_AS:   24712604 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:             3552 kB
HardwareCorrupted:     0 kB
AnonHugePages:     26624 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
CmaTotal:              0 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      714480 kB
DirectMap2M:    13891584 kB
DirectMap1G:     3145728 kB

and free -m

# free -m
             total       used       free     shared    buffers     cached
Mem:         15965       9447       6517         51        512       2771
-/+ buffers/cache:       6163       9801
Swap:         2047        950       1097

EDIT

strace swapoff -a

[email protected]:~# strace swapoff -a
execve("/sbin/swapoff", ["swapoff", "-a"], [/* 22 vars */]) = 0
...
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=9469488, ...}) = 0
mmap(NULL, 9469488, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd262737000
close(3)                                = 0
open("/proc/swaps", O_RDONLY)           = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd263a54000
read(3, "Filename\t\t\t\tType\t\tSize\tUsed\tPrio"..., 1024) = 102
readlink("/2GB.swap", 0x7ffcfbb3bea0, 4096) = -1 EINVAL (Invalid argument)
read(3, "", 1024)                       = 0
close(3)                                = 0
munmap(0x7fd263a54000, 4096)            = 0
swapoff("/2GB.swap")                    = -1 ENOMEM (Cannot allocate memory)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd263a54000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7fd263a54000, 4096)            = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/util-linux.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/usr/share/locale-langpack/en/LC_MESSAGES/util-linux.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "swapoff: ", 9swapoff: )                = 9
write(2, "/2GB.swap: swapoff failed", 25/2GB.swap: swapoff failed) = 25
write(2, ": ", 2: )                       = 2
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, "Cannot allocate memory\n", 23Cannot allocate memory
) = 23
open("/etc/fstab", O_RDONLY|O_CLOEXEC)  = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=838, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd263a54000
read(3, "# /etc/fstab: static file system"..., 4096) = 838
readlink("/2GB.swap", 0x7ffcfbb3c2b0, 4096) = -1 EINVAL (Invalid argument)
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7fd263a54000, 4096)            = 0
exit_group(-1)                          = ?
+++ exited with 255 +++

0 comments

Related Questions

Sponsored Content

1 Answered Questions

0 Answered Questions

Process killed by OOM killer when plenty of memory apparently free

  • 2015-09-24 11:19:17
  • Gareth McCaughan
  • 1136 View
  • 5 Score
  • 0 Answer
  • Tags:   memory out-of-memory

3 Answered Questions

[SOLVED] Swap memory, and when the OS starts using it

1 Answered Questions

[SOLVED] Why is swapoff so slow?

  • 2017-11-09 04:34:35
  • Tom Hale
  • 2231 View
  • 8 Score
  • 1 Answer
  • Tags:   linux swap

1 Answered Questions

System protection against low memory crashes when not using swap

  • 2017-01-08 11:13:34
  • glarry
  • 63 View
  • 1 Score
  • 1 Answer
  • Tags:   linux memory swap

2 Answered Questions

[SOLVED] Why QEMU can't use the linux memory buffers memory?

  • 2016-08-06 09:14:10
  • Marcus
  • 520 View
  • 1 Score
  • 2 Answer
  • Tags:   memory qemu

2 Answered Questions

[SOLVED] swapoff fails when overcommit_memory==2

  • 2013-09-05 09:14:48
  • Ruslan
  • 8027 View
  • 6 Score
  • 2 Answer
  • Tags:   memory swap

3 Answered Questions

[SOLVED] why we need ram if we having swap memory?

  • 2016-02-05 07:25:38
  • chandu
  • 139 View
  • -2 Score
  • 3 Answer
  • Tags:   memory swap

1 Answered Questions

[SOLVED] Why does chroot get ENOENT on an existing file?

1 Answered Questions

[SOLVED] Why is swap used when a lot of memory is still free?

Sponsored Content