The kernel uses a memory management program that detects blocks, aka pages, of memory in which the contents have not been used recently. This frees up RAM and makes room for more data to be entered into your spreadsheet. The total amount of memory in a Linux computer is the RAM plus swap space and is referred to as virtual memory. Linux provides for two types of swap space.
By default, most Linux installations create a swap partition, but it is also possible to use a specially configured file as a swap file. A swap partition is just what its name implies—a standard disk partition that is designated as swap space by the mkswap command.
A swap file can be used if there is no free disk space in which to create a new swap partition or space in a volume group where a logical volume can be created for swap space. This is just a regular file that is created and preallocated to a specified size.
Then the mkswap command is run to configure it as swap space. Thrashing can occur when total virtual memory, both RAM and swap space, become nearly full. The system spends so much time paging blocks of memory between swap space and RAM and back that little time is left for real work.
The typical symptoms of this are obvious: The system becomes slow or completely unresponsive, and the hard drive activity light is on almost constantly. If you can manage to issue a command like free that shows CPU load and memory usage, you will see that the CPU load is very high, perhaps as much as 30 to 40 times the number of CPU cores in the system. Another symptom is that both RAM and swap space are almost completely allocated.
After the fact, looking at SAR system activity report data can also show these symptoms. I install SAR on every system I work on and use it for post-repair forensic analysis.
Many years ago, the rule of thumb for the amount of swap space that should be allocated on the hard drive was 2X the amount of RAM installed in the computer of course, that was when most computers' RAM was measured in KB or MB.
This rule took into account the facts that RAM sizes were typically quite small at that time and that allocating more than 2X RAM for swap space did not improve performance. With more than twice RAM for swap, most systems spent more time thrashing than actually performing useful work. RAM has become an inexpensive commodity and most computers these days have amounts of RAM that extend into tens of gigabytes.
When dealing with computers having huge amounts of RAM, the limiting performance factor for swap space is far lower than the 2X multiplier. The Fedora 28 online Installation Guide, which can be found online at Fedora Installation Guide , defines current thinking about swap space allocation.
I have included below some discussion and the table of recommendations from that document. The following table provides the recommended size of a swap partition depending on the amount of RAM in your system and whether you want sufficient memory for your system to hibernate.
The recommended swap partition size is established automatically during installation. To allow for hibernation, however, you will need to edit the swap space in the custom partitioning stage. At the border between each range listed above for example, a system with 2 GB, 8 GB, or 64 GB of system RAM , use discretion with regard to chosen swap space and hibernation support. If your system resources allow for it, increasing the swap space may lead to better performance.
Of course, most Linux administrators have their own ideas about the appropriate amount of swap space—as well as pretty much everything else. Table 2, below, contains my recommendations based on my personal experiences in multiple environments. These may not work for you, but as with Table 1, they may help you get started. One consideration in both tables is that as the amount of RAM increases, beyond a certain point adding more swap space simply leads to thrashing well before the swap space even comes close to being filled.
If you have too little virtual memory while following these recommendations, you should add more RAM, if possible, rather than more swap space. As with all recommendations that affect system performance, use what works best for your specific environment.
This will take time and effort to experiment and make changes based on the conditions in your Linux environment. Due to changing requirements for swap space on hosts with Linux already installed, it may become necessary to modify the amount of swap space defined for the system. This procedure can be used for any general case where the amount of swap space needs to be increased.
What is Swap Space? Adding Swap Space 5. Removing Swap Space 5. Moving Swap Space. Hibernation suspend-to-disk The hibernation feature suspend-to-disk writes out the contents of RAM to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. Although the latest versions of Ubuntu don't support hibernation OOTB you may configure your system to allow Hibernation.
Unforeseeable Circumstances Unforeseeable events can and will happen a program going crazy, some action needing much more space than you thought, or any other unpredictable combination of events. In these cases, swap can give you an extra delay to figure out what happened, or to finish what you are working on.
Optimizing memory usage Since mechanical hard drives are considerably slower than RAM SSD - Solid State Drive - storage is not as slow as physical drives, but still slower than RAM , when you need a file be it a data file like a video, executables like Firefox, or libraries , the Linux kernel reads the file into RAM and keeps it there, so that the next time you need it, it is already in RAM and data access is much faster. The portions of RAM that accelerate disk read are called "cached memory.
The Linux kernel automatically moves RAM reserved by programs--but not really used--into swap, so that it can serve the better purpose of extending cached memory. Optimizing Swap performance Because swap space uses a disk device, this can cause performance issues in any system that uses swap space significantly because the system itself may also be using the same disk device at the same time that it is required for swap operations. One way to reduce this problem is to have swap space on a different physical drive so that the competition for that resource is either reduced or eliminated.
Also, it's recommended that the swap space is maximum twice the amount of RAM depending upon the amount of hard disk space available for the system because of diminishing returns. The only downside to having more swap space than you will actually use, is the disk space you will be reserving for it. Swap is generally associated with a swap partition, perhaps because the user is prompted to create a swap partition at the time of installation.
In fact, any file can be used as a swapping device, be it a partition or a conventional file. Swap can be added by increasing the size of the swap partition or by adding a swap file. Keep in mind that when creating a swap file that it may not necessarily be using contiguous disk blocks as a swap partition will , and this could have a negative impact on performance as disk access times may be longer, and the more your system uses swap, the worse it will be.
The Linux kernel also accesses swap disk block IO directly bypassing all caching, metadata and filesystem code, so a swap file should have no ill effect on the stability of your base filesystem. Since kernel 2. The advantages of a swap file are many, but it is problematic for using the default swsusp hibernation method for powerless sleep. The best solution for maintaining hibernate capability after adding RAM is to increase the size of the swap partition.
If by some miracle you're able to resize your swap partition from here, I imagine your life will be a lot easier than mine. When there are only a few applications running your system manages with the available RAM. But if there are too many applications running or if the applications need a lot of RAM, then your system gets into trouble.
If an application needs more memory but entire RAM is already in use, the application will crash. Swap acts as a breather to your system when the RAM is exhausted. What happens here is that when the RAM is exhausted, your Linux system uses part of the hard disk memory and allocates it to the running application. That sounds cool. This means if you allocate like 50GB of swap size, your system can run hundreds or perhaps thousands of applications at the same time?
You see, the speed matters here. RAM access data in the order of nanoseconds. An SSD access data in microseconds while as a normal hard disk accesses the data in milliseconds. If an application relies too much on the swap, its performance will degrade as it cannot access the data at the same speed as it would have in RAM. So instead of taking 1 second for a task, it may take several minutes to complete the same task.
It will leave the application almost useless. This is known as thrashing in computing terms.
0コメント