This is what I've tried:

sudo zsh -c 'echo offline >/sys/devices/system/memory/memory109/state'`

and got the following error:

zsh:echo:1: write error: device or resource busy

Do I perhaps need to make sure that the memory module that I am about to take offline is empty first?

And if so, how could I do that?


I'm running an Ubuntu based distro virtualized as a guest by VMWare.

I'm hoping to reduce the memory usage of the guest system, freeing up more to be available to the host without having to restart the guest.

In case any of that may matter.

Edit 2016-09-29:

Encouraged by @Gilles' comments and link saying that in theory it should be possible, I got the idea that maybe memory109 contained some unmovable pages. So I decided to try it on some other modules(?) too.

At first I tried a few others by hand. But since those were unsuccessful, I thought I would try all of them:

for i in /sys/devices/system/memory/memory*/state;
  do echo -n "Trying "$i" \t";
  sudo zsh -c "echo offline > $i";

Caution: Be careful with the above script as it may succeed on your machine which could offline most if not all of your memory leaving your system starved and hanging.

This is what I got for most:

Trying /sys/devices/system/memory/memory44/state        zsh:echo:1: write error: device or resource busy
Trying /sys/devices/system/memory/memory45/state        zsh:echo:1: write error: device or resource busy
Trying /sys/devices/system/memory/memory46/state        zsh:echo:1: write error: device or resource busy

With only two exceptions:

Trying /sys/devices/system/memory/memory0/state         zsh:echo:1: write error: invalid argument
Trying /sys/devices/system/memory/memory86/state        zsh:echo:1: write error: invalid argument

Any ideas why this may not work?

  • 1
    According to §6.2 “How to offline memory”, if I understand correctly, you can offline a memory block provided that it doesn't contain any unmovable memory (i.e. some kinds of kernel memory). I don't think there's a way to generically ensure that a memory zone can be offlined, but I have no experience of this. – Gilles Sep 26 '16 at 23:06

I don't think it's possible by kernel's default features. Kernel only supports hot-plug, but unplug. There could be a weirdo way to do this, but technically it sounds bad... there are few problems with this at least.

  • 1
    I don't know if it's possible with the build options used by Ubuntu's default kernel, but it certainly is possible with a mainline kernel, no patches needed. It has been for about a decade. – Gilles Sep 26 '16 at 23:01
  • Yup, I know. But he is running Ubuntu. And I said default. So he need to compile kernel for himself. – NapoleonTheCake Sep 27 '16 at 4:57
  • Just did this yesterday with creating config so there was this option. Anyway it is bad in my mind and without right knowledge you will cause kernel panic. – NapoleonTheCake Sep 27 '16 at 5:11
  • I don't think you can cause a kernel panic this way. You could cause the system to run out of memory (having ample swap will reduce that risk) but that only triggers the OOM killer, not a kernel panic. – Gilles Sep 27 '16 at 9:22
  • 4
    I've checked, Ubuntu's default kernel configuration does include all the settings needed for memory unplugging. So it absolutely is possible using the kernel's default features on Ubuntu. There's nothing “weirdo” about this. Why do you claim that “there are few problems with this”? Why do you claim that there is a risk of kernel panic? – Gilles Sep 29 '16 at 10:13

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.