Hot answers tagged

116

Identify configured swap devices and files with cat /proc/swaps. Turn off all swap devices and files with swapoff -a. Remove any matching reference found in /etc/fstab. Optional: Destroy any swap devices or files found in step 1 to prevent their reuse. Due to your concerns about leaking sensitive information, you may wish to consider performing some sort of ...


68

This is not a problem and is likely normal. Lots of code (and possibly data) is used very rarely so the system will swap it out to free up memory. Swapping is mostly only a problem if memory is being swapped in and out continuously. It is that kind of activity that kills performance and suggests a problem elsewhere on the system. If you want to monitor ...


48

The idea of kubernetes is to tightly pack instances to as close to 100% utilized as possible. All deployments should be pinned with CPU/memory limits. So if the scheduler sends a pod to a machine it should never use swap at all. You don't want to swap since it'll slow things down. Its mainly for performance.


39

This appears to be problem in combination of two factors: Using a virtual machine. A possible kernel bug. This is partly one of the lines which describes why this happens: Mar 7 02:43:11 myhost kernel: memcheck-amd64- invoked oom-killer: gfp_mask=0x24002c2, order=0, oom_score_adj=0 The other line is this: Mar 7 02:43:11 myhost kernel: 0 pages HighMem/...


33

To answer your headline question, use oom_score_adj(kernel >=2.6.36) or for earlier kernels (>=2.6.11) oom_adj, see man proc /proc/[pid]/oom_score_adj (since Linux 2.6.36) This file can be used to adjust the badness heuristic used to select which process gets killed in out-of-memory conditions... /proc/[pid]/oom_adj (since Linux 2.6.11) This ...


32

TL;DR not properly using swap is just a lazy hack that demonstrates a poor understanding of the memory subsystems and a lack of fundamental systems administration skills. Designing infrastructure services and not understanding these systems is bound to end in failure. So, I've got some commentary on this, this seems more like laziness to me rather than a ...


25

Linux will pre-emptively write out pages to disk if it has nothing better to do. That does not mean that it will evict those pages from memory, though. It's just that in case it must evict those pages sometime in the future, it doesn't need to wait for them to be written to disk, because they are already there. After all, the reason you are running out of ...


24

The reason for this, as I understand it, is that the kubelet isn't designed to handle swap situations and the Kubernetes team aren't planning to implement this as the goal is that pods should fit within the memory of the host. from this GitHub issue #53533 Support for swap is non-trivial. Guaranteed pods should never require swap. Burstable pods should have ...


23

There is no problem. Even if there is still available RAM, the Linux Kernel will move memory pages which are hardly ever used into swap space. It’s good to swap out memory pages that have been inactive for a while, keeping often-used data in cache; this is the desired situation of the Kernel. You can have more control on this by using vfs_cache_pressure (...


20

It is doing this because Ubuntu is trying to switch to a high resolution video mode for the console and your hardware isn't cooperating. Fixing this while at the machine When Grub2 shows up: Highlight the menu item for Ubuntu and press 'e' Go to the line where it loads the kernel and press 'End' to go to the end of the line Add 'nomodeset' Press F10 or ...


15

It used to be that only swap partitions in /etc/fstab were used automatically, however, systemd may be changing that slightly. You might need to do: systemctl mask dev-sdXX.swap (change sdXX) to your real formatted swap partition, which, begs the question of why you have a swap partition if you don't want it used... If you are not using systemd, then, ...


13

It seems a relatively common problem When the problem is happening, can you check if issuing the following command stops it: echo 1 > /proc/sys/vm/drop_caches If it works, you can schedule it as a periodic cron job as a workaround.


13

Swap space from a swap partition does not use any inodes, as swap partitions don't contain a real file-system. If you use Swap File(s) rather than a swap partition, your systems only uses as many inodes as you have swap files. See for instance this Q&A to find which part of your file system has (too) many inodes to investigate the cause. (Runaway ...


12

Is there any reason to NOT have a swap file on CentOS Yes: You have some type of horizontal scaling in place which increases your number of servers based on their memory usage, thus eliminating the possibility of swap being used. You have a specific performance requirement that means you cannot allow your program to use swap for processing as it is ...


12

If you are really sure you want to disable swapping (note: this is not recommended, even where you are pretty sure that physical RAM is more than enough), follow these steps: run swapoff -a: this will immediately disable swap remove any swap entry from /etc/fstab reboot the system. If the swap is gone, good. If, for some reason, it is still here, you had to ...


12

Several thoughts (from my comments above), and links to interresting reads about your situation: I recommend that you check that 1) you can adress more than 3Gb with your current kernel & config (& cpu) [because if 3Gb is a limit for your system & os, you are exceeding it] . 2) that you allow swapping and the swapping subsystem is in place and ...


