Skip to content

Commit ee7aad2

Browse files
authored
Updates and fixes for Azure.VM.DiskCaching #3673 (#3725)
1 parent f0d80b1 commit ee7aad2

8 files changed

Lines changed: 208 additions & 82 deletions

File tree

docs/changelog.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ What's changed since v1.47.0:
5151
- Azure Kubernetes Service:
5252
- Updated `Azure.AKS.Version` to use `1.33.7` as the minimum version by @BernieWhite.
5353
[#3708](https://github.com/Azure/PSRule.Rules.Azure/issues/3708)
54-
- Improved documentation for expansion internals with a high-level flow diagram and code references by @BernieWhite.
55-
[#3715](https://github.com/Azure/PSRule.Rules.Azure/issues/3715)
54+
- Virtual Machine:
55+
- Updated `Azure.VM.DiskCaching` to check for `ReadWrite` caching on OS disks instead only by @BernieWhite.
56+
[#3673](https://github.com/Azure/PSRule.Rules.Azure/issues/3673)
57+
- Renamed the rule from `Azure.VM.DiskCaching` to `Azure.VM.OSDiskCache` to reflect updated scope.
58+
- Updates to provide more complete documentation.
59+
- Engineering
60+
- Improved documentation for expansion internals with a high-level flow diagram and code references by @BernieWhite.
61+
[#3715](https://github.com/Azure/PSRule.Rules.Azure/issues/3715)
5662

5763
## v1.47.0
5864

docs/en/rules/Azure.VM.DiskCaching.md

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
reviewed: 2026-03-25
3+
severity: Important
4+
pillar: Performance Efficiency
5+
category: PE:08 Data performance
6+
resource: Virtual Machine
7+
resourceType: Microsoft.Compute/virtualMachines
8+
online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.VM.OSDiskCache/
9+
ms-content-id: d28da16e-4639-466f-95e5-4ab6bf61aec7
10+
---
11+
12+
# Virtual Machine OS disk read write caching is not enabled
13+
14+
## SYNOPSIS
15+
16+
Operating system (OS) disk read/ write caching can improve virtual machines (VMs) performance.
17+
18+
## DESCRIPTION
19+
20+
Azure Virtual Machines (VMs) support caching for OS disks to improve performance.
21+
The caching mode can be set to `ReadOnly`, `ReadWrite`, or `None`.
22+
By default, the OS disks have `ReadWrite` caching enabled.
23+
24+
The appropriate caching mode depends on the specific workload configuration and performance requirements.
25+
For most workloads `ReadWrite` caching provides improved performance and acceptable integrity of operating system files.
26+
This is because operating system files and processes typically infrequently change and support flushing writes during changes.
27+
28+
In cases where workload data files are stored on the OS disk, `ReadWrite` caching may be inappropriate.
29+
When designing high performance workloads, separate workload data files from the OS disk and use data disks.
30+
31+
## RECOMMENDATION
32+
33+
Consider enabling `ReadWrite` caching for OS disks to improve OS storage performance.
34+
35+
## EXAMPLES
36+
37+
### Configure with Bicep
38+
39+
To deploy VMs that pass this rule:
40+
41+
- Set the `properties.storageProfile.osDisk.caching` property to `ReadWrite`.
42+
43+
For example:
44+
45+
```bicep
46+
resource linux 'Microsoft.Compute/virtualMachines@2025-04-01' = {
47+
name: name
48+
location: location
49+
identity: {
50+
type: 'SystemAssigned'
51+
}
52+
properties: {
53+
hardwareProfile: {
54+
vmSize: 'Standard_D8ds_v6'
55+
}
56+
osProfile: {
57+
computerName: name
58+
adminUsername: adminUsername
59+
linuxConfiguration: {
60+
provisionVMAgent: true
61+
disablePasswordAuthentication: true
62+
}
63+
}
64+
storageProfile: {
65+
imageReference: {
66+
publisher: 'MicrosoftCblMariner'
67+
offer: 'azure-linux-3'
68+
sku: 'azure-linux-3-gen2'
69+
version: 'latest'
70+
}
71+
osDisk: {
72+
name: '${name}-disk0'
73+
caching: 'ReadWrite'
74+
createOption: 'FromImage'
75+
managedDisk: {
76+
storageAccountType: 'Premium_LRS'
77+
}
78+
}
79+
}
80+
networkProfile: {
81+
networkInterfaces: [
82+
{
83+
id: nic.id
84+
}
85+
]
86+
}
87+
}
88+
zones: [
89+
'1'
90+
]
91+
}
92+
```
93+
94+
### Configure with Azure template
95+
96+
To deploy VMs that pass this rule:
97+
98+
- Set the `properties.storageProfile.osDisk.caching` property to `ReadWrite`.
99+
100+
For example:
101+
102+
```json
103+
{
104+
"type": "Microsoft.Compute/virtualMachines",
105+
"apiVersion": "2025-04-01",
106+
"name": "[parameters('name')]",
107+
"location": "[parameters('location')]",
108+
"identity": {
109+
"type": "SystemAssigned"
110+
},
111+
"properties": {
112+
"hardwareProfile": {
113+
"vmSize": "Standard_D8ds_v6"
114+
},
115+
"osProfile": {
116+
"computerName": "[parameters('name')]",
117+
"adminUsername": "[parameters('adminUsername')]",
118+
"linuxConfiguration": {
119+
"provisionVMAgent": true,
120+
"disablePasswordAuthentication": true
121+
}
122+
},
123+
"storageProfile": {
124+
"imageReference": {
125+
"publisher": "MicrosoftCblMariner",
126+
"offer": "azure-linux-3",
127+
"sku": "azure-linux-3-gen2",
128+
"version": "latest"
129+
},
130+
"osDisk": {
131+
"name": "[format('{0}-disk0', parameters('name'))]",
132+
"caching": "ReadWrite",
133+
"createOption": "FromImage",
134+
"managedDisk": {
135+
"storageAccountType": "Premium_LRS"
136+
}
137+
}
138+
},
139+
"networkProfile": {
140+
"networkInterfaces": [
141+
{
142+
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
143+
}
144+
]
145+
}
146+
},
147+
"zones": [
148+
"1"
149+
],
150+
"dependsOn": [
151+
"[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
152+
]
153+
}
154+
```
155+
156+
## LINKS
157+
158+
- [PE:08 Data performance](https://learn.microsoft.com/azure/well-architected/performance-efficiency/optimize-data-performance)
159+
- [Design for high performance](https://learn.microsoft.com/azure/virtual-machines/premium-storage-performance#disk-caching)
160+
- [Virtual machine and disk performance](https://learn.microsoft.com/azure/virtual-machines/disks-performance)
161+
- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.compute/virtualmachines)

docs/examples/resources/vm.bicep

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ param subnetId string
2929
param amaIdentityId string
3030

3131
// An example virtual machine running Windows Server and one data disk attached.
32-
resource vm 'Microsoft.Compute/virtualMachines@2024-11-01' = {
32+
resource vm 'Microsoft.Compute/virtualMachines@2025-04-01' = {
3333
name: name
3434
location: location
3535
identity: {
@@ -94,7 +94,7 @@ resource vm 'Microsoft.Compute/virtualMachines@2024-11-01' = {
9494
}
9595

9696
// An example of a VM managed disk.
97-
resource dataDisk 'Microsoft.Compute/disks@2023-10-02' = {
97+
resource dataDisk 'Microsoft.Compute/disks@2025-01-02' = {
9898
name: name
9999
location: location
100100
sku: {
@@ -109,7 +109,7 @@ resource dataDisk 'Microsoft.Compute/disks@2023-10-02' = {
109109
}
110110

111111
// An example of configuring a VM extension for the Azure Monitor Agent.
112-
resource windowsAgent 'Microsoft.Compute/virtualMachines/extensions@2024-03-01' = {
112+
resource windowsAgent 'Microsoft.Compute/virtualMachines/extensions@2025-04-01' = {
113113
parent: vm
114114
name: 'AzureMonitorWindowsAgent'
115115
location: location
@@ -156,7 +156,7 @@ resource config 'Microsoft.Maintenance/configurationAssignments@2023-04-01' = {
156156
}
157157

158158
// An example virtual machine with Azure Hybrid Benefit.
159-
resource vm_with_benefit 'Microsoft.Compute/virtualMachines@2024-07-01' = {
159+
resource vm_with_benefit 'Microsoft.Compute/virtualMachines@2025-04-01' = {
160160
name: name
161161
location: location
162162
zones: [
@@ -204,7 +204,7 @@ resource vm_with_benefit 'Microsoft.Compute/virtualMachines@2024-07-01' = {
204204
param nicName string
205205

206206
// An example network interface
207-
resource nic 'Microsoft.Network/networkInterfaces@2023-06-01' = {
207+
resource nic 'Microsoft.Network/networkInterfaces@2025-05-01' = {
208208
name: nicName
209209
location: location
210210
properties: {
@@ -223,15 +223,15 @@ resource nic 'Microsoft.Network/networkInterfaces@2023-06-01' = {
223223
}
224224

225225
// An example virtual machine running Azure Linux.
226-
resource linux 'Microsoft.Compute/virtualMachines@2024-03-01' = {
226+
resource linux 'Microsoft.Compute/virtualMachines@2025-04-01' = {
227227
name: name
228228
location: location
229229
identity: {
230230
type: 'SystemAssigned'
231231
}
232232
properties: {
233233
hardwareProfile: {
234-
vmSize: 'Standard_D8d_v5'
234+
vmSize: 'Standard_D8ds_v6'
235235
}
236236
osProfile: {
237237
computerName: name
@@ -244,8 +244,8 @@ resource linux 'Microsoft.Compute/virtualMachines@2024-03-01' = {
244244
storageProfile: {
245245
imageReference: {
246246
publisher: 'MicrosoftCblMariner'
247-
offer: 'Cbl-Mariner'
248-
sku: 'cbl-mariner-2-gen2'
247+
offer: 'azure-linux-3'
248+
sku: 'azure-linux-3-gen2'
249249
version: 'latest'
250250
}
251251
osDisk: {

docs/examples/resources/vm.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"metadata": {
55
"_generator": {
66
"name": "bicep",
7-
"version": "0.34.44.8038",
8-
"templateHash": "18140604143517495412"
7+
"version": "0.41.2.15936",
8+
"templateHash": "12918842436261158023"
99
}
1010
},
1111
"parameters": {
1212
"name": {
1313
"type": "string",
14+
"minLength": 1,
15+
"maxLength": 15,
1416
"metadata": {
1517
"description": "The name of the resource."
1618
}
@@ -64,7 +66,7 @@
6466
"resources": [
6567
{
6668
"type": "Microsoft.Compute/virtualMachines",
67-
"apiVersion": "2024-11-01",
69+
"apiVersion": "2025-04-01",
6870
"name": "[parameters('name')]",
6971
"location": "[parameters('location')]",
7072
"identity": {
@@ -133,7 +135,7 @@
133135
},
134136
{
135137
"type": "Microsoft.Compute/disks",
136-
"apiVersion": "2023-10-02",
138+
"apiVersion": "2025-01-02",
137139
"name": "[parameters('name')]",
138140
"location": "[parameters('location')]",
139141
"sku": {
@@ -148,7 +150,7 @@
148150
},
149151
{
150152
"type": "Microsoft.Compute/virtualMachines/extensions",
151-
"apiVersion": "2024-03-01",
153+
"apiVersion": "2025-04-01",
152154
"name": "[format('{0}/{1}', parameters('name'), 'AzureMonitorWindowsAgent')]",
153155
"location": "[parameters('location')]",
154156
"properties": {
@@ -188,7 +190,7 @@
188190
{
189191
"type": "Microsoft.Maintenance/configurationAssignments",
190192
"apiVersion": "2023-04-01",
191-
"scope": "[format('Microsoft.Compute/virtualMachines/{0}', parameters('name'))]",
193+
"scope": "[resourceId('Microsoft.Compute/virtualMachines', parameters('name'))]",
192194
"name": "[parameters('name')]",
193195
"location": "[parameters('location')]",
194196
"properties": {
@@ -201,7 +203,7 @@
201203
},
202204
{
203205
"type": "Microsoft.Compute/virtualMachines",
204-
"apiVersion": "2024-07-01",
206+
"apiVersion": "2025-04-01",
205207
"name": "[parameters('name')]",
206208
"location": "[parameters('location')]",
207209
"zones": [
@@ -247,7 +249,7 @@
247249
},
248250
{
249251
"type": "Microsoft.Network/networkInterfaces",
250-
"apiVersion": "2023-06-01",
252+
"apiVersion": "2025-05-01",
251253
"name": "[parameters('nicName')]",
252254
"location": "[parameters('location')]",
253255
"properties": {
@@ -266,15 +268,15 @@
266268
},
267269
{
268270
"type": "Microsoft.Compute/virtualMachines",
269-
"apiVersion": "2024-03-01",
271+
"apiVersion": "2025-04-01",
270272
"name": "[parameters('name')]",
271273
"location": "[parameters('location')]",
272274
"identity": {
273275
"type": "SystemAssigned"
274276
},
275277
"properties": {
276278
"hardwareProfile": {
277-
"vmSize": "Standard_D8d_v5"
279+
"vmSize": "Standard_D8ds_v6"
278280
},
279281
"osProfile": {
280282
"computerName": "[parameters('name')]",
@@ -287,8 +289,8 @@
287289
"storageProfile": {
288290
"imageReference": {
289291
"publisher": "MicrosoftCblMariner",
290-
"offer": "Cbl-Mariner",
291-
"sku": "cbl-mariner-2-gen2",
292+
"offer": "azure-linux-3",
293+
"sku": "azure-linux-3-gen2",
292294
"version": "latest"
293295
},
294296
"osDisk": {

0 commit comments

Comments
 (0)