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,15 @@ 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 not specified, we do want to pro-actively set this value to the
644+ // kernel-default of zero, else the subprocess inherits the styrolite
645+ // oom score (which is typically set to a very low value).
646+ fs:: write (
647+ "/proc/self/oom_score_adj" ,
648+ self . exec . oom_score_adj . unwrap_or ( 0 ) . to_string ( ) ,
649+ ) ?;
650+
642651 // We need to toggle SECBIT before we change UID/GID,
643652 // or else changing UID/GID may cause us to lose the capabilities
644653 // we need to explicitly drop capabilities later on.
@@ -841,6 +850,10 @@ impl Wrappable for AttachRequest {
841850
842851 apply_capabilities ( self . capabilities . as_ref ( ) ) ?;
843852
853+ if let Some ( score) = self . exec . oom_score_adj {
854+ fs:: write ( "/proc/self/oom_score_adj" , score. to_string ( ) ) ?;
855+ }
856+
844857 debug ! ( "all namespaces joined -- forking child" ) ;
845858 fork_and_wait ( ) ?;
846859
You can’t perform that action at this time.
0 commit comments