Clear Cache Ram Ubuntu



  1. Clear Linux Cache
  2. Ubuntu Clear Apt Cache
  3. Linux Clear Memory Cache
  4. Ubuntu Clean Apt Cache
  5. Clear Dns Cache Ubuntu

Swap is a virtual memory concept that allows your system to use a portion of your hard drive as the physical memory (RAM). Your system swaps the inactive pages in memory in RAM to this swap space on the hard disk. This way, your system has more free RAM available for other programs.

I have shown you to check RAM in Linux and I have also discussed how to check swap usage on Linux. In this quick tip, I’ll show you how to clear swap memory in Linux.

Clear swap in Linux

But first, why would you want to clear swap at all? There could be various reasons. Some time your system will use a lot of swap even when plenty of RAM is available.

  • An easy way to do this is to run 'free -m' to see what is being used in swap and in RAM. Once you power it off, you can wait an arbitrary amount of time (30 sec or so) to give the operation time to complete, then power the swap back on. This clears the swap memory cache and re-enables it. Here are all of the commands you'll need!
  • To clear ram cache, you may call the script whenever required. Setting a cron to clear RAM cache everyday 2 hours. root@linuxhelp # crontab -e Append the following line, save and exit to execute it at 2 hours daily. 0 2. /path/to/script.sh To clear automatically the RAM cache on production server.
  • If you have to clear the disk cache, the first command is safest in enterprise and production as “.echo 1.” will clear the PageCache only. It is not recommended to use third option above “.echo 3 ” in production until you know what you are doing, as it will clear PageCache, dentries and inodes.

Clear RAM Memory Cache, Buffer and Swap Space on Linux. Have you ever have any process is eating away your memory and you want to clear it, Linux provides a way to flush or clear ram cache. How to Clear Cache in Linux? Every Linux System has three options to clear cache without interrupting any processes or services. Clear PageCache only. GNU or Linux has amazing Memory Management system for efficient Memory Management but still if you think that any process is occupying your memory then Linux offers the process to clear the RAM cache. The process to do so is given in the following text.

This may or may not be associated with swappiness of your system. Sometimes it happens that the RAM doesn’t swap back the pages from swap space to RAM. In such cases, you’ll have to manually clear the swap.

Attention

Before clearing the swap, check that you have enough free RAM available to take all the pages from swap. In other words, you should have more free RAM available than the current swap in use.

You can see the state of RAM and swap using the free command in Linux:

Once you are sure that the size of free RAM is bigger than the swap memory in use, you can clear the swap memory by turning it off and on again.

Pun aside, that’s the way to do it. Disable all the swap using this command:

Now turn the swap back on:

That’s it. This simple exercise will clear the swap in your Linux system. I hope you find this little tip helpful. Any questions or suggestions are always welcome.

Become a Member for FREE
Become a member to get the regular Linux newsletter (2-4 times a month) and access member-only contents.

Join the conversation.

How to use Intel Optane Memory for SSD Caching

Recently Michael from Opvizor ordered a new laptop - a HP ProBook 650 G5. And here comes his story to enable Intel Optane using Ubuntu.

Addicted to Linux, the decision was clear to purge Windows and to setup Ubuntu, currently 18.04 LTS.
But wait:

The machine is equiped with an 'INTEL® OPTANE™ MEMORY H10 WITH SOLID STATE STORAGE'.

**What is that?
**Ask Google helped:

It is a solid state disk with an additional non volatile cache memory. That cache is build up of Optane memory, which is slower than DRAM, but faster than flash memory, and non volatile too.
Its easy for Windows users - there is the preinstalled Intel RST-Driver, which setups the Optane memory as cache for the SSD. But in Linux? No driver support from Intel for that.

However, using the Optane Memory isn't that hard. Many people on the net suggest to use it as an independent, fast, but also small disk.

Clear Linux Cache

