From c3217bd6ebc0ecdad45219d6a46c06a54c4405f2 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 3 Mar 2021 16:28:10 -0800 Subject: [PATCH] Use actual size for buffer selection (#11687) For compressed inputs, this will be -1, but the object may be small. --- cmd/erasure-multipart.go | 9 ++++++++- cmd/erasure-object.go | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/erasure-multipart.go b/cmd/erasure-multipart.go index 58b0f6719..4664fb8ad 100644 --- a/cmd/erasure-multipart.go +++ b/cmd/erasure-multipart.go @@ -452,7 +452,14 @@ func (er erasureObjects) PutObjectPart(ctx context.Context, bucket, object, uplo switch size := data.Size(); { case size == 0: buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF - case size == -1 || size >= fi.Erasure.BlockSize: + case size == -1: + if size := data.ActualSize(); size > 0 && size < fi.Erasure.BlockSize { + buffer = make([]byte, data.ActualSize()+256, data.ActualSize()*2+512) + } else { + buffer = er.bp.Get() + defer er.bp.Put(buffer) + } + case size >= fi.Erasure.BlockSize: buffer = er.bp.Get() defer er.bp.Put(buffer) case size < fi.Erasure.BlockSize: diff --git a/cmd/erasure-object.go b/cmd/erasure-object.go index 16e7f89a5..53ec298e0 100644 --- a/cmd/erasure-object.go +++ b/cmd/erasure-object.go @@ -683,7 +683,14 @@ func (er erasureObjects) putObject(ctx context.Context, bucket string, object st switch size := data.Size(); { case size == 0: buffer = make([]byte, 1) // Allocate atleast a byte to reach EOF - case size == -1 || size >= fi.Erasure.BlockSize: + case size == -1: + if size := data.ActualSize(); size > 0 && size < fi.Erasure.BlockSize { + buffer = make([]byte, data.ActualSize()+256, data.ActualSize()*2+512) + } else { + buffer = er.bp.Get() + defer er.bp.Put(buffer) + } + case size >= fi.Erasure.BlockSize: buffer = er.bp.Get() defer er.bp.Put(buffer) case size < fi.Erasure.BlockSize: