@@ -62,6 +62,54 @@ pub enum ServerConfig {
6262 } ,
6363}
6464
65+ #[ cfg( test) ]
66+ pub ( crate ) mod defs {
67+
68+ use serde:: Deserialize ;
69+ use serde:: Serialize ;
70+
71+ #[ derive( schemars:: JsonSchema , Serialize , Deserialize ) ]
72+ #[ serde( remote = "foyer::IopsCounter" ) ]
73+ #[ serde( deny_unknown_fields) ]
74+ #[ serde( tag = "mode" ) ]
75+ pub enum IopsCounterDef {
76+ /// Count 1 iops for each read/write.
77+ #[ serde( rename = "per_io" ) ]
78+ PerIo ,
79+ /// Count 1 iops for each read/write with the size of the i/o.
80+ #[ serde( rename = "per_io_size" ) ]
81+ PerIoSize ( std:: num:: NonZeroUsize ) ,
82+ }
83+
84+ #[ derive( schemars:: JsonSchema , Serialize , Deserialize ) ]
85+ #[ serde( remote = "foyer::Throttle" ) ]
86+ #[ serde( deny_unknown_fields) ]
87+ pub struct ThrottleDef {
88+ /// The maximum write iops for the device.
89+ pub write_iops : Option < std:: num:: NonZeroUsize > ,
90+ /// The maximum read iops for the device.
91+ pub read_iops : Option < std:: num:: NonZeroUsize > ,
92+ /// The maximum write throughput for the device.
93+ pub write_throughput : Option < std:: num:: NonZeroUsize > ,
94+ /// The maximum read throughput for the device.
95+ pub read_throughput : Option < std:: num:: NonZeroUsize > ,
96+ /// The iops counter for the device.
97+ #[ serde( with = "IopsCounterDef" ) ]
98+ pub iops_counter : foyer:: IopsCounter ,
99+ }
100+ }
101+ #[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
102+ #[ cfg_attr( test, derive( schemars:: JsonSchema ) ) ]
103+ #[ serde( deny_unknown_fields) ]
104+ #[ repr( transparent) ]
105+ pub struct DiskThrottle ( #[ cfg_attr( test, serde( with = "defs::ThrottleDef" ) ) ] foyer:: Throttle ) ;
106+
107+ impl From < DiskThrottle > for foyer:: Throttle {
108+ fn from ( value : DiskThrottle ) -> Self {
109+ value. 0
110+ }
111+ }
112+
65113#[ derive( Debug , Clone , PartialEq , Eq , Serialize , Deserialize ) ]
66114#[ cfg_attr( test, derive( schemars:: JsonSchema ) ) ]
67115#[ serde( deny_unknown_fields) ]
@@ -70,6 +118,8 @@ pub struct StorageConfig {
70118 pub data_dir : PathBuf ,
71119 pub disk_capacity : u64 ,
72120 #[ serde( skip_serializing_if = "Option::is_none" ) ]
121+ pub disk_throttle : Option < DiskThrottle > ,
122+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
73123 pub memory_capacity : Option < u64 > ,
74124}
75125
@@ -203,6 +253,7 @@ impl Default for Config {
203253 storage : StorageConfig {
204254 data_dir : default_data_dir ( ) ,
205255 disk_capacity : 512 * 1024 * 1024 ,
256+ disk_throttle : None ,
206257 memory_capacity : None ,
207258 } ,
208259 telemetry : TelemetryConfig {
@@ -299,6 +350,31 @@ pub const fn known_option_entries() -> &'static [OptionEntry] {
299350 ent_path : "storage.disk_capacity" ,
300351 ent_type : "integer" ,
301352 } ,
353+ OptionEntry {
354+ env_name : "PERCAS_CONFIG_STORAGE_DISK_THROTTLE_IOPS_COUNTER_MODE" ,
355+ ent_path : "storage.disk_throttle.iops_counter.mode" ,
356+ ent_type : "string" ,
357+ } ,
358+ OptionEntry {
359+ env_name : "PERCAS_CONFIG_STORAGE_DISK_THROTTLE_READ_IOPS" ,
360+ ent_path : "storage.disk_throttle.read_iops" ,
361+ ent_type : "integer" ,
362+ } ,
363+ OptionEntry {
364+ env_name : "PERCAS_CONFIG_STORAGE_DISK_THROTTLE_READ_THROUGHPUT" ,
365+ ent_path : "storage.disk_throttle.read_throughput" ,
366+ ent_type : "integer" ,
367+ } ,
368+ OptionEntry {
369+ env_name : "PERCAS_CONFIG_STORAGE_DISK_THROTTLE_WRITE_IOPS" ,
370+ ent_path : "storage.disk_throttle.write_iops" ,
371+ ent_type : "integer" ,
372+ } ,
373+ OptionEntry {
374+ env_name : "PERCAS_CONFIG_STORAGE_DISK_THROTTLE_WRITE_THROUGHPUT" ,
375+ ent_path : "storage.disk_throttle.write_throughput" ,
376+ ent_type : "integer" ,
377+ } ,
302378 OptionEntry {
303379 env_name : "PERCAS_CONFIG_STORAGE_MEMORY_CAPACITY" ,
304380 ent_path : "storage.memory_capacity" ,
0 commit comments