Out of memory

Last updated
Out of memory screen display on system running Linux Mint 9 (kernel 2.6.32) Out of Memory in Linux.jpg
Out of memory screen display on system running Linux Mint 9 (kernel 2.6.32)

Out of memory (OOM) is an often undesired state of computer operation where no additional memory can be allocated for use by programs or the operating system. Such a system will be unable to load any additional programs, and since many programs may load additional data into memory during execution, these will cease to function correctly. This usually occurs because all available memory, including disk swap space, has been allocated.

Contents

History

Historically, the out-of-memory condition was more common than it is now, since early computers and operating systems were limited to small amounts of physical random-access memory (RAM) due to the inability of early processors to address large amounts of memory, as well as cost considerations. Since the advent of virtual memory opened the door for the usage of swap space, the condition is less frequent. Almost all modern programs expect to be able to allocate and deallocate memory freely at run-time, and tend to fail in uncontrolled ways (crash) when that expectation is not met; older ones often allocated memory only once, checked whether they got enough to do all their work, and then expected no more to be forthcoming. Therefore, they would either fail immediately with an "out of memory" error (OOME) message, or work as expected.[ citation needed ]

Early operating systems such as MS-DOS lacked support for multitasking. Programs were allocated physical memory that they could use as they needed. Physical memory was often a scarce resource, and when it was exhausted by applications such as those with terminate-and-stay-resident functionality, no further applications could be started until running applications were closed.

Modern operating systems provide virtual memory, in which processes are given a range of memory, but where the memory does not directly correspond to actual physical RAM. Virtual memory can be backed by physical RAM, a disk file via mmap (on Unix-derivatives) or MapViewOfFile (on Windows), or swap space, and the operating system can move virtual memory pages around as it needs. Because virtual memory does not need to be backed by physical memory, exhaustion of it is rare, and usually there are other limits imposed by the operating system on resource consumption. [1]

As predicted by Moore's law, the amount of physical memory in all computers has grown almost exponentially, although this is offset to some degree by programs and files themselves becoming larger. In some cases, a computer with virtual memory support where the majority of the loaded data resides on the hard disk may run out of physical memory but not virtual memory, thus causing excessive paging. This condition, known as thrashing, usually renders the computer unusable until some programs are closed or the machine is rebooted. Due to these reasons, an out-of-memory message is rarely encountered by applications with modern computers.[ citation needed ]

It is, however, still possible to encounter an OOM condition with a modern computer. The typical OOM case in modern computers happens when the operating system is unable to create any more virtual memory, because all of its potential backing devices have been filled or the end-user has disabled them. The condition may arise because of copy-on-write after fork().

Recovery

The kernels of operating systems such as Linux will attempt to recover from this type of OOM condition by terminating one or more processes, a mechanism known as the OOM Killer. [2] [3] Linux 4.6 (released in May 2016) introduced changes in OOM situations, improving detection and reliability. [4] [5] cgroup awareness in OOM killer was implemented in Linux kernel 4.19 released in October 2018, which adds an ability to kill a cgroup as a single unit. [6]

Due to late activation of OOM Killer on some Linux systems, [7] there are several daemons and kernel patches that help to recover memory from OOM condition before it was too late.

Per-process memory limits

Apart from the system-wide physical memory limits, some systems limit the amount of memory each process can use. Usually a matter of policy, such a limitation can also happen when the OS has a larger address space than is available at the process level. Some high-end 32-bit systems (such as those with Physical Address Extension enabled) come with 8 gigabytes or more of system memory, even though any single process can only access 4 GB of it in a 32-bit flat memory model.

A process that exceeds its per-process limit and then attempts to allocate further memory will encounter an error condition. For example, the C standard function for allocating memory, malloc(), will return NULL and a well-behaved application should handle this situation.

Related Research Articles

<span class="mw-page-title-main">Non-uniform memory access</span> Computer memory design used in multiprocessing

