7

I have a weird problem with turning off the swap. The server has 192 GB of memory, 154 GB free.

It's a Hypervisor running a number of Linux KVM Virtual Machines.

When trying to:

# swapoff -a
swapoff: /dev/sda2: swapoff failed: Cannot allocate memory

but memory is free:

# cat /proc/meminfo
MemTotal:       197805748 kB
MemFree:        162274264 kB
MemAvailable:   162388912 kB
Buffers:             432 kB
Cached:           353524 kB
SwapCached:       221828 kB
Active:         28253440 kB
Inactive:        5349056 kB
Active(anon):   28159204 kB
Inactive(anon):  5289320 kB
Active(file):      94236 kB
Inactive(file):    59736 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:      124999676 kB
SwapFree:       124534724 kB
Dirty:               796 kB
Writeback:             0 kB
AnonPages:      33063024 kB
Mapped:            59236 kB
Shmem:            199984 kB
Slab:             313264 kB
SReclaimable:     206596 kB
SUnreclaim:       106668 kB
KernelStack:       10784 kB
PageTables:        94012 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    223902548 kB
Committed_AS:   43094824 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      794656 kB
VmallocChunk:   34358685284 kB
HardwareCorrupted:     0 kB
AnonHugePages:  32186368 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      136564 kB
DirectMap2M:     8136704 kB
DirectMap1G:    195035136 kB

Does anyone has any idea what could be the cause ?

5
  • would you be able to umount it after dropping caches, e.g. echo 1 > /proc/sys/vm/drop_caches? Nov 7, 2016 at 16:58
  • 1
    @RuiFRibeiro Tried 3, 2 and 1, neither helped removing the swap file unfortunately.
    – Dom
    Nov 7, 2016 at 17:06
  • 1
    Is there any clue in the kernel logs? Nov 7, 2016 at 22:41
  • @Gilles nothing unfortunately, it does not even attempt to perform the operation.
    – Dom
    Nov 8, 2016 at 9:23
  • fwiw, on FreeBSD the message is swapoff: <device path>: Cannot allocate memory
    – myrdd
    Sep 3, 2018 at 9:32

2 Answers 2

2

Try it:

sync ; echo 3 > /proc/sys/vm/drop_caches

and then

swapoff

Or temporary add new swap file

0

me pasó igual y así es como lo resolví.

LIBERAR SWAP CUANDO NO SE DEJA DESACTIVAR.

Crear un archivo Swap Temporalmente

dd if=/dev/zero of=/home/swap bs=1024 count=512000

Convertir el archivo en Swap|

mkswap /home/swap

Activar el archivo Swap temporal

swapon /home/swap

Deshactivar la Swap del problema

swapoff /dev/dm-1

Activar nuevamente la Swap del problema

swapon /dev/dm-1

Desactivar archivo de Swap Temporal Creada

swapoff /home/swap

Remover archivo de Swap

rm -f /home/swap

Fuente: https://leizhilong.github.io/post/case-study-swapoff-cannot-allocate-memory/

2
  • Bienvenido a U&L SE. Lo siento, este sitio es anglofono. Por favor, traducir la respuesta al ingles.
    – AdminBee
    Nov 26, 2021 at 12:41
  • John this just creates another place for swap. The person asking the question is (quite reasonably) asking why they need swap at all if they've so much spare memory
    – roaima
    Nov 26, 2021 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .