 634f0c0c83
			
		
	
	634f0c0c83
	
	
	
		
			
			This adds a config option to set the oom score for the containerd daemon as well as automatically setting the oom score for the shim's lauched so that they are not killed until the very end of an out of memory condition. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
		
			
				
	
	
		
			32 lines
		
	
	
		
			658 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			658 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| // +build !windows
 | |
| 
 | |
| package sys
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"os"
 | |
| 	"strconv"
 | |
| 
 | |
| 	"github.com/opencontainers/runc/libcontainer/system"
 | |
| )
 | |
| 
 | |
| // OOMScoreMaxKillable is the maximum score keeping the process killable by the oom killer
 | |
| const OOMScoreMaxKillable = -999
 | |
| 
 | |
| // SetOOMScore sets the oom score for the provided pid
 | |
| func SetOOMScore(pid, score int) error {
 | |
| 	path := fmt.Sprintf("/proc/%d/oom_score_adj", pid)
 | |
| 	f, err := os.OpenFile(path, os.O_WRONLY, 0)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 	defer f.Close()
 | |
| 	if _, err = f.WriteString(strconv.Itoa(score)); err != nil {
 | |
| 		if os.IsPermission(err) && system.RunningInUserNS() {
 | |
| 			return nil
 | |
| 		}
 | |
| 		return err
 | |
| 	}
 | |
| 	return nil
 | |
| }
 |