In the comments, I suggested you create a cgroup, set memory.swappiness
to zero (to minimize swapping) and run your application inside of that. If you did that, your application probably wouldn't swap unless you were running so incredibly low on physical memory that swapping pages for programs in that cgroup was the only way to make enough physical memory available.
To do this on RHEL 6.5:
Ensure the libcgroup
package is installed. This gives you access to userspace tools like cgcreate
and cgexec
.
Start and enable the cgconfig
service so that changes to cgroup configuration are persistent between reboots. On RHEL this service should also mount the required filesystems underneath the /cgroup
tree.
Create the cgroup with cgcreate -g memory:thunderbird
Set swappiness to zero in this group with cgset -r memory.swappiness=0 thunderbird
Use cgsnapshot -s > /etc/cgconfig.conf
to save an updated persistent configuration for the cgconfig
service (all changes up until now have been runtime changes. You'll probably want to save the default config file somewhere and give it a once-over before making it the persistent configuration.
You can now use cgexec
to start desired applications within the thunderbird
cgroup:
[root@xxx601 ~]# cgexec -g memory:thunderbird ls
anaconda-ks.cfg a.out foreman.log index.html install.log install.log.syslog node.pp sleep sleep.c ssl-build stack test
[root@xxx601 ~]#
I don't have thunderbird
actually installed otherwise I would have done that. Not sure why the formatting of the above is messed up.
One alternative to cgexec
would be to start thunderbird and add the PID to the tasks
file for the application. For example:
[root@xxx601 ~]# cat /cgroup/memory/thunderbird/tasks
[root@xxx601 ~]# pidof httpd
25926 10227 10226 10225 10163 10162 10161 10160 10159 10157 10156 10155 10152 10109
[root@xxx601 ~]# echo 25926 > /cgroup/memory/thunderbird/tasks
[root@xxx601 ~]# cat /cgroup/memory/thunderbird/tasks
25926
Again, it's bears mentioning that this doesn't technically prevent swapping but short of modifying the application itself, it's probably your best bet. I've just now found memory.memsw.limit_in_bytes
which seems like it might be a more direct control on forcing there to be no swapping but I haven't played around with it enough to really feel comfortable saying that it fixes your problem completely. That said, it might be something to look into after this.
The real answer would be to have the application mlock
sensitive information to get around this sort of concern. I'm willing to bet an application like Thunderbird, though, does do that but I don't know enough about the internals to comment on that.
cgexec
thunderbird into it. You still need root access, but that's the admin-level resolution. If you're developing your own application you would use mlock. – Bratchley Feb 13 '15 at 14:06mlock
, you should check. – Steve Wills Feb 13 '15 at 14:11memory.swappiness=0
may not be a perfect solution but it may resolve the issue at a practical level. – Bratchley Feb 13 '15 at 18:55