vendor: update go-runc to reduce gc pressure

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2018-01-24 16:19:24 -08:00
parent 3fcc52b091
commit f534a20173
3 changed files with 25 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
package runc
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -532,7 +531,9 @@ func (r *Runc) Restore(context context.Context, id, bundle string, opts *Restore
// Update updates the current container with the provided resource spec
func (r *Runc) Update(context context.Context, id string, resources *specs.LinuxResources) error {
buf := bytes.NewBuffer(nil)
buf := getBuf()
defer putBuf(buf)
if err := json.NewEncoder(buf).Encode(resources); err != nil {
return err
}
@@ -638,11 +639,12 @@ func (r *Runc) runOrError(cmd *exec.Cmd) error {
}
func cmdOutput(cmd *exec.Cmd, combined bool) ([]byte, error) {
var b bytes.Buffer
b := getBuf()
defer putBuf(b)
cmd.Stdout = &b
cmd.Stdout = b
if combined {
cmd.Stderr = &b
cmd.Stderr = b
}
ec, err := Monitor.Start(cmd)
if err != nil {

View File

@@ -1,8 +1,10 @@
package runc
import (
"bytes"
"io/ioutil"
"strconv"
"sync"
"syscall"
)
@@ -26,3 +28,18 @@ func exitStatus(status syscall.WaitStatus) int {
}
return status.ExitStatus()
}
var bytesBufferPool = sync.Pool{
New: func() interface{} {
return bytes.NewBuffer(nil)
},
}
func getBuf() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer)
}
func putBuf(b *bytes.Buffer) {
b.Reset()
bytesBufferPool.Put(b)
}