Swapfile configuration and best practice in Azure VM?

EnterpriseArchitect 6,041 Reputation points
2023-02-13T05:50:36.05+00:00

Hi Everyone,

Does Azure Virtual Machine is also utilizing or will be using Swap files when required on both the Guest OS level as well as the Hypervisor level?

If yes, how can this be configured as best practice for Azure VM performance?

I look forward to your reply.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,044 questions
0 comments No comments
{count} votes

Accepted answer
  1. Prrudram-MSFT 28,286 Reputation points Microsoft Employee Moderator
    2023-02-13T09:26:24.3266667+00:00

    Hi @EnterpriseArchitect

    Yes, Azure VMs with Linux at the guest level uses the swap space when required which is similar to page file in windows.

    The Azure Linux Agent or Cloud-init can be used to configure swap space using the local resource disk. This resource disk is attached to the VM after provisioning on Azure. The local resource disk is a temporary disk, and might be emptied when the VM is deprovisioned. The following blocks show how to configure this swap.

    Note: Do not create swap space on the OS disk.

    Azure Linux Agent Modify the following parameters in /etc/waagent.conf

    ResourceDisk.Format=y
    ResourceDisk.Filesystem=ext4
    ResourceDisk.MountPoint=/mnt/resource
    ResourceDisk.EnableSwap=y
    ResourceDisk.SwapSizeMB=2048    ## NOTE: Set this to your desired size.
    

    More detailed steps that you need to follow are available at General Linux System Requirements look from step#7

    Additional details:

    You can check how the system is doing memory wise by running the “free” command from the Linux shell prompt, and in particular, you can use “cat /proc/swaps” to see the state of the swap space – how much is configured and how much is in use. See the screenshot, below.

    Note: For cases where the swap space is not configured at all, as is the default case with Linux VM’s provisioned in Windows Azure Virtual Machines, the “cat /proc/swaps” will return nothing, and likewise the “free” command will not show any activity in swap.

    Hope this helps! :)

    If this response has answered your query, please 'Accept as Answer' and Upvote using "Thumbs-up" so that the relevancy of this post will improve when anyone in the community search for a similar query.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.