diff --git a/cmd/erasure-utils.go b/cmd/erasure-utils.go index 498997eba..5897d5e02 100644 --- a/cmd/erasure-utils.go +++ b/cmd/erasure-utils.go @@ -24,6 +24,7 @@ import ( "sync" "github.com/klauspost/reedsolomon" + "github.com/minio/sha256-simd" "golang.org/x/crypto/blake2b" ) @@ -37,23 +38,26 @@ func newHashWriters(diskCount int, algo string) []hash.Hash { } // newHash - gives you a newly allocated hash depending on the input algorithm. -func newHash(algo string) hash.Hash { +func newHash(algo string) (h hash.Hash) { switch algo { + case "sha256": + // sha256 checksum specially on ARM64 platforms or whenever + // requested as dictated by `xl.json` entry. + h = sha256.New() case "blake2b": // ignore the error, because New512 without a key never fails // New512 only returns a non-nil error, if the length of the passed // key > 64 bytes - but we use blake2b as hash fucntion (no key) - h, _ := blake2b.New512(nil) - return h + h, _ = blake2b.New512(nil) // Add new hashes here. default: // Default to blake2b. // ignore the error, because New512 without a key never fails // New512 only returns a non-nil error, if the length of the passed // key > 64 bytes - but we use blake2b as hash fucntion (no key) - h, _ := blake2b.New512(nil) - return h + h, _ = blake2b.New512(nil) } + return h } // Hash buffer pool is a pool of reusable diff --git a/cmd/xl-v1-metadata.go b/cmd/xl-v1-metadata.go index 37b21deee..8edd7d2ba 100644 --- a/cmd/xl-v1-metadata.go +++ b/cmd/xl-v1-metadata.go @@ -20,6 +20,7 @@ import ( "encoding/json" "errors" "path" + "runtime" "sort" "sync" "time" @@ -54,9 +55,28 @@ type checkSumInfo struct { } // Constant indicates current bit-rot algo used when creating objects. -const ( - bitRotAlgo = "blake2b" -) +// Depending on the architecture we are choosing a different checksum. +var bitRotAlgo = getDefaultBitRotAlgo() + +// Get the default bit-rot algo depending on the architecture. +// Currently this function defaults to "blake2b" as the preferred +// checksum algorithm on all architectures except ARM64. On ARM64 +// we use sha256 (optimized using sha2 instructions of ARM NEON chip). +func getDefaultBitRotAlgo() string { + switch runtime.GOARCH { + case "arm64": + // As a special case for ARM64 we use an optimized + // version of hash i.e sha256. This is done so that + // blake2b is sub-optimal and slower on ARM64. + // This would also allows erasure coded writes + // on ARM64 servers to be on-par with their + // counter-part X86_64 servers. + return "sha256" + default: + // Default for all other architectures we use blake2b. + return "blake2b" + } +} // erasureInfo - carries erasure coding related information, block // distribution and checksums.