mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Remove globalMaxCacheSize and globalCacheExpiry variables (#3826)
This patch fixes below * Remove global variables globalMaxCacheSize and globalCacheExpiry. * Make global variables into constant in objcache package.
This commit is contained in:
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/objcache"
|
||||
)
|
||||
|
||||
// minio configuration related constants.
|
||||
@@ -78,16 +77,9 @@ var (
|
||||
// Set to true if credentials were passed from env, default is false.
|
||||
globalIsEnvCreds = false
|
||||
|
||||
// Maximum cache size. Defaults to disabled.
|
||||
// Caching is enabled only for RAM size > 8GiB.
|
||||
globalMaxCacheSize = uint64(0)
|
||||
|
||||
// Maximum size of internal objects parts
|
||||
globalPutPartSize = int64(64 * 1024 * 1024)
|
||||
|
||||
// Cache expiry.
|
||||
globalCacheExpiry = objcache.DefaultExpiry
|
||||
|
||||
// Minio local server address (in `host:port` format)
|
||||
globalMinioAddr = ""
|
||||
// Minio default port, can be changed through command line.
|
||||
|
||||
@@ -138,16 +138,8 @@ func initServerConfig(c *cli.Context) {
|
||||
// Load user supplied root CAs
|
||||
loadRootCAs()
|
||||
|
||||
// Set maxOpenFiles, This is necessary since default operating
|
||||
// system limits of 1024, 2048 are not enough for Minio server.
|
||||
setMaxOpenFiles()
|
||||
|
||||
// Set maxMemory, This is necessary since default operating
|
||||
// system limits might be changed and we need to make sure we
|
||||
// do not crash the server so the set the maxCacheSize appropriately.
|
||||
setMaxMemory()
|
||||
|
||||
// Do not fail if this is not allowed, lower limits are fine as well.
|
||||
// Set system resources to maximum.
|
||||
errorIf(setMaxResources(), "Unable to change resource limit")
|
||||
}
|
||||
|
||||
// Validate if input disks are sufficient for initializing XL.
|
||||
|
||||
@@ -16,17 +16,27 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/minio/pkg/sys"
|
||||
)
|
||||
import "github.com/minio/minio/pkg/sys"
|
||||
|
||||
func setMaxOpenFiles() error {
|
||||
_, maxLimit, err := sys.GetMaxOpenFileLimit()
|
||||
if err != nil {
|
||||
func setMaxResources() (err error) {
|
||||
var maxLimit uint64
|
||||
|
||||
// Set open files limit to maximum.
|
||||
if _, maxLimit, err = sys.GetMaxOpenFileLimit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return sys.SetMaxOpenFileLimit(maxLimit, maxLimit)
|
||||
if err = sys.SetMaxOpenFileLimit(maxLimit, maxLimit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set max memory limit as current memory limit.
|
||||
if _, maxLimit, err = sys.GetMaxMemoryLimit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = sys.SetMaxMemoryLimit(maxLimit, maxLimit)
|
||||
return err
|
||||
}
|
||||
|
||||
func getMaxCacheSize(curLimit, totalRAM uint64) (cacheSize uint64) {
|
||||
@@ -45,29 +55,25 @@ func getMaxCacheSize(curLimit, totalRAM uint64) (cacheSize uint64) {
|
||||
return cacheSize
|
||||
}
|
||||
|
||||
func setMaxMemory() error {
|
||||
// GetMaxCacheSize returns maximum cache size based on current RAM size and memory limit.
|
||||
func GetMaxCacheSize() (cacheSize uint64, err error) {
|
||||
// Get max memory limit
|
||||
_, maxLimit, err := sys.GetMaxMemoryLimit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set max memory limit as current memory limit.
|
||||
if err = sys.SetMaxMemoryLimit(maxLimit, maxLimit); err != nil {
|
||||
return err
|
||||
var curLimit uint64
|
||||
if curLimit, _, err = sys.GetMaxMemoryLimit(); err != nil {
|
||||
return cacheSize, err
|
||||
}
|
||||
|
||||
// Get total RAM.
|
||||
stats, err := sys.GetStats()
|
||||
if err != nil {
|
||||
return err
|
||||
var stats sys.Stats
|
||||
if stats, err = sys.GetStats(); err != nil {
|
||||
return cacheSize, err
|
||||
}
|
||||
|
||||
// In some OS like windows, maxLimit is zero. Set total RAM as maxLimit.
|
||||
if maxLimit == 0 {
|
||||
maxLimit = stats.TotalRAM
|
||||
if curLimit == 0 {
|
||||
curLimit = stats.TotalRAM
|
||||
}
|
||||
|
||||
globalMaxCacheSize = getMaxCacheSize(maxLimit, stats.TotalRAM)
|
||||
return nil
|
||||
cacheSize = getMaxCacheSize(curLimit, stats.TotalRAM)
|
||||
return cacheSize, err
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ func init() {
|
||||
// Disable printing console messages during tests.
|
||||
color.Output = ioutil.Discard
|
||||
|
||||
// Enable caching.
|
||||
setMaxMemory()
|
||||
// Set system resources to maximum.
|
||||
setMaxResources()
|
||||
}
|
||||
|
||||
func prepareFS() (ObjectLayer, string, error) {
|
||||
|
||||
17
cmd/xl-v1.go
17
cmd/xl-v1.go
@@ -127,14 +127,23 @@ func newXLObjects(storageDisks []StorageAPI) (ObjectLayer, error) {
|
||||
listPool: listPool,
|
||||
}
|
||||
|
||||
// Object cache is enabled when _MINIO_CACHE env is missing.
|
||||
// and cache size is > 0.
|
||||
xl.objCacheEnabled = !objCacheDisabled && globalMaxCacheSize > 0
|
||||
// Get cache size if _MINIO_CACHE environment variable is set.
|
||||
var maxCacheSize uint64
|
||||
if !objCacheDisabled {
|
||||
maxCacheSize, err = GetMaxCacheSize()
|
||||
errorIf(err, "Unable to get maximum cache size")
|
||||
|
||||
// Enable object cache if cache size is more than zero
|
||||
xl.objCacheEnabled = maxCacheSize > 0
|
||||
}
|
||||
|
||||
// Check if object cache is enabled.
|
||||
if xl.objCacheEnabled {
|
||||
// Initialize object cache.
|
||||
objCache := objcache.New(globalMaxCacheSize, globalCacheExpiry)
|
||||
objCache, err := objcache.New(maxCacheSize, objcache.DefaultExpiry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
objCache.OnEviction = func(key string) {
|
||||
debug.FreeOSMemory()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user