11

Swap used is not bad, but a lot of swap activity is vmstat 1 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 6 0 521040 114564 6688 377308 8 13 639 173 0 1100 5 4 90 0 1 0 521040 114964 6688 377448 0 0 256 0 ...


11

In regard to the second field, for swap partitions, the Linux man page for fstab states: For swap partitions, this field should be specified as `none'. It has stated the same thing since at least 27 November 1993, the earliest man page I could find. In practice it doesn't matter; if the filesystem type is swap, the system ignores the mountpoint field. I ...


10

If you're on Ubuntu 15.10 or greater, this may actually be the result of a bug, especially if your system is a virtual machine lacking a swap partition (e.g., AWS EC2). The problem exists on other distributions, but, as of writing, it's unclear if the same fix works universally. A temporary workaround: sudo ln -s /dev/null /etc/udev/rules.d/40-vm-hotadd....


10

While it is true that kernel uses swap even if there may be memory left, using more than two thirds of it may be an indicator that historically the server may have been running out of memory and that is why it started swapping. I would correlate swap usage with memory usage in the sar reports to deduce whether the system has enough ram. I would also check ...


10

I'm not quite clear what you're asking. tmpfs is an in-memory filesystem but you apparently don't want the contents of /tmp to actually reside in memory, is that right? Then you simply don't use tmpfs and instead use an ordinary on-disk /tmp directory or dedicated partition with a normal file-system.


9

Fedora 18 and up have smem in the repos. You could download the python script and install from source. Here's a sample output (somewhat snipped and anonymized) from my machine: # smem -s swap -t -k -n PID User Command Swap USS PSS RSS 20917 1001 bash 0 1.1M 1.1M 1....


9

I agree with comment about more RAM. Answering your question: you can create either additional swap partition (if you have extra space on a hard drive) or create swap file. dd if=/dev/zero of=/path/to/swap_file bs=1024 count=${size_of_additional_swap} mkswap /path/to/swap_file swapon /path/to/swap_file The more swap in use the more load on your hard disk ...


9

Since nobody else had an answer here, thought I'd share the only thing that has worked for us. First, these ideas did not work: larger cache instance type: was having the same problem on smaller instances than the cache.r3.2xlarge we're using now tweaking maxmemory-policy: neither volatile-lru nor allkeys-lru seemed to make any difference bumping up ...


8

This is what I use on debian-based systems. It's an improved version of Dan's answer. It gets the available memory from a grain, multiplies it by 2, to create the swapfile with the appropriate size. It also makes an entry in /etc/fstab, if non-existent. coreutils: pkg.installed /swapfile: cmd.run: - name: | [ -f /swapfile ] || dd if=/dev/...


8

No. Things that are swapped out are, by definition, not in memory and not eligible to be executed.


8

The Linux Kernel starts to swap out memory pages even if you have plenty of ram free. You can fine tune this behaviour by setting a custom swappiness. http://en.wikipedia.org/wiki/Swappiness For servers, I'd recommend to set the swappiness to 1 if you have always enough memory for your workload. For workstations, I'd recommend using the default of 60. # ...


8

No problem to have swap file on this disk but make sure to use the Linux agent to create it. It will automatically create and manage it in the resource disk. Here's how to enable: Edit the "/etc/waagent.conf" Add or uncomment these lines: ResourceDisk.Format=y ResourceDisk.Filesystem=ext4 ResourceDisk.MountPoint=/mnt/resource ResourceDisk.EnableSwap=y ...


8

Disabling swap is a good idea if your software can deal with out-of-memory conditions gracefully or limits itself to avoid OOM situations having consistent performance is critical (when your system is swapping latency will increase which can be bad enough to make it effectively useless for many applications) This sort of thing often happens with ...


8

This is not an answer for your question; but rather, just extra information to help you make an informed decision. If you would like to know what processes specifically are using how much swap, here is a little shell script: #!/bin/bash set -o posix set -u OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"` ; do PID=`echo $DIR ...


Only top voted, non community-wiki answers of a minimum length are eligible