Non-uniform memory access (NUMA) is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory. The benefits of NUMA are limited to particular workloads, notably on servers where the data is often associated strongly with certain tasks or users.

<span class="mw-page-title-main">Process (computing)</span> Particular execution of a computer program

In computing, a process is the instance of a computer program that is being executed by one or many threads. There are many different process models, some of which are light weight, but almost all processes are rooted in an operating system (OS) process which comprises the program code, assigned system resources, physical and logical access permissions, and data structures to initiate, control and coordinate execution activity. Depending on the OS, a process may be made up of multiple threads of execution that execute instructions concurrently.

In computer operating systems, memory paging is a memory management scheme by which a computer stores and retrieves data from secondary storage for use in main memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. Paging is an important part of virtual memory implementations in modern operating systems, using secondary storage to let programs exceed the size of available physical memory.

In computer science, thrashing occurs in a system with virtual memory when a computer's real storage resources are overcommitted, leading to a constant state of paging and page faults, slowing most application-level processing. This causes the performance of the computer to degrade or collapse. The situation can continue indefinitely until the user closes some running applications or the active processes free up additional virtual memory resources.

In computing, a page fault is an exception that the memory management unit (MMU) raises when a process accesses a memory page without proper preparations. Accessing the page requires a mapping to be added to the process's virtual address space. Besides, the actual page contents may need to be loaded from a backing store, such as a disk. The MMU detects the page fault, but the operating system's kernel handles the exception by making the required page accessible in the physical memory or denying an illegal memory access.

The Direct Rendering Manager (DRM) is a subsystem of the Linux kernel responsible for interfacing with GPUs of modern video cards. DRM exposes an API that user-space programs can use to send commands and data to the GPU and perform operations such as configuring the mode setting of the display. DRM was first developed as the kernel-space component of the X Server Direct Rendering Infrastructure, but since then it has been used by other graphic stack alternatives such as Wayland and standalone applications and libraries such as SDL2 and Kodi.

seccomp is a computer security facility in the Linux kernel. seccomp allows a process to make a one-way transition into a "secure" state where it cannot make any system calls except exit , sigreturn , read and write to already-open file descriptors. Should it attempt any other system calls, the kernel will either just log the event or terminate the process with SIGKILL or SIGSYS. In this sense, it does not virtualize the system's resources but isolates the process from them entirely.

OS-level virtualization is an operating system (OS) virtualization paradigm in which the kernel allows the existence of multiple isolated user space instances, called containers, zones, virtual private servers (OpenVZ), partitions, virtual environments (VEs), virtual kernels, or jails. Such instances may look like real computers from the point of view of programs running in them. A computer program running on an ordinary operating system can see all resources of that computer. However, programs running inside of a container can only see the container's contents and devices assigned to the container.

<span class="mw-page-title-main">Minix 3</span> Unix-like operating system

Minix 3 is a small, Unix-like operating system. It is published under a BSD-3-Clause license and is a successor project to the earlier versions, Minix 1 and 2.

ext4 is a journaling file system for Linux, developed as the successor to ext3.

<span class="mw-page-title-main">Kernel-based Virtual Machine</span> Virtualization module in the Linux kernel

Kernel-based Virtual Machine (KVM) is a free and open-source virtualization module in the Linux kernel that allows the kernel to function as a hypervisor. It was merged into the mainline Linux kernel in version 2.6.20, which was released on February 5, 2007. KVM requires a processor with hardware virtualization extensions, such as Intel VT or AMD-V. KVM has also been ported to other operating systems such as FreeBSD and illumos in the form of loadable kernel modules.

The Berkeley Packet Filter is a network tap and packet filter which permits computer network packets to be captured and filtered at the operating system level. It provides a raw interface to data link layers, permitting raw link-layer packets to be sent and received, and allows a userspace process to supply a filter program that specifies which packets it wants to receive. For example, a tcpdump process may want to receive only packets that initiate a TCP connection. BPF returns only packets that pass the filter that the process supplies. This avoids copying unwanted packets from the operating system kernel to the process, greatly improving performance. The filter program is in the form of instructions for a virtual machine, which are interpreted, or compiled into machine code by a just-in-time (JIT) mechanism and executed, in the kernel.

