Swap space with mounts module not working

Bug #1410824 reported by trialotto
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

The cloud config settings

# swap can also be set up by the 'mounts' module
# default is to not create any swap files, because 'size' is set to 0
swap:
   filename: /swap.img
   size: "auto" or size in bytes
   maxsize: size in bytes

will not result in a swap space.

Some big questions are present with respect to the operational logic behind this cloud config setting:

a) which (underlying) command is used to create the swap space?
b) is being made use of sparse files? (not desirable for swap. Answer is probably "not", given "size: auto" option)
c) what are the requirements for creation of swap? (should a partition exist and/or should the partition type be 82. Answer is probably "no", given the fact that a swap file is created)

In essence, some problems encountered when creating swap manually (instead of using the swap config setting):

1) when creating a swap file on the ephemeral disk: mkswap does not work probably (error: ...should at least be 40Kib)
2) when creating a separate partition of type 83 (hence preventing mkswap errors):

- swap file (manually created) exists, but is not active as swap,
- swap file (using the swap config setting) does not exist,

3) when creating a swap partition (of type 82): swap is not active and/or not mounted (and swap file creation therefore fails)

Note the use of partitions is not desirable for swap purposes, the sole intent was to test for the causes of failure.

Finally, some additional documentation for creating swap space with cloud-config would be (very) desirable).

Kind regards....

Revision history for this message
Scott Moser (smoser) wrote :

Hi,
  what version of cloud-init are you using?
  This functionality is only availble in trunk since 2014-10-01. It is only in Ubuntu vivid and utopic, not in trusty.

That said, I just launched an instance with this config:
#cloud-config
swap:
 size: auto
 filename: /swap.img
 maxsize: 8G

/var/log/cloud-init.log says:
Jan 15 15:33:18 vivid-20150115-153256 [CLOUDINIT] cc_mounts.py[DEBUG]: suggest 8182 MB swap for 7984 MB memory with '9092 MB' disk given max=8192 MB [max=8182 MB]'
Jan 15 15:33:32 vivid-20150115-153256 [CLOUDINIT] util.py[DEBUG]: creating swap file '/swap.img' of 8182MB took 14.301 seconds

$ ls -lh /swap.img ; du /swap.img
-rw------- 1 root root 8.0G Jan 15 15:33 /swap.img
8378372 /swap.img

$ free
             total used free shared buffers cached
Mem: 8176028 8009932 166096 308 9280 7680480
-/+ buffers/cache: 320172 7855856
Swap: 8378364 0 8378364

Launching another instance without the specified 'max' gives me:
Jan 15 15:44:41 vivid-20150115-154415 [CLOUDINIT] cc_mounts.py[DEBUG]: suggest 2273 MB swap for 7984 MB memory with '9092 MB' disk given max=None [max=2273 MB]'

The algorithm for 'auto' is agreeably nebulus, but I feel that any algoritm is going to seem odd/broken for some set.

Revision history for this message
trialotto (trialotto) wrote :

@Scott,

The output info is not that detailed, I get something like

Jan 16 01:23:12 swap1 [CLOUDINIT] util.py[DEBUG]: Cloud-init v. 0.7.5 finished at Fri.....

when creating a Linux VM on Azure, with Ubuntu 14.04.1 LTS.

The cc_mounts.py does certainly not include the new code for the swap file.

I have no (simple) option to launch a Trusty with a new version of cloud-init.

A simple Utopic (14.10) launch is indeed creating a persistent swap, rather stating the obvious.

Can you make this package (version 0.7.6) available for 14.04.1 LTS (Trusty)? That would be much appreciated.

Furthermore, any documentation would be much appreciated.

Note that I will post some other comments (or bugs, if any) in this topic, since I am testing some alternative scenarios.....

Revision history for this message
trialotto (trialotto) wrote :

@Scott,

At the moment, the dd command is being used in version 0.7.6 of cloud-init, with a noticeable impact on provisioning speed.

Is it possible to use the fallocate command?

This would also be convenient for resizing swap space, for instance by using fallocate -o option.

Kind regards....

PS The impact on provisioning speed can be the result of Azure, since Azure seems to be have some performance issues at this time.

Revision history for this message
trialotto (trialotto) wrote :

@Scott,

By the way, the release 0.7.6 is ready for packaging, if I am not mistaken.

Note that the package above AND the 0.7.7 version can be used in Azure Linux VMs with Ubuntu 14.04.1 LTS (Trusty).

Performance seems to be improving on the Trusty machines, if using the latest packages.

Also note that upgrading the package in a running VM (Trusty) with CustomData containing a fixed swap size, will result in a swap with that fixed size after a shut-down and start sequence (even if a previous version, such as 0.7.5, did not create swap at all).

The above should imply that on Azure, the custom data option and/or a datasource can be used to fix swap size at start or restart.

An advantage thereof is that the implementation of a swap size of zero or another minimum amount, with the possibility to grow the swap size automatically, in specific circumstances.

These circumstances could or should be:

- changing the VM size (is probably tackled by the cloud-init versions 0.7.6 and 0.7.7)
- changing swap size manually (in a running VM)
- changing swap size in waagent.conf (if relevant and/or desired)

Kind regards......

PS Please introduce the 0.7.6 in Trusty, that would be a partion solution to many problems encountered for users of Trusty VMs.

Revision history for this message
Scott Moser (smoser) wrote :

Hi,
I'm sorry, but there is not likely to be an update to 14.04 to newer versions of cloud-init.
Updates to stable releases follow the ubuntu Stable Release Updates policy, and such large changes are not being done for 12.04 (https://wiki.ubuntu.com/StableReleaseUpdates).

I'm going to mark this as fix-released as it is functional on 16.04 and later.

Changed in cloud-init (Ubuntu):
status: New → Fix Released
Revision history for this message
trialotto (trialotto) wrote :

@Scott,

This really is not an issue anymore.

The whole issue occurred in "old" Azure environments and has not been re-occurring for a while now.

Nevertheless, thanks for the response.

Regards..........

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.