@@ -18,6 +18,7 @@ pub struct DockerService {
18
18
cancellation_token : CancellationToken ,
19
19
pub state : Arc < DockerState > ,
20
20
has_gpu : bool ,
21
+ system_memory_mb : Option < u32 > ,
21
22
task_bridge_socket_path : String ,
22
23
}
23
24
@@ -27,6 +28,7 @@ impl DockerService {
27
28
pub fn new (
28
29
cancellation_token : CancellationToken ,
29
30
has_gpu : bool ,
31
+ system_memory_mb : Option < u32 > ,
30
32
task_bridge_socket_path : String ,
31
33
storage_path : Option < String > ,
32
34
) -> Self {
@@ -36,6 +38,7 @@ impl DockerService {
36
38
cancellation_token,
37
39
state : Arc :: new ( DockerState :: new ( ) ) ,
38
40
has_gpu,
41
+ system_memory_mb,
39
42
task_bridge_socket_path,
40
43
}
41
44
}
@@ -142,6 +145,7 @@ impl DockerService {
142
145
let manager_clone = manager_clone. clone( ) ;
143
146
let state_clone = state. clone( ) ;
144
147
let has_gpu = self . has_gpu;
148
+ let system_memory_mb = self . system_memory_mb;
145
149
let task_bridge_socket_path = self . task_bridge_socket_path. clone( ) ;
146
150
let handle = tokio:: spawn( async move {
147
151
let payload = task_clone. unwrap( ) ;
@@ -170,8 +174,14 @@ impl DockerService {
170
174
false ,
171
175
)
172
176
] ;
173
-
174
- match manager_clone. start_container( & payload. image, & container_task_id, Some ( env_vars) , Some ( cmd) , has_gpu, Some ( volumes) ) . await {
177
+ let shm_size = match system_memory_mb {
178
+ Some ( mem_mb) => ( mem_mb as u64 ) * 1024 * 1024 / 2 , // Convert MB to bytes and divide by 2
179
+ None => {
180
+ Console :: warning( "System memory not available, using default shm size" ) ;
181
+ 67108864 // Default to 64MB in bytes
182
+ }
183
+ } ;
184
+ match manager_clone. start_container( & payload. image, & container_task_id, Some ( env_vars) , Some ( cmd) , has_gpu, Some ( volumes) , Some ( shm_size) ) . await {
175
185
Ok ( container_id) => {
176
186
Console :: info( "DockerService" , & format!( "Container started with id: {}" , container_id) ) ;
177
187
} ,
@@ -276,6 +286,7 @@ mod tests {
276
286
let docker_service = DockerService :: new (
277
287
cancellation_token. clone ( ) ,
278
288
false ,
289
+ Some ( 1024 ) ,
279
290
"/tmp/com.prime.miner/metrics.sock" . to_string ( ) ,
280
291
None ,
281
292
) ;
@@ -319,6 +330,7 @@ mod tests {
319
330
let docker_service = DockerService :: new (
320
331
cancellation_token. clone ( ) ,
321
332
false ,
333
+ Some ( 1024 ) ,
322
334
"/tmp/com.prime.miner/metrics.sock" . to_string ( ) ,
323
335
None ,
324
336
) ;
0 commit comments