I am running Gentoo Linux with kernel 4.4.8-hardened-r1, QEMU-KVM version 2.5.1 and 3227 MB of system-visible RAM (without considering RAM taken by BIOS and my AMD APU's graphics). I have a VM that uses 2.8 GB of memory, which for performance reasons must run with hugepages, and after using my system for other tasks for a while I have to restart my system because the system cannot allocate enough hugepages for my VM. A cursory online reading about Linux memory management says this happens when my memory allocation is fragmented and the system cannot find at least 2.8 contiguous GB of free memory for all these hugepages, and that Linux's memory management is 99% of the time perfectly fine for normal processes but it seems like I've just hit the 1% edge case where Linux's memory management falls short.

Is it possible to "defragment" my memory in order to be able to take all that memory without having to reboot the whole system?

  • There is no such thing as defragmenting memory. Disable hugepages if you only have 4 GB of RAM? – Satō Katsura Jul 18 '16 at 7:58
  • I must use them. I use my VM for gaming and LOL's launcher/client runs notoriously slow without hugepages. I enabled hugepages after I once almost accidentally dodged a ranked on promotion series because the launcher lagged during champion selection. – RAKK Jul 18 '16 at 8:50
  • The answer to your question is to disable hugepages. If you don't want to do that for other reasons, your other option is to buy more RAM. – Satō Katsura Jul 18 '16 at 9:00
  • @SatōKatsura That's not true, there is /proc/sys/vm/compact_memory however I'm finding it quite opaque. See unix.stackexchange.com/questions/450890/… – Max Ehrlich Jun 27 '18 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.