Hello Guys,

Yesterday when i was working, my Ubuntu stop responding(Freeze) and  was unable to perform any task. I checked my RAM status and it was nearly 100%. After some research, i found the solution and  I think its worthwhile to share this, since this is very common problem with relatively simple solution, but can waste your lot of time if doesn’t handle in proper way.  So below are the reasons and solution for the same. Hopefully it would be beneficial for you.

Reason:

The Ubuntu operating system gets freeze due to insufficient  RAM available, because there are  no space available to open other applications. Basically by default,  swap file gets created in the file system in OS installation time itself,  but due to some reason, it get removed, which ultimately raise the problem of freezing the operating system.

The Swap Space(Swap File) on the hard drive will be used mainly,  when there is  no sufficient space left in the RAM to hold in-use application data.

The information written to disk will be significantly slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap file for the older data. Overall, having swap file as a fallback is a good safety net against out-of-memory exceptions on systems with non-SSD storage available.

You can check your Swap file in your system monitor application.

 

Solution.

STEP 1 – Check if the system has configured swap file.

If you don’t get back any output, this means your system does not have Swap file available. Currently, you can verify that there is no active swap file using the free utility:

As you can see in the output (Swap row),  there is no swap active on the system.

STEP 2Checking Availability of space on the hard drive Partition, so we can create the swap file.

In the output, the device with / in the “Mounted on" column is our disk  in this case. We have plenty of space available in this example (only 1.4G used). Your usage will probably be different.

STEP 3 – Creating a swap file

If you have 4GB of ram on your system, then ideally, you should create a swap file of 4GB.

We can verify that the correct amount of space was reserved by typing:

Our file has been created with the correct amount of space set aside.

STEP 4- Enabling the swap file.

Make the file only accessible to root by typing:

We can now mark the file as swap space by typing:

After marking the file, we can enable the swap file, allowing our system to start utilizing it:

Verify that the swap is available by typing:

STEP – 5 Making swap file permanent 

Our recent changes have enabled the swap file for the current session. However, if we reboot, the OS will not retain the swap settings . We can change this by adding the swap file to our /etc/fstab file.

Back up the /etc/fstab file in case anything goes wrong:

Add the swap file information to the end of your /etc/fstab file by typing:

 

Now we have successfully created a swap space. Hopefully, the  problem of Ubuntu Freeze will also go away.

Please comments and share your experience with us to make us better next time.