It simulates the memory and can detect memory leaks.
Valgrind was originally designed to be a free memory debugging tool for Linux on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers. 0.0 What is memory and RAM, all that stuff Total system memory on my PC is made up of physical memory, in the form of random access memory (RAM), and virtual memory. This is different to “storage”, which is comprised of hard drives and other devices that are non-volatile and retain their contents when the computer is turned off. So memory is different from storage. PCs use RAM to run programs and operations. By default, the PC saves all the bits of information about apps and processes you run onto this short term memory. When there is not enough physical memory to complete a task, the PC uses virtual memory. In this memory management scheme, the PC can SWAP data between RAM and a temporary space on the hard drive, known as a paging file. Moving data to a paging file in secondary storage makes RAM available for new tasks and data, but it can result in delays. 0.1 What is SWAP space? Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory. If M < 2 S = M *2 Else S = M + 2 For systems with really large amounts of RAM (more than 32 GB) you can likely get away with a smaller swap partition (around 1x, or less, of physical RAM). 0.2 Virtual memory So actually what is a virtual memory? Core reason of introducing Virtual memory is the use of space on a hard disk drive (HDD) to simulate additional main memory. Also, when program is launched. The program only know how to access virtual memory address, but not physical address on RAM. User space applications have no way of accessing the memory using physical addresses - that's one of the abstractions the OS gives each process. In order to free up space in memory, an operating system with a virtual memory capability transfers data that is not immediately needed from memory to the HDD; when that data is needed again, it is copied back into memory. That is, when all of the RAM is being used (e.g., if there are many programs open simultaneously or if one very large program is in use), a computer with virtual memory enabled will swap data to the HDD and back to memory as needed, thus, in effect, increasing the total system memory. Application programs cannot distinguish between primary memory and virtual memory, and thus they run as if all the data is in primary memory. Virtual memory is likewise usually invisible to the user. However, its existence can become apparent in the form of degraded performance if it is used too heavily, because the CPU (central processing unit) will spend more of its time copying data back and forth to the HDD and less of its time doing useful work. This is termed thrashing. The reduced efficiency is also a result of the facts that HDDs are far slower than RAM and that they are not designed for accessing small pieces of data (e.g., single bytes) one at a time. The space on a HDD that is used to store the overflow from memory is called swap space. On Linux it is a separate partition (i.e., a logically independent section of a HDD) that is set up during installation of the operating system and which is referred to as the swap partition. It is generally recommended that the size of the swap partition be about twice the amount of system RAM, for small RAM computers. The swap space is divided into segments called pages, each of which is associated with a specific address in memory. When an address is referenced, the page is swapped into memory. It is returned to the disk when no longer needed and other pages are called. 1.0 Virtual Memory limit
1.1 Special notes: how to clean up memory on Ubuntu 1. sudo -i This means that login-specific resource files such as .profile, .bashrc or .login will be read and executed by the shell. So it enables shells to control critical parts of the system For the below, choose one. 2. echo 1 > /proc/sys/vm/drop_caches Free the page cache 3. echo 2 > /proc/sys/vm/drop_caches Freeing Up the Dentries and Inodes 4. echo 3 > /proc/sys/vm/drop_caches Freeing Up the Page Cache, Dentries and Inodes 5. sync Flushing the File System Buffers 2.0 Physical memory 3.0 Segments of memory
|
AuthorShaowu Pan Archives
December 2017
Categories
All
|