But my workloads vary, and I don't want to waste time deciding what to put on Optane and what to put on flash. So I wanted to use the Optane Memory as cache too, like the Windows people do.

Optane Memory in Linux

On the physical layer, the device splits up into two independent nvme devices:

These devices are mapped as /dev/nvme0 and /dev/nvme1, and because of nvme technology, the usable blockdevices are /dev/nvme0n1 and /dev/nvme1n1 (aka nvme namespaces).
So the first step is to disable the BIOS option 'Advanced / System options / Configure Storage Controller for Intel Optane'. Have a look in the option ROM of the controller too, to make sure there is no combined device anymore. These options are intended for the RST-driver to recognize a device constructed of the two components. But in Linux we will do that without RST, so no need for that options.

Be aware: Since there is no support for RST's caching with Optane memory in Linux, you can't dual boot Windows with RST caching configured, and Linux. Either turn of Optane in Windows or put Windows into a VM in the Linux OS. To make things not complicated, the following won't consider dual boot.

Installation

Step 1

Start with a conventional installation, use the complete SSD (/dev/nvme0n1) with LVM and LUKS Encryption. LVM is mandatory for the latter steps, encryption optional, but assumed to be enabled. So in the installer, these are the selections:

After installation, the resulting disk layout is quite simple:

nvme0n1p1 holds /boot/efi, nvme0n1p2 holds /boot, and nvme0n1p3 holds a LUKS container, which is used by LVM as physical device for the volume group ubuntu-vg. LVM delivers the logical volumes for swap and root.

Configure LUKS

When you have successfully booted into your new system, the next step is to configure the LUKS encryption layer:

The purpose of /etc/crypttab is to hold a list of encrypted devices. This information is essential for booting the system. There should be already one line for the device nvme0n1p3_crypt . Now add the line for nvme1n1_crypt, using the UUID from the last step.

Of course, your UUIDs will be different. The discard option is not used for the Optane-based device, since Optane Memory works in a different way than flash memory and so won't need discards.

lvmcache

The cache is build with lvmcache, gives a compact explanation. Use the command:

Clear cache ubuntu terminal

That command given, you created a pool for the caching using the complete optane memory. Due to thin provisioning capabilities, this pool serves both caching and metadata device needed by the kernel driver dm-cache.

The cache is created for the logical volume root (holding your root filesystem). The cache mode is set to writeback, which is perfectly good since you use non volatile memory!

Do not reboot

And now: DON'T REBOOT, since the machine won't come up again! You have to do some additional tasks. Enable the universe-repositories and install the thin-provisioning-tools.

Ubuntu Clear Apt Cache

These will be needed to check the consistency of the cached device on boot.

script thin-provisioning-tools

Download the script thin-provisioning-tools and install it to the directory /usr/share/initramfs-tools/hooks:

Download thin-provisioning-tools

The script is based on this article, with support for lvmcache added. The purpose of this script is, to put the binaries of the thin-provisioning-tools onto the initial ramdisk, and to load the required kernel modules for caching.

Finish

These initial ramdisk(s) have support for:

  • second LUKS device based on the Optane Memory
  • the kernel drivers needed to run the cache
  • the tools used to check the cached volume, needed for starting it

NOW you are save to reboot. Don't be afraid when asked twice for LUKS passwords: once for nvme0n1p3_crypt, and once for nvme1n1_crypt.

Results

To get a quick overview of your cache usage, issue the command

Linux Clear Memory Cache

You can repeat the command over time. You will see the cache filling with data, and you will see the efficiency going up when looking at the ratio hits/misses. E.g.

Ubuntu Clean Apt Cache

Additional notes

Clear Dns Cache Ubuntu

If you decide to remove the cache from your configuration, run

Typically, Ubuntu 18.04 creates a logical volume for swapping. Consider to replace this with a swapfile in your root filesystem. The logical volume swap is not cached with Optane memory, but the logical volume root is.