了解儲存空間直接存取中的快取Understanding the cache in Storage Spaces Direct

適用於︰Windows Server 2016Applies To: Windows Server 2016

儲存空間直接存取包含內建的伺服器端快取,可將儲存效能發揮極致。Storage Spaces Direct features a built-in server-side cache to maximize storage performance. 它是大型持久的即時讀寫快取。It is a large, persistent, real-time read and write cache. 啟用儲存空間直接存取時,就會自動設定快取。The cache is configured automatically when Storage Spaces Direct is enabled. 大多數的情況下,不需要任何的手動管理。In most cases, no manual management whatsoever is required. 快取的運作方式取決於磁碟機呈現的類型。How the cache works depends on the types of drives present.

下列影片深入探討儲存空間直接存取的快取運作方式,以及其他設計考量。The following video goes into details on how caching works for Storage Spaces Direct, as well as other design considerations.

儲存空間直接存取設計考量Storage Spaces Direct design considerations
(20 分鐘)(20 minutes)

磁碟機類型及部署選項Drive types and deployment options

儲存空間直接存取目前適用於三種類型的存放裝置:Storage Spaces Direct currently works with three types of storage devices:

NVMe (非揮發性記憶體高速規格)NVMe (Non-Volatile Memory Express)
SATA/SAS SSD (固態硬碟)SATA/SAS SSD (Solid-State Drive)
HDD (硬碟)HDD (Hard Disk Drive)

有六種組合,且分為「全快閃」及「混合式」兩類。These can be combined in six ways, which we group into two categories: "all-flash" and "hybrid".

全快閃部署可能性All-flash deployment possibilities

全快閃部署的目標是將儲存效能發揮極致,且不包括旋轉硬碟 (HDD)。All-flash deployments aim to maximize storage performance and do not include rotational hard disk drives (HDD).

All-Flash-Deployment-Possibilities

混合式部署可能性Hybrid deployment possibilities

混合式部署的目標是平衡效能與容量或將容量發揮極致,且不包括旋轉硬碟 (HDD)。Hybrid deployments aim to balance performance and capacity or to maximize capacity and do include rotational hard disk drives (HDD).

混合式部署可能性

快取磁碟機為自動選取Cache drives are selected automatically

在多類型磁碟機的部署中,儲存空間直接存取會自動使用所有「最快」類型的磁碟機進行快取。In deployments with multiple types of drives, Storage Spaces Direct automatically uses all drives of the "fastest" type for caching. 其餘磁碟機則用於容量。The remaining drives are used for capacity.

哪種類型「最快」則交由下列階層決定。Which type is "fastest" is determined according to the following hierarchy.

Drive-Type-Hierarchy

例如,若有 NVMe 和 SSD,則 NVMe 會快取 SSD。For example, if you have NVMe and SSDs, the NVMe will cache for the SSDs.

如果您有 SSD 和 HDD,則 SSD 會快取 HDD。If you have SSDs and HDDs, the SSDs will cache for the HDDs.

注意

快取磁碟機不提供可用的儲存容量。Cache drives do not contribute usable storage capacity. 儲存在快取中的所有資料也會儲存在其他位置,或一旦取消暫存即另存他處。All data stored in the cache is also stored elsewhere, or will be once it de-stages. 意即部署的原始儲存容量只是容量磁碟機的總和。This means the total raw storage capacity of your deployment is the sum of your capacity drives only.

當所有的磁碟機類型相同時,不會自動設定任何快取。When all drives are of the same type, no cache is configured automatically. 您可以選擇手動設定較高耐力磁碟機快取同類型的較低耐力磁碟機,詳情請參閱手動設定一節。You have the option to manually configure higher-endurance drives to cache for lower-endurance drives of the same type – see the Manual configuration section to learn how.

提示

在全 NVMe 或全 SSD 部署中,特別是極小規模時,不「配置」任何磁碟機執行快取,可大幅提升儲存效能。In all-NVMe or all-SSD deployments, especially at very small scale, having no drives "spent" on cache can improve storage efficiency meaningfully.

快取行為會自動設定Cache behavior is set automatically

