Object-cache: enforce cache size to be less than RAM. (#2338)

This commit is contained in:
Krishna Srinivas
2016-08-02 22:34:35 +05:30
committed by Harshavardhana
parent 1494af485e
commit 69fd196471
6 changed files with 207 additions and 1 deletions
+16 -1
View File
@@ -18,7 +18,11 @@
package main
import "syscall"
import (
"syscall"
"github.com/minio/minio/pkg/sys"
)
// For all unixes we need to bump allowed number of open files to a
// higher value than its usual default of '1024'. The reasoning is
@@ -72,5 +76,16 @@ func setMaxMemory() error {
if rLimit.Cur < globalMaxCacheSize {
globalMaxCacheSize = (80 / 100) * rLimit.Cur
}
// Make sure globalMaxCacheSize is less than RAM size.
stats, err := sys.GetStats()
if err != nil && err != sys.ErrNotImplemented {
// sys.GetStats() is implemented only on linux. Ignore errors
// from other OSes.
return err
}
if err == nil && stats.TotalRAM < globalMaxCacheSize {
globalMaxCacheSize = (80 / 100) * stats.TotalRAM
}
return nil
}