Hot answers tagged

135

Since kernel 2.6.28, Linux uses a Split Least Recently Used (LRU) page replacement strategy. Pages with a filesystem source, such as program text or shared libraries belong to the file cache. Pages without filesystem backing are called anonymous pages, and consist of runtime data such as the stack space reserved for applications etc. Typically pages ...


110

The problem with fallocate(1) is that it uses filesystem ioctls to make the allocation fast and effective, the disadvantage is that it does not physically allocate the space but swapon(2) syscall requires a real space. Reference : https://bugzilla.redhat.com/show_bug.cgi?id=1129205 I'd faced this issue earlier with my box too. So instead of using fallocate, ...


100

Yes. You should most definitely always have swap enabled, except if there is a very compelling, forbidding reason (like, no disk at all, or only network disk present). Should you have a swap on the order of the often recommended ridiculous sizes (such as, twice the amount of RAM)? Well, no. The reason is that swap is not only useful when your applications ...


86

If you worry about write cycles, you won't get anywhere. You will have data on your SSD that changes frequently; your home, your configs, your browser caches, maybe even databases (if you use any). They all should be on SSD: why else would you have one, if not to gain speed for the things you do frequently? The number of writes may be limited, but a modern ...


61

Hibernation (or suspend to disk). Real hibernation powers off the system completely, so contents of RAM are lost, and you have to save the state to some persistent storage. AKA Swap. Unlike Windows with hiberfil.sys and pagefile.sys, Linux uses swap space for both over-committed memory and hibernation. On the other hand, hibernation seems a bit finicky to ...


57

First, let's look at what you can expect from your hard drive. Your hard drive can do 200 MB/s sequentially. When you factor seek times in, it can be much slower. To pick an arbitrary example, take a look at the specs for one of Seagate's modern 3TB disks, the ST3000DM001: Max sustained data rate: 210 MB/s Seek average read: <8.5 ms Bytes per sector: ...


50

I'm going to disagree with a few of the opinions that I see stated here. I'd still be creating a SWAP partition especially in a production environment. I do it for my home machines and VMs as well. These days I'm sizing them around 1-1.5 times memory. 2 times memory used to be the rule of thumb. The swap disk is "cheap" in that it does not need to be ...


49

Execute as root: # swapoff -a And to make that change permanent, edit /etc/fstab and remove or comment-out the swap entry.


48

There are oh so many reasons to have multiple swap areas (they don't need to be files), even if you only have a single spindle. 20-20 hindsight: You deployed a machine with a single swap area, then eventually realised it's not enough. You can't redeploy the machine at will, but you can make another swap area (probably a file) until redoing the partition ...


44

If you have GParted open, close it. Its Swapoff feature does not appear to to be permanent. Open terminal and become root (su); if you have sudo enabled, you may also do for example sudo -i; see man sudo for all options): sudo -i Turn off the particular swap partition and / or all of the swaps: swapoff --all Make 100% sure the particular swap partition ...


41

What might be happening if a process is "killed due to low RAM"? It's sometimes said that linux by default never denies requests for more memory from application code -- e.g. malloc().1 This is not in fact true; the default uses a heuristic whereby Obvious overcommits of address space are refused. Used for a typical system. It ...


36

I've been experiencing the same problem with my laptop which has a SSD so seeks times shouldn't be a problem. I found an alternative explanation. Here is an excerpt The way it works now, swapoff looks at each swapped out memory page in the swap partition, and tries to find all the programs that use it. If it can’t find them right away, it will look ...


36

Of course the primary goal is not to have the need to use swap in the first place... The main thing is to create the swap LVM volume when the system is still quite fresh, the same as when you create a swap file, as swap space performs best when it is contiguous, or enforce that with lvcreate -C option. You don't want to actual disk blocks that make up the ...


31

Swap limit support allows you to limit the swap the container uses, see https://docs.docker.com/engine/admin/resource_constraints According to https://docs.docker.com/engine/installation/linux/linux-postinstall/#your-kernel-does-not-support-cgroup-swap-limit-capabilities : You can enable these capabilities on Ubuntu or Debian by following these ...


30

Ok, so the goal is to get as much bang for the buck as possible - Speed vs. the price of replacement hardware (assuming a single large harddisk and medium-size SSD, which seems to be the norm). To simplify you can to weigh how much you notice the speed increase from moving a file to the SSD against the number of sectors written to move that file to the SSD. ...


28

