Skip to main content

What is Virtual Memory and Need of Swap Patitions


Virtual memory is a  concept whereby operating system can provide more RAM to a process than a physical RAM which is actually available. In a way it does is actually a disk space to allow a computers main memory i.e. Random Access Memory or RAM to appear to be bigger than it is.
What actually happens is that the operating system of the computer moves data around between disk and between physical RAM in order to implement this virtual memory area.

The act of moving pages of data between RAM and Disk is called Swapping in Linux and historically we always use the outermost edge of the disk for this purpose.

Let's see How to maximize the performance? If you look at a chemical hard disk you have a rotating stack of platters and it is rotating at a constant angular velocity otherwise it has a constant speed of rotation. Actually, if you are standing in a middle of spinning wheel then you wouldn't be moving as fast and at absolute speed as somebody standing on the outer edge.

Same is true for data access. The data can be accessed more quickly at the outer edge of the hard disk than they can at the inner edge. Therefore more frequently accessed files such as virtual memory swap files will be placed at the outer edge of the disk. So we always put the swap partitions at the end of the partition table or at the outer edge of the disk. That way a dedicated partition we knew would be at the outer edge of the disk and could be used to store the swap memory pages. There was an alternative option and is still an alternative option which is called swap file but on older equipments that has lower performance because we could not guarantee the swap file would be at the outer edge of the disk and we also had an overhead of dealing with the file systems as the swap files was living inside.

On modern drives, this is less of a concern for a couple of reasons. First of all new hard drives are a bit of faster than old ones used to be and they are still much slower than the CPU. In fact, the relative gap between the CPU speed and mechanical hard drive speed at least has got larger in last 5 to 10 years that means real-time swapping is actually painfully slow and really slows the computer down and it doesn't really matter  where it is at the outer edge of the disk or at the inner edge of the disk.

So a solid state drive provides a potential solution to this problem because they are faster but they suffer from wear problems. So if you read and write to and from solid-state drive too frequently you can actually wear out the flash memory more quickly.

A Linux desktop system for typical consumer workloads generally will not use or touch the swap space as long as 1 - 2 GB RAM is available under the normal type of consumer workload consider like internet surfing or email checking etc. When we are performing Linux installation for users and we are giving each of them at least 1 GB RAM, we normally don't really need swap.
If we have an automatic installer tool, automatically partitions a disk and gives us swap, then it's ok, as it is not going to hurt anything but we don't actually need to provide swap if the Virtual Memory has at least a 1GB of RAM.

Note: - It is important to note that if your physical RAM is around 1 to 2GB, and if your application requires 1.5 GB RAM then it would be always better to have a swap partition.

Swap partitions are themselves actually fairly obsolete because the relative performance difference from swap location on a modern mechanical HDD just not sufficient.

The fastest part of the Hard Drive is still so much slower than the CPU or the main memory that swap is slow and it does not matter which edge of the drive you are on. If you need swap for any reason, if you have some sort of thing for which you require a swap, you can add a swap file later to provide swap space and it isn't going to affect your performance that much.

If the system has 128MB or 256MB of RAM then a swap partition might be necessary at the time of Linux installation. Also, the systems that use swap files for either idle process management on these systems a swap file or swap logical volume is sufficient, no need of dedicated swap partition.

There are some exceptions to it. Let's see them: - Only a memory constrained systems which one under 512MB swap might still be needed. The swap partition is however only needed in a swap file if there isn't enough physical RAM available to install the system. If you can't get the system installed with the physical RAM available then you are going to need a swap partition. 

Comments

Popular posts from this blog

What Relational Database Management System is all About ? What is RDBMS?

In this tutorial, we will discuss Relational Database Management Systems .  Let's first discuss What do databases do ? Databases have an ability to store a large amount of data. So when we search for any information on the internet then it finds all the URL's that meet the criteria. So far if you have been looking for a particular data or subject and type that in a web browser and click search then that's actually talking to a database. When you use Twitter, all messages are stored and indexed by #tags and every time any tweet is sent it is stored in a database allows them to search them for information, with a particular information, with particular #tags. We use PhotoBucket for uploading images on the internet and they have been linked to the user accounts. Other people can access those images as well and also other programs like Facebook, Messenger etc. Also, a lot of Google products are products of the database. Databases are required to store a ...

Top 10 Website Hosting Companies in 2019

Top 10 Website Hosting Companies in 2019. There is a number of websites of individuals or businesses. This website can be accessed from any part of the world once they are entered or kept on the web. Now web hosters are the company or firm who uses the technology, tools and various factors necessary to keep any particular site on the web. 1. High performance. 2. Cost. 3. Maintainance. 4. Effectiveness. 5. Server Location. 6. Customer Support 7. Security. 1)  HostGator HostGator is a global provider of web hosting and related services. Founded in a dorm room at Florida Atlantic University by Brent Oxley, HostGator has grown into a leading provider of Shared, Reseller, VPS, and Dedicated web hosting. HostGator is headquartered in Houston and Austin, Texas, with several international offices throughout the globe. for more details:  https://www.hostgator.in 2)  Hostripples Hostripples is among the first companies in India to offer fully automate...

What is AJAX all about? What is the use of AJAX ?

Brief Introduction to AJAX Many of you may be wondering what is AJAX? and Why one should learn it? So let's have a look at how you can use AJAX with JavaScript, for developing a dynamic web application? Before discussing about AJAX let's have a look at how browser's get information to display a page. When a browser requests a page from a website , then the browser in your machine is acting as a client. The website is being delivered through a machine that is serving up the information, therefore we call that a server. When you ask for a page, the client makes a request to a server and the server returns a page. Sometimes when you are looking at a page you may want to ask for some additional information from the server. Say for ex: - That your page has some thumbnails for photo albums and perhaps the album has more thumbnails than you can see in the current view. Without AJAX, if you want to see more thumbnails, you would have to make a request back t...