@@ -71,22 +71,22 @@ func EnableKernelMemoryAccounting(path string) error {
7171 // until a limit is set on the cgroup and limit cannot be set once the
7272 // cgroup has children, or if there are already tasks in the cgroup.
7373 for _ , i := range []int64 {1 , - 1 } {
74- if err := setKernelMemory (path , i ); err != nil {
74+ if err := setKernelMemory (path , uint64 ( i ) ); err != nil {
7575 return err
7676 }
7777 }
7878 return nil
7979}
8080
81- func setKernelMemory (path string , kernelMemoryLimit int64 ) error {
81+ func setKernelMemory (path string , kernelMemoryLimit uint64 ) error {
8282 if path == "" {
8383 return fmt .Errorf ("no such directory for %s" , cgroupKernelMemoryLimit )
8484 }
8585 if ! cgroups .PathExists (filepath .Join (path , cgroupKernelMemoryLimit )) {
8686 // kernel memory is not enabled on the system so we should do nothing
8787 return nil
8888 }
89- if err := ioutil .WriteFile (filepath .Join (path , cgroupKernelMemoryLimit ), []byte (strconv .FormatInt (kernelMemoryLimit , 10 )), 0700 ); err != nil {
89+ if err := ioutil .WriteFile (filepath .Join (path , cgroupKernelMemoryLimit ), []byte (strconv .FormatUint (kernelMemoryLimit , 10 )), 0700 ); err != nil {
9090 // Check if the error number returned by the syscall is "EBUSY"
9191 // The EBUSY signal is returned on attempts to write to the
9292 // memory.kmem.limit_in_bytes file if the cgroup has children or
@@ -104,12 +104,14 @@ func setKernelMemory(path string, kernelMemoryLimit int64) error {
104104}
105105
106106func setMemoryAndSwap (path string , cgroup * configs.Cgroup ) error {
107- // If the memory update is set to -1 we should also set swap to -1
108- // -1 means unlimited memory
109- if cgroup .Resources .Memory == - 1 {
107+ ulimited := - 1
108+
109+ // If the memory update is set to uint64(-1) we should also
110+ // set swap to uint64(-1), it means unlimited memory.
111+ if cgroup .Resources .Memory == uint64 (ulimited ) {
110112 // Only set swap if it's enbled in kernel
111113 if cgroups .PathExists (filepath .Join (path , cgroupMemorySwapLimit )) {
112- cgroup .Resources .MemorySwap = - 1
114+ cgroup .Resources .MemorySwap = uint64 ( ulimited )
113115 }
114116 }
115117
@@ -124,29 +126,29 @@ func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
124126 // When update memory limit, we should adapt the write sequence
125127 // for memory and swap memory, so it won't fail because the new
126128 // value and the old value don't fit kernel's validation.
127- if cgroup .Resources .MemorySwap == - 1 || memoryUsage .Limit < uint64 ( cgroup .Resources .MemorySwap ) {
128- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
129+ if cgroup .Resources .MemorySwap == uint64 ( ulimited ) || memoryUsage .Limit < cgroup .Resources .MemorySwap {
130+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
129131 return err
130132 }
131- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
133+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
132134 return err
133135 }
134136 } else {
135- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
137+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
136138 return err
137139 }
138- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
140+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
139141 return err
140142 }
141143 }
142144 } else {
143145 if cgroup .Resources .Memory != 0 {
144- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
146+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
145147 return err
146148 }
147149 }
148150 if cgroup .Resources .MemorySwap != 0 {
149- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
151+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
150152 return err
151153 }
152154 }
@@ -167,13 +169,13 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
167169 }
168170
169171 if cgroup .Resources .MemoryReservation != 0 {
170- if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatInt (cgroup .Resources .MemoryReservation , 10 )); err != nil {
172+ if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatUint (cgroup .Resources .MemoryReservation , 10 )); err != nil {
171173 return err
172174 }
173175 }
174176
175177 if cgroup .Resources .KernelMemoryTCP != 0 {
176- if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatInt (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
178+ if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatUint (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
177179 return err
178180 }
179181 }
@@ -184,12 +186,12 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
184186 }
185187 if cgroup .Resources .MemorySwappiness == nil || int64 (* cgroup .Resources .MemorySwappiness ) == - 1 {
186188 return nil
187- } else if int64 ( * cgroup .Resources .MemorySwappiness ) >= 0 && int64 ( * cgroup . Resources . MemorySwappiness ) <= 100 {
188- if err := writeFile (path , "memory.swappiness" , strconv .FormatInt (* cgroup .Resources .MemorySwappiness , 10 )); err != nil {
189+ } else if * cgroup .Resources .MemorySwappiness <= 100 {
190+ if err := writeFile (path , "memory.swappiness" , strconv .FormatUint (* cgroup .Resources .MemorySwappiness , 10 )); err != nil {
189191 return err
190192 }
191193 } else {
192- return fmt .Errorf ("invalid value:%d. valid memory swappiness range is 0-100" , int64 ( * cgroup .Resources .MemorySwappiness ) )
194+ return fmt .Errorf ("invalid value:%d. valid memory swappiness range is 0-100" , * cgroup .Resources .MemorySwappiness )
193195 }
194196
195197 return nil
@@ -251,7 +253,7 @@ func memoryAssigned(cgroup *configs.Cgroup) bool {
251253 cgroup .Resources .KernelMemory > 0 ||
252254 cgroup .Resources .KernelMemoryTCP > 0 ||
253255 cgroup .Resources .OomKillDisable ||
254- (cgroup .Resources .MemorySwappiness != nil && * cgroup .Resources .MemorySwappiness != - 1 )
256+ (cgroup .Resources .MemorySwappiness != nil && int64 ( * cgroup .Resources .MemorySwappiness ) != - 1 )
255257}
256258
257259func getMemoryData (path , name string ) (cgroups.MemoryData , error ) {
0 commit comments