github.com/kubewharf/katalyst-core@v0.5.3/cmd/katalyst-agent/app/options/qrm/memory_plugin.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package qrm
    18  
    19  import (
    20  	cliflag "k8s.io/component-base/cli/flag"
    21  
    22  	qrmconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/qrm"
    23  )
    24  
    25  type MemoryOptions struct {
    26  	PolicyName                  string
    27  	ReservedMemoryGB            uint64
    28  	SkipMemoryStateCorruption   bool
    29  	EnableSettingMemoryMigrate  bool
    30  	EnableMemoryAdvisor         bool
    31  	ExtraControlKnobConfigFile  string
    32  	EnableOOMPriority           bool
    33  	OOMPriorityPinnedMapAbsPath string
    34  
    35  	SockMemOptions
    36  }
    37  
    38  type SockMemOptions struct {
    39  	EnableSettingSockMem bool
    40  	// SetGlobalTCPMemRatio limits global max tcp memory usage.
    41  	SetGlobalTCPMemRatio int
    42  	// SetCgroupTCPMemLimitRatio limit cgroup max tcp memory usage.
    43  	SetCgroupTCPMemRatio int
    44  }
    45  
    46  func NewMemoryOptions() *MemoryOptions {
    47  	return &MemoryOptions{
    48  		PolicyName:                 "dynamic",
    49  		ReservedMemoryGB:           0,
    50  		SkipMemoryStateCorruption:  false,
    51  		EnableSettingMemoryMigrate: false,
    52  		EnableMemoryAdvisor:        false,
    53  		EnableOOMPriority:          false,
    54  		SockMemOptions: SockMemOptions{
    55  			EnableSettingSockMem: false,
    56  			SetGlobalTCPMemRatio: 20,  // default: 20% * {host total memory}
    57  			SetCgroupTCPMemRatio: 100, // default: 100% * {cgroup memory}
    58  		},
    59  	}
    60  }
    61  
    62  func (o *MemoryOptions) AddFlags(fss *cliflag.NamedFlagSets) {
    63  	fs := fss.FlagSet("memory_resource_plugin")
    64  
    65  	fs.StringVar(&o.PolicyName, "memory-resource-plugin-policy",
    66  		o.PolicyName, "The policy memory resource plugin should use")
    67  	fs.Uint64Var(&o.ReservedMemoryGB, "memory-resource-plugin-reserved",
    68  		o.ReservedMemoryGB, "reserved memory(GB) for system agents")
    69  	fs.BoolVar(&o.SkipMemoryStateCorruption, "skip-memory-state-corruption",
    70  		o.SkipMemoryStateCorruption, "if set true, we will skip memory state corruption")
    71  	fs.BoolVar(&o.EnableSettingMemoryMigrate, "enable-setting-memory-migrate",
    72  		o.EnableSettingMemoryMigrate, "if set true, we will enable cpuset.memory_migrate for containers not numa_binding")
    73  	fs.BoolVar(&o.EnableMemoryAdvisor, "memory-resource-plugin-advisor",
    74  		o.EnableMemoryAdvisor, "Whether memory resource plugin should enable sys-advisor")
    75  	fs.StringVar(&o.ExtraControlKnobConfigFile, "memory-extra-control-knob-config-file",
    76  		o.ExtraControlKnobConfigFile, "the absolute path of extra control knob config file")
    77  	fs.BoolVar(&o.EnableOOMPriority, "enable-oom-priority",
    78  		o.EnableOOMPriority, "if set true, we will enable oom priority enhancement")
    79  	fs.StringVar(&o.OOMPriorityPinnedMapAbsPath, "oom-priority-pinned-bpf-map-path",
    80  		o.OOMPriorityPinnedMapAbsPath, "the absolute path of oom priority pinned bpf map")
    81  	fs.BoolVar(&o.EnableSettingSockMem, "enable-setting-sockmem",
    82  		o.EnableSettingSockMem, "if set true, we will limit tcpmem usage in cgroup and host level")
    83  	fs.IntVar(&o.SetGlobalTCPMemRatio, "qrm-memory-global-tcpmem-ratio",
    84  		o.SetGlobalTCPMemRatio, "limit global max tcp memory usage")
    85  	fs.IntVar(&o.SetCgroupTCPMemRatio, "qrm-memory-cgroup-tcpmem-ratio",
    86  		o.SetCgroupTCPMemRatio, "limit cgroup max tcp memory usage")
    87  }
    88  
    89  func (o *MemoryOptions) ApplyTo(conf *qrmconfig.MemoryQRMPluginConfig) error {
    90  	conf.PolicyName = o.PolicyName
    91  	conf.ReservedMemoryGB = o.ReservedMemoryGB
    92  	conf.SkipMemoryStateCorruption = o.SkipMemoryStateCorruption
    93  	conf.EnableSettingMemoryMigrate = o.EnableSettingMemoryMigrate
    94  	conf.EnableMemoryAdvisor = o.EnableMemoryAdvisor
    95  	conf.ExtraControlKnobConfigFile = o.ExtraControlKnobConfigFile
    96  	conf.EnableOOMPriority = o.EnableOOMPriority
    97  	conf.OOMPriorityPinnedMapAbsPath = o.OOMPriorityPinnedMapAbsPath
    98  	conf.EnableSettingSockMem = o.EnableSettingSockMem
    99  	conf.SetGlobalTCPMemRatio = o.SetGlobalTCPMemRatio
   100  	conf.SetCgroupTCPMemRatio = o.SetCgroupTCPMemRatio
   101  	return nil
   102  }