Don't confuse (the) swap (as a disk area) and (to) swap (as a method to move memory pages from RAM to disk and reciprocally). Excessive swapping is something to be avoided for performance reasons but having a swap area isn't necessarily a problem. On systems, like Linux, that overcommit memory, i.e. that allow processes to allocate more memory than ...


27

Since kernel version 2.6.28, Linux uses a Split Least Recently Used (LRU) page replacement strategy. Pages with a filesystem source, such as program text or shared libraries belong to the file cache. Pages without filesystem backing are called anonymous pages, and consist of runtime data such as the stack space reserved for applications etc. Typically pages ...


26

What this is telling you is that you have 16GB of virtual memory. Virtual memory is the total of physical RAM and swap space added up. It's a way of letting your system run more programs than it physically has the space for. How much swap should be allocated to a machine is a complicated and opinionated question; ask 2 people and get 3 answers :-) Your ...


25

Everything is well explained in the Wikipedia page you gave. # Set the swappiness value as root echo 10 > /proc/sys/vm/swappiness # Alternatively, run this as a non-root user # This does the same as the previous command sudo sysctl -w vm.swappiness=10 # Verify the change cat /proc/sys/vm/swappiness 10 At this point, the system will manage the swap ...


25

One fix is to make sure the memory cgroup controller is enabled (I think it is by default in even half-recent kernels, otherwise you'll need to add cgroup_enable=memory to the kernel command line). Then you can run your I/O intensive task in a cgroup with a memory limit, which also limits the amount of cache it can consume. If you're using systemd, you can ...


24

Statically configured swap space (the type that pretty much every distribution uses) is configured in /etc/fstab just like filesystems are. A typical entry looks something like: UUID=21618415-7989-46aa-8e49-881efa488132 none swap sw 0 0 You may also see either discard or nofail specified in the flags field (the fourth field). Every such ...


23

Yup, the swapoff mechanism is horrendously inefficient. The workaround is easy: iterate over processes, instead iterating over the swapped pages. Use this python script (I am not affiliated): git clone https://github.com/wiedemannc/deswappify-auto Note that the daemon mode of operation is only for desktops/laptops that are often hibernated. I wouldn't run ...


23

Maybe: I've given a lot of thought to this topic and seen opinions landing on both sides of the argument more times than I can count. My approach was to develop a way to find out. Start with an active swap partition of what you think is a sufficient size. Then, open a terminal in a workspace and issue the command free -hs 1 which will report usage once ...


22

I also struggled with that issue. I just want my system to stay responsive, no matter what, and I prefer losing processes to waiting a few minutes. There seems to be no way to achieve this using the kernel oom killer. However, in the user space, we can do whatever we want. So i wrote the Early OOM Daemon ( https://github.com/rfjakob/earlyoom ) that will ...


21

let's say Fedora and Ubuntu? … both of which are nowadays systemd operating systems. What happens in systemd operating systems the native mechanism Systemd employs various kinds of units. .mount unit files instruct it to mount volumes. .swap unit files instruct it to tell the kernel about swap partitions. (.service unit files instruct it how to ...


19

From this Ask Ubuntu question: You can also clear your swap by running swapoff -a and then swapon -a as root instead of rebooting to achieve the same effect. Thus: $ free -tm ... Swap: 6439 196 6243 ... $ sudo swapoff -a $ sudo swapon -a $ free -tm ... Swap: 6439 0 6439 ... As noted in a comment, if you don't ...


19

Comment/remove the relevant entry in the /etc/fstab to prevent it from being reenabled on the next boot, then reboot or run swapoff -a to disable the usage of the swap partition for the currently running system. Now delete the swap partition, extend your system partition over that unused space and extend the actual filesystem. I don't know whether your ...


19

Follow these steps, it works on DigitalOcean's droplets. I tested. Change the amount 4096 according to your need yum install nano -y sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo nano /etc/fstab add this line: /swapfile swap swap sw 0 0 run this command sudo ...


18

Is this not how to set up a swap file? I think you missed a step in between chmod and swapon: mkswap /mnt/sda2/swapfile As for the oxymoromic error... swapon: /mnt/sda2/swapfile: read swap header failed: Success What this literally means is there's a bug in the swapon code, but not necessarily one related to its primary functioning. C library ...


18

What sets the size of the tmpfs? (On my machine it resides in /dev/shm) I can see its entry in /etc/fstab, but no notation of its size. The kernel documentation covers this underneath the mount options: size: The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs ...


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