From 0cef9718325d0d9807ac173310b0282a8d297a1f Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 7 Dec 2016 01:09:26 +0100 Subject: [PATCH] Fix max cache size calculation when system RAM is inferior to the default cache size (#3410) --- cmd/server-rlimit-nix.go | 2 +- pkg/objcache/objcache.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/server-rlimit-nix.go b/cmd/server-rlimit-nix.go index 687d41e4b..ff8bf1c65 100644 --- a/cmd/server-rlimit-nix.go +++ b/cmd/server-rlimit-nix.go @@ -77,7 +77,7 @@ func setMaxMemory() error { return err } if err == nil && stats.TotalRAM < globalMaxCacheSize { - globalMaxCacheSize = (80 / 100) * stats.TotalRAM + globalMaxCacheSize = uint64(float64(80*stats.TotalRAM) / 100) } return nil } diff --git a/pkg/objcache/objcache.go b/pkg/objcache/objcache.go index 4e266d02a..11cf3cc88 100644 --- a/pkg/objcache/objcache.go +++ b/pkg/objcache/objcache.go @@ -73,6 +73,9 @@ type Cache struct { // the items in the cache never expire (by default), and must be deleted // manually. func New(maxSize uint64, expiry time.Duration) *Cache { + if maxSize == 0 { + panic("objcache: setting maximum cache size to zero is forbidden.") + } C := &Cache{ maxSize: maxSize, entries: make(map[string]*buffer),