@@ -73,22 +73,22 @@ func EnableKernelMemoryAccounting(path string) error {
7373 // until a limit is set on the cgroup and limit cannot be set once the
7474 // cgroup has children, or if there are already tasks in the cgroup.
7575 for _ , i := range []int64 {1 , - 1 } {
76- if err := setKernelMemory (path , uint64 ( i ) ); err != nil {
76+ if err := setKernelMemory (path , i ); err != nil {
7777 return err
7878 }
7979 }
8080 return nil
8181}
8282
83- func setKernelMemory (path string , kernelMemoryLimit uint64 ) error {
83+ func setKernelMemory (path string , kernelMemoryLimit int64 ) error {
8484 if path == "" {
8585 return fmt .Errorf ("no such directory for %s" , cgroupKernelMemoryLimit )
8686 }
8787 if ! cgroups .PathExists (filepath .Join (path , cgroupKernelMemoryLimit )) {
8888 // kernel memory is not enabled on the system so we should do nothing
8989 return nil
9090 }
91- if err := ioutil .WriteFile (filepath .Join (path , cgroupKernelMemoryLimit ), []byte (strconv .FormatUint (kernelMemoryLimit , 10 )), 0700 ); err != nil {
91+ if err := ioutil .WriteFile (filepath .Join (path , cgroupKernelMemoryLimit ), []byte (strconv .FormatInt (kernelMemoryLimit , 10 )), 0700 ); err != nil {
9292 // Check if the error number returned by the syscall is "EBUSY"
9393 // The EBUSY signal is returned on attempts to write to the
9494 // memory.kmem.limit_in_bytes file if the cgroup has children or
@@ -106,14 +106,12 @@ func setKernelMemory(path string, kernelMemoryLimit uint64) error {
106106}
107107
108108func setMemoryAndSwap (path string , cgroup * configs.Cgroup ) error {
109- ulimited := - 1
110-
111- // If the memory update is set to uint64(-1) we should also
112- // set swap to uint64(-1), it means unlimited memory.
113- if cgroup .Resources .Memory == uint64 (ulimited ) {
114- // Only set swap if it's enbled in kernel
109+ // If the memory update is set to -1 we should also
110+ // set swap to -1, it means unlimited memory.
111+ if cgroup .Resources .Memory == - 1 {
112+ // Only set swap if it's enabled in kernel
115113 if cgroups .PathExists (filepath .Join (path , cgroupMemorySwapLimit )) {
116- cgroup .Resources .MemorySwap = uint64 ( ulimited )
114+ cgroup .Resources .MemorySwap = - 1
117115 }
118116 }
119117
@@ -128,29 +126,29 @@ func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
128126 // When update memory limit, we should adapt the write sequence
129127 // for memory and swap memory, so it won't fail because the new
130128 // value and the old value don't fit kernel's validation.
131- if cgroup .Resources .MemorySwap == uint64 ( ulimited ) || memoryUsage .Limit < cgroup .Resources .MemorySwap {
132- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
129+ if cgroup .Resources .MemorySwap == - 1 || memoryUsage .Limit < uint64 ( cgroup .Resources .MemorySwap ) {
130+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
133131 return err
134132 }
135- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
133+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
136134 return err
137135 }
138136 } else {
139- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
137+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
140138 return err
141139 }
142- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
140+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
143141 return err
144142 }
145143 }
146144 } else {
147145 if cgroup .Resources .Memory != 0 {
148- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
146+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
149147 return err
150148 }
151149 }
152150 if cgroup .Resources .MemorySwap != 0 {
153- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
151+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
154152 return err
155153 }
156154 }
@@ -171,13 +169,13 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
171169 }
172170
173171 if cgroup .Resources .MemoryReservation != 0 {
174- if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatUint (cgroup .Resources .MemoryReservation , 10 )); err != nil {
172+ if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatInt (cgroup .Resources .MemoryReservation , 10 )); err != nil {
175173 return err
176174 }
177175 }
178176
179177 if cgroup .Resources .KernelMemoryTCP != 0 {
180- if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatUint (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
178+ if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatInt (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
181179 return err
182180 }
183181 }
0 commit comments