A page, memory page, or virtual page is a fixed-length contiguous block of virtual memory, described by a single entry in a page table. It is the smallest unit of data for memory management in an operating system that uses virtual memory. Similarly, a page frame is the smallest fixed-length contiguous block of physical memory into which memory pages are mapped by the operating system.

<span class="mw-page-title-main">Kernel (operating system)</span> Core of a computer operating system

The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. The kernel is also responsible for preventing and mitigating conflicts between different processes. It is the portion of the operating system code that is always resident in memory and facilitates interactions between hardware and software components. A full kernel controls all hardware resources via device drivers, arbitrates conflicts between processes concerning such resources, and optimizes the utilization of common resources e.g. CPU & cache usage, file systems, and network sockets. On most systems, the kernel is one of the first programs loaded on startup. It handles the rest of startup as well as memory, peripherals, and input/output (I/O) requests from software, translating them into data-processing instructions for the central processing unit.

<span class="mw-page-title-main">LXC</span> Operating system-level virtualization for Linux

Linux Containers (LXC) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.

cgroups is a Linux kernel feature that limits, accounts for, and isolates the resource usage of a collection of processes.

zram, formerly called compcache, is a Linux kernel module for creating a compressed block device in RAM, i.e. a RAM disk with on-the-fly disk compression. The block device created with zram can then be used for swap or as general-purpose RAM disk. The two most common uses for zram are for the storage of temporary files and as a swap device. Initially, zram had only the latter function, hence the original name "compcache". Unlike swap, zram only uses 0.1% of the maximum size of the disk when not in use.

zswap is a Linux kernel feature that provides a compressed write-back cache for swapped pages, as a form of virtual memory compression. Instead of moving memory pages to a swap device when they are to be swapped out, zswap performs their compression and then stores them into a memory pool dynamically allocated in the system RAM. Later writeback to the actual swap device is deferred or even completely avoided, resulting in a significantly reduced I/O for Linux systems that require swapping; the tradeoff is the need for additional CPU cycles to perform the compression.

Namespaces are a feature of the Linux kernel that partition kernel resources such that one set of processes sees one set of resources, while another set of processes sees a different set of resources. The feature works by having the same namespace for a set of resources and processes, but those namespaces refer to distinct resources. Resources may exist in multiple spaces. Examples of such resources are process IDs, host-names, user IDs, file names, some names associated with network access, and Inter-process communication.

In the Linux kernel, kernfs is a set of functions that contain the functionality required for creating the pseudo file systems used internally by various kernel subsystems so that they may use virtual files. For example, sysfs provides a set of virtual files by exporting information about hardware devices and associated device drivers from the kernel's device model to user space.

References

  1. "How to Upgrade Ram Complete Guide". wincah.com. 2023.
  2. Linux OOM Killer
  3. "How to Configure the Linux Out-of-Memory Killer" . Retrieved 19 February 2015.
  4. "Toward more predictable and reliable out-of-memory handling [LWN.net]". lwn.net.
  5. "Linux_4.6 - Linux Kernel Newbies". kernelnewbies.org.
  6. "Linux_4.19 - Linux Kernel Newbies". kernelnewbies.org.
  7. "linux kernel - Is it possible to make the OOM killer intervent earlier?". Super User. Retrieved 7 March 2021.
  8. rfjakob (7 March 2021), rfjakob/earlyoom, GitHub, retrieved 7 March 2021
  9. Avramov, Alexey (5 March 2021), hakavlad/nohang, GitHub, retrieved 7 March 2021
  10. "linux-psi.git - Linux resource pressure metrics". git.cmpxchg.org. Retrieved 7 March 2021.
  11. facebookincubator/oomd, Facebook Incubator, 3 March 2021, retrieved 7 March 2021