File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -85,6 +85,9 @@ pub struct ExecutableSpec {
8585 /// Requires `no_new_privs = true`.
8686 #[ serde( default ) ]
8787 pub seccomp : Option < SeccompFilter > ,
88+
89+ /// An optional out-of-memory score adjustment value.
90+ pub oom_score_adj : Option < i32 > ,
8891}
8992
9093#[ derive( Default , Debug , Serialize , Deserialize ) ]
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ impl AttachRequestBuilder {
9797 self
9898 }
9999
100+ pub fn set_oom_score_adj ( mut self , score : i32 ) -> AttachRequestBuilder {
101+ self . config . exec . oom_score_adj = Some ( score) ;
102+ self
103+ }
104+
100105 pub fn push_namespace ( mut self , ns : Namespace ) -> AttachRequestBuilder {
101106 if self . config . namespaces . is_none ( ) {
102107 self . config . namespaces = vec ! [ ] . into ( ) ;
@@ -211,6 +216,11 @@ impl CreateRequestBuilder {
211216 self
212217 }
213218
219+ pub fn set_oom_score_adj ( mut self , score : i32 ) -> CreateRequestBuilder {
220+ self . config . exec . oom_score_adj = Some ( score) ;
221+ self
222+ }
223+
214224 pub fn set_hostname ( mut self , hostname : & str ) -> CreateRequestBuilder {
215225 self . config . hostname = hostname. to_string ( ) . into ( ) ;
216226 self
Original file line number Diff line number Diff line change @@ -639,6 +639,11 @@ impl Wrappable for CreateRequest {
639639
640640 debug ! ( "mount tree finalized, doing final prep" ) ;
641641
642+ // Ensure the process receives the desired out-of-memory score adjustment.
643+ if let Some ( score) = self . exec . oom_score_adj {
644+ fs:: write ( "/proc/self/oom_score_adj" , score. to_string ( ) ) ?;
645+ }
646+
642647 // We need to toggle SECBIT before we change UID/GID,
643648 // or else changing UID/GID may cause us to lose the capabilities
644649 // we need to explicitly drop capabilities later on.
@@ -841,6 +846,11 @@ impl Wrappable for AttachRequest {
841846
842847 apply_capabilities ( self . capabilities . as_ref ( ) ) ?;
843848
849+ // Ensure the process receives the desired out-of-memory score adjustment.
850+ if let Some ( score) = self . exec . oom_score_adj {
851+ fs:: write ( "/proc/self/oom_score_adj" , score. to_string ( ) ) ?;
852+ }
853+
844854 debug ! ( "all namespaces joined -- forking child" ) ;
845855 fork_and_wait ( ) ?;
846856
You can’t perform that action at this time.
0 commit comments