@@ -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 , uint64 ( i ) ); err != nil {
74+ if err := setKernelMemory (path , i ); err != nil {
7575 return err
7676 }
7777 }
7878 return nil
7979}
8080
81- func setKernelMemory (path string , kernelMemoryLimit uint64 ) error {
81+ func setKernelMemory (path string , kernelMemoryLimit int64 ) 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 .FormatUint (kernelMemoryLimit , 10 )), 0700 ); err != nil {
89+ if err := ioutil .WriteFile (filepath .Join (path , cgroupKernelMemoryLimit ), []byte (strconv .FormatInt (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,14 +104,12 @@ func setKernelMemory(path string, kernelMemoryLimit uint64) error {
104104}
105105
106106func setMemoryAndSwap (path string , cgroup * configs.Cgroup ) error {
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 ) {
112- // Only set swap if it's enbled in kernel
107+ // If the memory update is set to -1 we should also
108+ // set swap to -1, it means unlimited memory.
109+ if cgroup .Resources .Memory == - 1 {
110+ // Only set swap if it's enabled in kernel
113111 if cgroups .PathExists (filepath .Join (path , cgroupMemorySwapLimit )) {
114- cgroup .Resources .MemorySwap = uint64 ( ulimited )
112+ cgroup .Resources .MemorySwap = - 1
115113 }
116114 }
117115
@@ -126,29 +124,29 @@ func setMemoryAndSwap(path string, cgroup *configs.Cgroup) error {
126124 // When update memory limit, we should adapt the write sequence
127125 // for memory and swap memory, so it won't fail because the new
128126 // value and the old value don't fit kernel's validation.
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 {
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 {
131129 return err
132130 }
133- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
131+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
134132 return err
135133 }
136134 } else {
137- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
135+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
138136 return err
139137 }
140- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
138+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
141139 return err
142140 }
143141 }
144142 } else {
145143 if cgroup .Resources .Memory != 0 {
146- if err := writeFile (path , cgroupMemoryLimit , strconv .FormatUint (cgroup .Resources .Memory , 10 )); err != nil {
144+ if err := writeFile (path , cgroupMemoryLimit , strconv .FormatInt (cgroup .Resources .Memory , 10 )); err != nil {
147145 return err
148146 }
149147 }
150148 if cgroup .Resources .MemorySwap != 0 {
151- if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatUint (cgroup .Resources .MemorySwap , 10 )); err != nil {
149+ if err := writeFile (path , cgroupMemorySwapLimit , strconv .FormatInt (cgroup .Resources .MemorySwap , 10 )); err != nil {
152150 return err
153151 }
154152 }
@@ -169,13 +167,13 @@ func (s *MemoryGroup) Set(path string, cgroup *configs.Cgroup) error {
169167 }
170168
171169 if cgroup .Resources .MemoryReservation != 0 {
172- if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatUint (cgroup .Resources .MemoryReservation , 10 )); err != nil {
170+ if err := writeFile (path , "memory.soft_limit_in_bytes" , strconv .FormatInt (cgroup .Resources .MemoryReservation , 10 )); err != nil {
173171 return err
174172 }
175173 }
176174
177175 if cgroup .Resources .KernelMemoryTCP != 0 {
178- if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatUint (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
176+ if err := writeFile (path , "memory.kmem.tcp.limit_in_bytes" , strconv .FormatInt (cgroup .Resources .KernelMemoryTCP , 10 )); err != nil {
179177 return err
180178 }
181179 }
0 commit comments