From 66aeb467de80c92a099e49eaad6c25974c96f9cf Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 12 Oct 2017 19:08:18 +0200 Subject: pkg/ipc: don't send program padding to executor Currently we always send 2MB of data to executor in ipc_simple.go. Send only what's consumed by the program, and don't send the trailing zeros. Serialized programs usually take only few KBs. --- prog/encodingexec.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'prog/encodingexec.go') diff --git a/prog/encodingexec.go b/prog/encodingexec.go index b2b173bbe..e45ba1192 100644 --- a/prog/encodingexec.go +++ b/prog/encodingexec.go @@ -57,8 +57,9 @@ func (s ByPhysicalAddr) Less(i, j int) bool { } // SerializeForExec serializes program p for execution by process pid into the provided buffer. +// Returns number of bytes written to the buffer. // If the provided buffer is too small for the program an error is returned. -func (p *Prog) SerializeForExec(buffer []byte, pid int) error { +func (p *Prog) SerializeForExec(buffer []byte, pid int) (int, error) { if debug { if err := p.validate(); err != nil { panic(fmt.Errorf("serializing invalid program: %v", err)) @@ -193,9 +194,9 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error { } w.write(ExecInstrEOF) if w.eof { - return fmt.Errorf("provided buffer is too small") + return 0, fmt.Errorf("provided buffer is too small") } - return nil + return len(buffer) - len(w.buf), nil } func (target *Target) physicalAddr(arg Arg) uint64 { -- cgit mrf-deployment