Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 563  / 3 Years ago, tue, july 27, 2021, 8:49:09

I have a question regarding swap and physical memory. Often times I run a program that requires a lot of memory and as a result I can see some of the data is copied from the physical memory into swap. However, once the program is terminated, and the physical memory is freed I can still see a considerable amount of data on swap which significantly slows down the system and is annoying!



What is the reason behind this and how does the OS decide which part of data should go to swap? How long is this data supposed to be there and how is it "freed"?


More From » 10.10

 Answers
1

If you frequently experience slowdown due to page swapping you likely need more memory. Shutting down unused or low priority services and making other memory reducing adjustments may be used as a temporary stopgap.




What is the reason behind this and how does the OS decide which part of data should go to swap?




While your memory heavy process was running the memory management swapped out pages to make room for your process. This is usually done on a Least Recently Used basis. (Programs often have pages of memory which were required at one point, but no longer are.)



If you have multiple devices, you can break the page mapping by removing that swap partition. This will force the pages into memory (although they may be swapped out fairly quickly).




How long is this data supposed to be there and how is it "freed"?




Once mapped to swap, pages may remain mapped to swap until the process is terminated at which point the pages are "freed". Pages mapped to the swap space may be located in memory. The page manager may maintain the mapping to prevent the need to remap the page if it needs to be swapped out again.



Some slowdown while the pages are swapped into memory is to be expected. Depending on memory demand and program scheduling, use of swap in known to significantly decrease performance.



Using sar or munin to monitor page in/out activity should enable you do see how long it takes to map active pages into memory. Once they have been swapped back into memory they should stay there as long as memory is available.



Some things which may increase swap performance.




  • A dedicated swap partition located next to actively accessed partitions. This reduces head latency when swapping is required.

  • Using a swap file located on the most heavily used partition. This may reduce head latency.

  • A dedicated drive for the swap partition. A number of I/O performance improvements apply.

  • Use of an SSD for swap space. I/O is much faster than disk. (A fast USB drive may also perform better than your disk, but measure I/O rates first.)



Swap files and partitions can be added and removed from a running system. Swap devices can be given different priorities to control which device is used first.


[#39650] Wednesday, July 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
igeonlothe

Total Points: 370
Total Questions: 121
Total Answers: 114

Location: United States Minor Outlying Island
Member since Fri, Feb 5, 2021
3 Years ago
igeonlothe questions
Wed, May 31, 23, 02:34, 1 Year ago
Sat, Mar 12, 22, 17:13, 2 Years ago
Tue, Aug 31, 21, 09:46, 3 Years ago
;