快取行為會根據要進行快取的磁碟機類型自動決定。The behavior of the cache is determined automatically based on the type(s) of drives that are being cached for. 快取固態硬碟時 (例如 NVMe 快取 SSD),只快取寫入。When caching for solid-state drives (such as NVMe caching for SSDs), only writes are cached. 快取硬碟時 (例如 SSD 快取 HDD),則會快取讀取和寫入。When caching for hard disk drives (such as SSDs caching for HDDs), both reads and writes are cached.

Cache-Read-Write-Behavior

全快閃部署的僅寫入快取Write-only caching for all-flash deployments

快取固態硬碟時 (NVMe 或 SSD),只快取寫入。When caching for solid-state drives (NVMe or SSDs), only writes are cached. 這會降低容量磁碟機損耗,因為快取會合併多次寫入和重寫,然後只在有需要時取消暫存,可降低容量磁碟機的累計流量並延長其壽命。This reduces wear on the capacity drives because many writes and re-writes can coalesce in the cache and then de-stage only as needed, reducing the cumulative traffic to the capacity drives and extending their lifetime. 因此,建議您選取較高耐力、最佳化寫入的磁碟機執行快取。For this reason, we recommend selecting higher-endurance, write-optimized drives for the cache. 容量磁碟機的寫入耐力本就較低。The capacity drives may reasonably have lower write endurance.

因為讀取不會顯著影響快閃的壽命,且因為固態硬碟普遍難覺察讀取延遲,所以不快取讀取:它們直接從容量磁碟機提供 (除非資料最近才寫入且尚未取消暫存)。Because reads do not significantly affect the lifespan of flash, and because solid-state drives universally offer low read latency, reads are not cached: they are served directly from the capacity drives (except when the data was written so recently that it has not yet been de-staged). 這可讓快取全部投入寫入,發揮最大效率。This allows the cache to be dedicated entirely to writes, maximizing its effectiveness.

這就造成快取磁碟機記錄寫入特性,如寫入延遲,而容量磁碟機記錄讀取特性。This results in write characteristics, such as write latency, being dictated by the cache drives, while read characteristics are dictated by the capacity drives. 兩者為一致、可預測且統一。Both are consistent, predictable, and uniform.

混合式部署的讀/寫快取Read/write caching for hybrid deployments

快取硬碟 (HDD) 時,會快取讀取寫入,為兩者提供快閃式延遲 (通常提升約 10 倍速度)。When caching for hard disk drives (HDDs), both reads and writes are cached, to provide flash-like latency (often ~10x better) for both. 讀取快取儲存最近和經常讀取的資料供快速存取,並可將 HDD 的隨機流量減到最低。The read cache stores recently and frequently read data for fast access and to minimize random traffic to the HDDs. (因為搜尋和旋轉延遲之故,隨機存取 HDD 發生的時間延遲和損失很可觀。) 快取寫入以吸收高載,且和以前一樣合併寫入及重寫,將容量磁碟機的累計流量降至最低。(Because of seek and rotational delays, the latency and lost time incurred by random access to an HDD is significant.) Writes are cached to absorb bursts and, as before, to coalesce writes and re-writes and minimize the cumulative traffic to the capacity drives.

儲存空間直接存取實作的演算法,可以先取消隨機化再取消暫存寫入,模擬似乎循序的磁碟 IO 模式,即使實際的工作負載 IO (如虛擬機器) 為隨機。Storage Spaces Direct implements an algorithm that de-randomizes writes before de-staging them, to emulate an IO pattern to disk that seems sequential even when the actual IO coming from the workload (such as virtual machines) is random. 這可最大化 IOPS 及 HDD 輸送量。This maximizes the IOPS and throughput to the HDDs.

三種類型磁碟機都齊全之部署的快取Caching in deployments with drives of all three types

當三種類型的磁碟機都齊全時,NVMe 磁碟機可以快取 SSD 和 HDD。When drives of all three types are present, the NVMe drives provides caching for both the SSDs and the HDDs. 此行為如前文所述:SSD 只快取寫入,HDD 則讀取和寫入都快取。The behavior is as described above: only writes are cached for the SSDs, and both reads and writes are cached for the HDDs. 快取 HDD 的負荷會平均分散到快取磁碟。The burden of caching for the HDDs is distributed evenly among the cache drives.

