From bdefb77309fdc6e47102a8d6272fd2293aefa1d9 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 26 Oct 2021 09:15:17 +0800 Subject: [PATCH] internal/poll: improve the padding calculation inside struct splicePipe Updates #48968 and CL 358114 Change-Id: Ic68b4c5420c1c32f78b56874b53d717fa9af1f74 Reviewed-on: https://go-review.googlesource.com/c/go/+/358734 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Tobias Klauser --- src/internal/poll/splice_linux.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go index 6869a40b24..2d87c3d023 100644 --- a/src/internal/poll/splice_linux.go +++ b/src/internal/poll/splice_linux.go @@ -154,14 +154,18 @@ func splice(out int, in int, max int, flags int) (int, error) { return int(n), err } -type splicePipe struct { +type splicePipeFields struct { rfd int wfd int data int +} + +type splicePipe struct { + splicePipeFields // We want to use a finalizer, so ensure that the size is // large enough to not use the tiny allocator. - _ [24 - 3*unsafe.Sizeof(int(0))]byte + _ [24 - unsafe.Sizeof(splicePipeFields{})%24]byte } // splicePipePool caches pipes to avoid high-frequency construction and destruction of pipe buffers. @@ -222,7 +226,7 @@ func newPipe() (sp *splicePipe) { return nil } - sp = &splicePipe{rfd: fds[0], wfd: fds[1]} + sp = &splicePipe{splicePipeFields: splicePipeFields{rfd: fds[0], wfd: fds[1]}} if p == nil { p = new(bool) -- 2.51.0