@@ -3,7 +3,6 @@ package cgroups
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
- "io/ioutil"
7
6
"os"
8
7
"path/filepath"
9
8
"runtime"
@@ -22,7 +21,7 @@ func createKokerGroup() error {
22
21
}
23
22
24
23
// Enable controllers
25
- return ioutil .WriteFile (filepath .Join (kokerCGroup , "cgroup.subtree_control" ),
24
+ return os .WriteFile (filepath .Join (kokerCGroup , "cgroup.subtree_control" ),
26
25
[]byte ("+cpu +memory +pids" ), 0644 )
27
26
}
28
27
@@ -42,12 +41,12 @@ func newCGroupsv2(path string) (cgroupsv2, error) {
42
41
func (cg cgroupsv2 ) SetMemSwpLimit (memory , swap int ) error {
43
42
if memory > 0 {
44
43
memFile := filepath .Join (cg .dir , "memory.max" )
45
- if err := ioutil .WriteFile (memFile , []byte (strconv .Itoa (memory * 1024 * 1024 )), 0644 ); err != nil {
44
+ if err := os .WriteFile (memFile , []byte (strconv .Itoa (memory * 1024 * 1024 )), 0644 ); err != nil {
46
45
return err
47
46
}
48
47
if swap > 0 {
49
48
memswFile := filepath .Join (cg .dir , "memory.swap.max" )
50
- if err := ioutil .WriteFile (memswFile , []byte (strconv .Itoa ((memory + swap )* 1024 * 1024 )), 0644 ); err != nil {
49
+ if err := os .WriteFile (memswFile , []byte (strconv .Itoa ((memory + swap )* 1024 * 1024 )), 0644 ); err != nil {
51
50
return err
52
51
}
53
52
}
@@ -60,7 +59,7 @@ func (cg cgroupsv2) SetMemSwpLimit(memory, swap int) error {
60
59
func (cg cgroupsv2 ) SetPidsLimit (pids int ) error {
61
60
if pids > 0 {
62
61
pidsFile := filepath .Join (cg .dir , "pids.max" )
63
- if err := ioutil .WriteFile (pidsFile , []byte (strconv .Itoa (pids )), 0644 ); err != nil {
62
+ if err := os .WriteFile (pidsFile , []byte (strconv .Itoa (pids )), 0644 ); err != nil {
64
63
return err
65
64
}
66
65
}
@@ -73,7 +72,7 @@ func (cg cgroupsv2) SetCPULimit(cpus float64) error {
73
72
cpuFile := filepath .Join (cg .dir , "cpu.max" )
74
73
cpuVal := fmt .Sprintf ("%d%d" , int (cpus * constants .DefaultCfsPeriod ),
75
74
constants .DefaultCfsPeriod )
76
- if err := ioutil .WriteFile (cpuFile , []byte (cpuVal ), 0644 ); err != nil {
75
+ if err := os .WriteFile (cpuFile , []byte (cpuVal ), 0644 ); err != nil {
77
76
return err
78
77
}
79
78
}
@@ -85,7 +84,7 @@ func (cg cgroupsv2) AddProcess() error {
85
84
// Get pid
86
85
pid := os .Getpid ()
87
86
procsFile := filepath .Join (cg .dir , "cgroup.procs" )
88
- return ioutil .WriteFile (procsFile , []byte (strconv .Itoa (pid )), 0700 )
87
+ return os .WriteFile (procsFile , []byte (strconv .Itoa (pid )), 0700 )
89
88
}
90
89
91
90
// Remove removes CGroups
0 commit comments