摘要Summary

本表摘要說明哪些磁碟機用於快取、哪些用於容量,以及各種部署可能出現的快取行為。This table summarizes which drives are used for caching, which are used for capacity, and what the caching behavior is for each deployment possibility.

部署Deployment 快取磁碟機Cache drives 容量磁碟機Capacity drives 快取行為 (預設)Cache behavior (default)
全 NVMeAll NVMe 無 (選擇性:手動設定)None (Optional: configure manually) NVMeNVMe 僅寫入 (如有設定)Write-only (if configured)
全 SSDAll SSD 無 (選擇性:手動設定)None (Optional: configure manually) SSDSSD 僅寫入 (如有設定)Write-only (if configured)
NVMe + SSDNVMe + SSD NVMeNVMe SSDSSD 唯寫Write-only
NVMe + HDDNVMe + HDD NVMeNVMe HDDHDD 讀取 + 寫入Read + Write
SSD + HDDSSD + HDD SSDSSD HDDHDD 讀取 + 寫入Read + Write
NVMe + SSD + HDDNVMe + SSD + HDD NVMeNVMe SSD + HDDSSD + HDD HDD 讀取 + 寫入、SSD 僅寫入Read + Write for HDD, Write-only for SSD

伺服器端架構Server-side architecture

快取在磁碟機層級實作:一部伺服器內的個別快取磁碟機可繫結至同伺服器內的一或多部容量磁碟機。The cache is implemented at the drive level: individual cache drives within one server are bound to one or many capacity drives within the same server.

因為快取在其餘 Windows 軟體定義的儲存堆疊之下,它沒有也不需要感知任何儲存空間或容錯等概念。Because the cache is below the rest of the Windows software-defined storage stack, it does not have nor need any awareness of concepts such as Storage Spaces or fault tolerance. 您可以把這當成建立對 Windows 而言的「混合式」(部分快閃、部分磁碟) 磁碟機。You can think of it as creating "hybrid" (part flash, part disk) drives which are then presented to Windows. 至於真正的混合式磁碟機,外部幾乎看不到經常存取的資料和原始資料在實體媒體的較快和較慢部分之間的即時移動。As with an actual hybrid drive, the real-time movement of hot and cold data between the faster and slower portions of the physical media is nearly invisible to the outside.

假設儲存空間直接存取中的復原至少要在伺服器上 (表示資料複本一律寫入不同的伺服器,每部伺服器最多一份),資料在不在快取中,從同一復原得到的協助皆為相同。Given that resiliency in Storage Spaces Direct is at least server-level (meaning data copies are always written to different servers; at most one copy per server), data in the cache benefits from the same resiliency as data not in the cache.

Cache-Server-Side-Architecture

例如,使用三向鏡像時,任何資料都會有三份複本寫入不同的伺服器,其在快取中置於該處。For example, when using three-way mirroring, three copies of any data are written to different servers, where they land in cache. 無論它們待會是否會取消暫存,這三份複本都會一直存在。Regardless of whether they are later de-staged or not, three copies will always exist.

磁碟機繫結為動態Drive bindings are dynamic

快取和容量磁碟機之間的繫結可為任何比例,從 1:1 到 1:12 甚至更多。The binding between cache and capacity drives can have any ratio, from 1:1 up to 1:12 and beyond. 只要新增或移除磁碟機就會動態調整,例如相應增加時或失敗後。It adjusts dynamically whenever drives are added or removed, such as when scaling up or after failures. 這表示您可以隨時獨立新增快取磁碟機或容量磁碟機。This means you can add cache drives or capacity drives independently, whenever you want.

Dynamic-Binding

為對稱起見,建議容量磁碟機數為快取磁碟機數的倍數。We recommend making the number of capacity drives a multiple of the number of cache drives, for symmetry. 例如,若有 4 部快取磁碟機,則 8 部容量磁碟機 (比例為 1:2) 展現的效能會比 7 或 9 部更好。For example, if you have 4 cache drives, you will experience more even performance with 8 capacity drives (1:2 ratio) than with 7 or 9.

處理快取磁碟機失敗錯誤Handling cache drive failures

