mirror of
https://github.com/minio/minio.git
synced 2025-02-28 05:49:16 -05:00
fix: Set globalMaxCacheSize to allowable value. (#3816)
If memory resource limit and total RAM are more than 8GiB, either 50% of memory resource limit or total RAM is set to globalMaxCacheSize.
This commit is contained in:
parent
fcad4a44fd
commit
097cec676a
@ -59,25 +59,35 @@ func setMaxMemory() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = syscall.Getrlimit(syscall.RLIMIT_AS, &rLimit)
|
err = syscall.Getrlimit(syscall.RLIMIT_AS, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Validate if rlimit memory is set to lower
|
// If current rlimit is less than minRAMSize, do not set globalMaxCacheSize.
|
||||||
// than max cache size. Then we should use such value.
|
if rLimit.Cur < minRAMSize {
|
||||||
if uint64(rLimit.Cur) < globalMaxCacheSize {
|
return nil
|
||||||
globalMaxCacheSize = uint64(float64(50*rLimit.Cur) / 100)
|
}
|
||||||
}
|
|
||||||
|
// Get total RAM.
|
||||||
// Make sure globalMaxCacheSize is less than RAM size.
|
stats, err := sys.GetStats()
|
||||||
stats, err := sys.GetStats()
|
if err != nil {
|
||||||
if err != nil && err != sys.ErrNotImplemented {
|
// Ignore sys.ErrNotImplemented error.
|
||||||
return err
|
if err == sys.ErrNotImplemented {
|
||||||
}
|
err = nil
|
||||||
// If TotalRAM is >= minRAMSize we proceed to enable cache.
|
}
|
||||||
// cache is always 50% of the totalRAM.
|
|
||||||
if err == nil && stats.TotalRAM >= minRAMSize {
|
return err
|
||||||
globalMaxCacheSize = uint64(float64(50*stats.TotalRAM) / 100)
|
}
|
||||||
}
|
|
||||||
|
// Set 50% of current rlimit or total RAM to globalMaxCacheSize.
|
||||||
|
if stats.TotalRAM >= minRAMSize {
|
||||||
|
if rLimit.Cur < stats.TotalRAM {
|
||||||
|
globalMaxCacheSize = rLimit.Cur / 2
|
||||||
|
} else {
|
||||||
|
globalMaxCacheSize = stats.TotalRAM / 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -59,25 +59,35 @@ func setMaxMemory() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = syscall.Getrlimit(syscall.RLIMIT_DATA, &rLimit)
|
err = syscall.Getrlimit(syscall.RLIMIT_DATA, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Validate if rlimit memory is set to lower
|
// If current rlimit is less than minRAMSize, do not set globalMaxCacheSize.
|
||||||
// than max cache size. Then we should use such value.
|
if rLimit.Cur < minRAMSize {
|
||||||
if uint64(rLimit.Cur) < globalMaxCacheSize {
|
return nil
|
||||||
globalMaxCacheSize = uint64(float64(50*rLimit.Cur) / 100)
|
}
|
||||||
}
|
|
||||||
|
// Get total RAM.
|
||||||
// Make sure globalMaxCacheSize is less than RAM size.
|
stats, err := sys.GetStats()
|
||||||
stats, err := sys.GetStats()
|
if err != nil {
|
||||||
if err != nil && err != sys.ErrNotImplemented {
|
// Ignore sys.ErrNotImplemented error.
|
||||||
return err
|
if err == sys.ErrNotImplemented {
|
||||||
}
|
err = nil
|
||||||
// If TotalRAM is >= minRAMSize we proceed to enable cache.
|
}
|
||||||
// cache is always 50% of the totalRAM.
|
|
||||||
if err == nil && stats.TotalRAM >= minRAMSize {
|
return err
|
||||||
globalMaxCacheSize = uint64(float64(50*stats.TotalRAM) / 100)
|
}
|
||||||
}
|
|
||||||
|
// Set 50% of current rlimit or total RAM to globalMaxCacheSize.
|
||||||
|
if stats.TotalRAM >= minRAMSize {
|
||||||
|
if rLimit.Cur < stats.TotalRAM {
|
||||||
|
globalMaxCacheSize = rLimit.Cur / 2
|
||||||
|
} else {
|
||||||
|
globalMaxCacheSize = stats.TotalRAM / 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -28,15 +28,21 @@ func setMaxOpenFiles() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setMaxMemory() error {
|
func setMaxMemory() error {
|
||||||
// Make sure globalMaxCacheSize is less than RAM size.
|
// Get total RAM.
|
||||||
stats, err := sys.GetStats()
|
stats, err := sys.GetStats()
|
||||||
if err != nil && err != sys.ErrNotImplemented {
|
if err != nil {
|
||||||
|
// Ignore sys.ErrNotImplemented error.
|
||||||
|
if err == sys.ErrNotImplemented {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If TotalRAM is <= minRAMSize we proceed to enable cache.
|
|
||||||
// cache is always 50% of the totalRAM.
|
// Set 50% of total RAM to globalMaxCacheSize.
|
||||||
if err == nil && stats.TotalRAM >= minRAMSize {
|
if stats.TotalRAM >= minRAMSize {
|
||||||
globalMaxCacheSize = uint64(float64(50*stats.TotalRAM) / 100)
|
globalMaxCacheSize = stats.TotalRAM / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user