diff --git a/config/config.go b/config/config.go index b81d513a3ca70..ab06d9bdcf97a 100644 --- a/config/config.go +++ b/config/config.go @@ -363,8 +363,10 @@ type Status struct { // Performance is the performance section of the config. type Performance struct { - MaxProcs uint `toml:"max-procs" json:"max-procs"` + MaxProcs uint `toml:"max-procs" json:"max-procs"` + // Deprecated: use ServerMemoryQuota instead MaxMemory uint64 `toml:"max-memory" json:"max-memory"` + ServerMemoryQuota uint64 `toml:"server-memory-quota" json:"server-memory-quota"` StatsLease string `toml:"stats-lease" json:"stats-lease"` StmtCountLimit uint `toml:"stmt-count-limit" json:"stmt-count-limit"` FeedbackProbability float64 `toml:"feedback-probability" json:"feedback-probability"` @@ -603,6 +605,7 @@ var defaultConf = Config{ }, Performance: Performance{ MaxMemory: 0, + ServerMemoryQuota: 0, TCPKeepAlive: true, CrossJoin: true, StatsLease: "3s", @@ -714,6 +717,7 @@ var deprecatedConfig = map[string]struct{}{ "txn-local-latches": {}, "txn-local-latches.enabled": {}, "txn-local-latches.capacity": {}, + "performance.max-memory": {}, "max-txn-time-use": {}, } diff --git a/config/config.toml.example b/config/config.toml.example index 87544ac64c631..9df5a8268c592 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -200,8 +200,8 @@ record-db-qps = false # Max CPUs to use, 0 use number of CPUs in the machine. max-procs = 0 -# Max memory size to use, 0 use the total usable memory in the machine. -max-memory = 0 +# Memory size quota for tidb server, 0 means unlimited +server-memory-quota = 0 # StmtCountLimit limits the max count of statement inside a transaction. stmt-count-limit = 5000 diff --git a/planner/core/cache.go b/planner/core/cache.go index a9bed9877a114..e4d62da5d58ba 100644 --- a/planner/core/cache.go +++ b/planner/core/cache.go @@ -39,7 +39,7 @@ var ( PreparedPlanCacheCapacity uint = 100 // PreparedPlanCacheMemoryGuardRatio stores the global config "prepared-plan-cache-memory-guard-ratio". PreparedPlanCacheMemoryGuardRatio = 0.1 - // PreparedPlanCacheMaxMemory stores the max memory size defined in the global config "performance-max-memory". + // PreparedPlanCacheMaxMemory stores the max memory size defined in the global config "performance-server-memory-quota". PreparedPlanCacheMaxMemory = *atomic2.NewUint64(math.MaxUint64) ) diff --git a/tidb-server/main.go b/tidb-server/main.go index 9f152767ebf17..5d8ad5a1bf9e4 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -408,8 +408,8 @@ func reloadConfig(nc, c *config.Config) { // like config.GetGlobalConfig().OOMAction. // These config items will become available naturally after the global config pointer // is updated in function ReloadGlobalConfig. - if nc.Performance.MaxMemory != c.Performance.MaxMemory { - plannercore.PreparedPlanCacheMaxMemory.Store(nc.Performance.MaxMemory) + if nc.Performance.ServerMemoryQuota != c.Performance.ServerMemoryQuota { + plannercore.PreparedPlanCacheMaxMemory.Store(nc.Performance.ServerMemoryQuota) } if nc.Performance.CrossJoin != c.Performance.CrossJoin { plannercore.AllowCartesianProduct.Store(nc.Performance.CrossJoin) @@ -598,7 +598,7 @@ func setGlobalVars() { if plannercore.PreparedPlanCacheMemoryGuardRatio < 0.0 || plannercore.PreparedPlanCacheMemoryGuardRatio > 1.0 { plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1 } - plannercore.PreparedPlanCacheMaxMemory.Store(cfg.Performance.MaxMemory) + plannercore.PreparedPlanCacheMaxMemory.Store(cfg.Performance.ServerMemoryQuota) total, err := memory.MemTotal() terror.MustNil(err) if plannercore.PreparedPlanCacheMaxMemory.Load() > total || plannercore.PreparedPlanCacheMaxMemory.Load() <= 0 { @@ -612,11 +612,11 @@ func setGlobalVars() { domainutil.RepairInfo.SetRepairTableList(cfg.RepairTableList) c := config.GetGlobalConfig() executor.GlobalDiskUsageTracker.SetBytesLimit(c.TempStorageQuota) - if c.Performance.MaxMemory < 1 { + if c.Performance.ServerMemoryQuota < 1 { // If MaxMemory equals 0, it means unlimited executor.GlobalMemoryUsageTracker.SetBytesLimit(-1) } else { - executor.GlobalMemoryUsageTracker.SetBytesLimit(int64(c.Performance.MaxMemory)) + executor.GlobalMemoryUsageTracker.SetBytesLimit(int64(c.Performance.ServerMemoryQuota)) } kvcache.GlobalLRUMemUsageTracker.AttachToGlobalTracker(executor.GlobalMemoryUsageTracker) }