當快取磁碟機失敗時,任何尚未取消暫存的本機伺服器寫入都會遺失,表示它們只存在於其他複本 (在其他伺服器中)。When a cache drive fails, any writes which have not yet been de-staged are lost to the local server, meaning they exist only on the other copies (in other servers). 如同任何其他磁碟機失敗後,儲存空間可以並會諮詢留存的複本以自動復原。Just like after any other drive failure, Storage Spaces can and does automatically recover by consulting the surviving copies.

短時間內,繫結到遺失快取磁碟機的容量磁碟機會顯示狀況不良。For a brief period, the capacity drives which were bound to the lost cache drive will appear unhealthy. 一旦快取重新繫結 (自動) 並完成資料修復 (自動),它們會繼續顯示狀況良好。Once the cache rebinding has occurred (automatic) and the data repair has completed (automatic), they will resume showing as healthy.

這就是為什麼每部伺服器至少要有兩部快取磁碟機才能保持效能的原因。This scenario is why at minimum two cache drives are required per server to preserve performance.

Handling-Failure

您便可替換快取磁碟機,就像替換任何其他磁碟機一樣。You can then replace the cache drive just like any other drive replacement.

注意

您可能需要關閉電源以安全替換附加介面卡 (AIC) 或 M.2 尺寸的 NVMe。You may need to power down to safely replace NVMe that is Add-In Card (AIC) or M.2 form factor.

與其他快取的關係Relationship to other caches

Windows 軟體定義的儲存堆疊中還有幾種無關聯的快取。There are several other unrelated caches in the Windows software-defined storage stack. 例如,儲存空間回寫式快取,以及叢集共用磁碟區 (CSV) 記憶體內部讀取快取。Examples include the Storage Spaces write-back cache and the Cluster Shared Volume (CSV) in-memory read cache.

使用儲存空間直接存取,不必修改儲存空間回寫式快取的預設行為。With Storage Spaces Direct, the Storage Spaces write-back cache should not be modified from its default behavior. 例如,New-Volume Cmdlet 不該使用 -WriteCacheSize 參數。For example, parameters such as -WriteCacheSize on the New-Volume cmdlet should not be used.

您可以選擇是否要使用 CSV 快取,由您作主。You may choose to use the CSV cache, or not – it's up to you. 儲存空間直接存取預設予以關閉,但與本主題中所有提及的新快取都不衝突。It is off by default in Storage Spaces Direct, but it does not conflict with the new cache described in this topic in any way. 在某些情況下,它可提供極佳的效能表現。In certain scenarios it can provide valuable performance gains. 如需詳細資訊,請參閱如何啟用 CSV 快取 (英文)。For more information, see How to Enable CSV Cache.

手動設定 Manual configuration

大部分的部署都不需要手動設定。For most deployments, manual configuration is not required. 如果您真的需要,請繼續閱讀後文!In case you do need it, read on!

指定快取磁碟機模型Specify cache drive model

在所有磁碟機都是同樣類型的部署中 (例如全 NVMe 或 SSD 部署) 不會設定任何快取,因為 Windows 無法自動分辨同類型磁碟機的寫入耐力等特性。In deployments where all drives are of the same type, such as all-NVMe or all-SSD deployments, no cache is configured because Windows cannot distinguish characteristics like write endurance automatically among drives of the same type.

您可以指定哪些磁碟機模型使用 Enable-ClusterS2D Cmdlet 的 -CacheDeviceModel 參數,進而使用較高耐力磁碟機快取同類型的較低耐力磁碟機。To use higher-endurance drives to cache for lower-endurance drives of the same type, you can specify which drive model to use with the -CacheDeviceModel parameter of the Enable-ClusterS2D cmdlet. 一旦啟用儲存空間直接存取,該模型的所有磁碟機都會用於快取。Once Storage Spaces Direct is enabled, all drives of that model will be used for caching.

提示

模型字串與 Get-PhysicalDisk 輸出中的內容要完全一致。Be sure to match the model string exactly as it appears in the output of Get-PhysicalDisk.

範例Example

PS C:\> Get-PhysicalDisk | Group Model -NoElement

Count Name
----- ----
    8 FABRIKAM NVME-1710
   16 CONTOSO NVME-1520

