How to set a D3cold state flag for NVMe with a udev rule in Ubuntu 22.04

To set a D3cold state flag for NVMe with a udev rule in Ubuntu 22.04, you can follow the steps below:

Identify the NVMe device you want to apply the D3cold state flag to by running the following command in the terminal:

ls /sys/class/nvme/

This will list all the NVMe devices present in the system.

Once you have identified the NVMe device, create a new udev rule to apply the D3cold state flag. You can do this by creating a new file in the /etc/udev/rules.d/ directory with a .rules extension. For example, you can create a file named nvme-d3cold.rules by running the following command:

sudo nano /etc/udev/rules.d/nvme-d3cold.rules

In the new file, add the following rule:

# Set D3cold state flag for NVMe device
SUBSYSTEM=="nvme", KERNEL=="nvmeX", ATTR{power/control}="auto"

Replace nvmeX with the name of the NVMe device you identified in step 1.

The ATTR{power/control}=“auto” attribute sets the power management policy to “auto”, which enables the kernel to select the optimal power management policy for the device.

Save and close the file.

Reload the udev rules by running the following command in the terminal:

sudo udevadm control --reload-rules

This will apply the new udev rule and set the D3cold state flag for the specified NVMe device.

Note: The D3cold state flag may not be supported by all NVMe devices. Make sure to check the specifications of your NVMe device before applying the udev rule.

Explanation regarding D3cold

D3 Cold is a power state in the NVMe (Non-Volatile Memory Express) specification that is designed to reduce the power consumption of NVMe devices when they are not in use. When an NVMe device enters the D3 Cold state, it is put into a deep sleep mode where its power consumption is reduced to near-zero.

The D3 Cold state is a very deep sleep state that requires some time for the device to wake up and become operational again. During this time, the device will consume more power as it initializes and becomes ready for use. However, the power savings from being in the D3 Cold state for extended periods can outweigh the time and power required to wake up from this state.

The D3 Cold state can be enabled by setting the power/control attribute to “auto” in the udev rule for the NVMe device, as described in my previous answer. When the kernel decides that the device is idle, it can transition it into the D3 Cold state to save power.