PS C:\> Enable-ClusterS2D -CacheDeviceModel "FABRIKAM NVME-1710"

您可以在 PowerShell 中執行 Get-PhysicalDisk 驗證其 Usage 屬性是否顯示 "Journal",檢查您屬意的磁碟機是否用於快取。You can verify that the drives you intended are being used for caching by running Get-PhysicalDisk in PowerShell and verifying that their Usage property says "Journal".

手動部署可能性Manual deployment possibilities

手動設定有可能啟用下列部署:Manual configuration enables the following deployment possibilities:

Exotic-Deployment-Possibilities

設定快取行為Set cache behavior

有可能覆寫快取的預設行為。It is possible to override the default behavior of the cache. 例如,即使在全快間部署中仍可將它設為快取讀取。For example, you can set it to cache reads even in an all-flash deployment. 除非您確定預設不適合您的工作負載,否則不鼓勵修改行為。We discourage modifying the behavior unless you are certain the default does not suit your workload.

若要覆寫行為,請使用 Set-ClusterS2D Cmdlet 及其 -CacheModeSSD-CacheModeHDD 參數。To override the behavior, use Set-ClusterS2D cmdlet and its -CacheModeSSD and -CacheModeHDD parameters. CacheModeSSD 參數設定快取固態硬碟時的快取行為。The CacheModeSSD parameter sets the cache behavior when caching for solid-state drives. CacheModeHDD 參數設定快取硬碟時的快取行為。The CacheModeHDD parameter sets cache behavior when caching for hard disk drives. 啟用儲存空間直接存取後隨時可執行此作業。This can be done at any time after Storage Spaces Direct is enabled.

您可使用 Get-ClusterS2D 驗證行為是否已設定。You can use Get-ClusterS2D to verify the behavior is set.

範例Example

PS C:\> Get-ClusterS2D

CacheModeHDD : ReadWrite
CacheModeSSD : WriteOnly
...

PS C:\> Set-ClusterS2D -CacheModeSSD ReadWrite

PS C:\> Get-ClusterS2D

CacheModeHDD : ReadWrite
CacheModeSSD : ReadWrite
...

調整快取大小Sizing the cache

快取的大小應設為能容納您應用程式及工作負載的工作組 (任何時間正在讀取及寫入的資料)。The cache should be sized to accommodate the working set (the data being actively read or written at any given time) of your applications and workloads.

這在硬碟混合式部署中尤其重要。This is especially important in hybrid deployments with hard disk drives. 如果使用中的工作組超過快取大小,或者使用中的工作組漂移太快,讀取快取遺漏會增加,而寫入需要更頻繁地取消暫存,破壞整體效能。If the active working set exceeds the size of the cache, or if the active working set drifts too quickly, read cache misses will increase and writes will need to be de-staged more aggressively, hurting overall performance.

您可以使用 Windows 的內建效能監視器 (PerfMon.exe) 公用程式檢查快取遺漏的比例。You can use the built-in Performance Monitor (PerfMon.exe) utility in Windows to inspect the rate of cache misses. 特別是,您可以將 [叢集儲存混合式磁碟] 計數器集合的 [快取遺漏讀取數/秒] 與您所部署的整體讀取 IOPS 進行比較。Specifically, you can compare the Cache Miss Reads/sec from the Cluster Storage Hybrid Disk counter set to the overall read IOPS of your deployment. 每個「混合式磁碟」都對應一部容量磁碟機。Each "Hybrid Disk" corresponds to one capacity drive.

例如,2 部快取磁碟機繫結至 4 部容量磁碟機,造成每部伺服器有 4 個「混合式磁碟」物件執行個體。For example, 2 cache drives bound to 4 capacity drives results in 4 "Hybrid Disk" object instances per server.

Performance-Monitor

規則並無標準,但若讀取有太多快取遺漏,就需要縮減,而您應該考慮增加快取磁碟機擴張快取。There is no universal rule, but if too many reads are missing the cache, it may be undersized and you should consider adding cache drives to expand your cache. 您可以隨時獨立新增快取磁碟機或容量磁碟機。You can add cache drives or capacity drives independently whenever you want.

另請參閱See also