Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nri-memtierd: mount only needed dirs from host #121

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cmd/plugins/memtierd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ type memtierdEnv struct {
}

type options struct {
HostRoot string
runDir string
cgroupsDir string
}

const (
Expand Down Expand Up @@ -244,8 +245,6 @@ func (p *plugin) StartContainer(ctx context.Context, pod *api.PodSandbox, ctr *a
ppName := pprintCtr(pod, ctr)
log.Tracef("StartContainer: %s", ppName)

hostRoot := opt.HostRoot

namespace := pod.GetNamespace()
podName := pod.GetName()
containerName := ctr.GetName()
Expand All @@ -269,7 +268,7 @@ func (p *plugin) StartContainer(ctx context.Context, pod *api.PodSandbox, ctr *a
if err != nil {
return loggedErrorf("cannot detect cgroup v2 path for container %q: %v", ppName, err)
}
mtdEnv, err := newMemtierdEnv(fullCgroupsPath, namespace, podName, containerName, qoscls.MemtierdConfig, hostRoot)
mtdEnv, err := newMemtierdEnv(fullCgroupsPath, namespace, podName, containerName, qoscls.MemtierdConfig, opt.runDir)
if err != nil || mtdEnv == nil {
return loggedErrorf("failed to prepare memtierd run environment: %v", err)
}
Expand Down Expand Up @@ -385,9 +384,9 @@ func (p *plugin) getFullCgroupsPath(ctr *api.Container) (string, error) {

// newMemtierdEnv prepares new memtierd run environment with a
// configuration file template instantiated for managing a container.
func newMemtierdEnv(fullCgroupPath string, namespace string, podName string, containerName string, memtierdConfigIn string, hostRoot string) (*memtierdEnv, error) {
func newMemtierdEnv(fullCgroupPath string, namespace string, podName string, containerName string, memtierdConfigIn string, runDir string) (*memtierdEnv, error) {
// Create container directory if it doesn't exist
ctrDir := fmt.Sprintf("%s%s/memtierd/%s/%s/%s", hostRoot, os.TempDir(), namespace, podName, containerName)
ctrDir := fmt.Sprintf("%s/%s/%s/%s", runDir, namespace, podName, containerName)
if err := os.MkdirAll(ctrDir, 0755); err != nil {
return nil, fmt.Errorf("cannot create memtierd run directory %q: %w", ctrDir, err)
}
Expand Down Expand Up @@ -466,7 +465,8 @@ func main() {
flag.StringVar(&pluginName, "name", "", "plugin name to register to NRI")
flag.StringVar(&pluginIdx, "idx", "", "plugin index to register to NRI")
flag.StringVar(&configFile, "config", "", "configuration file name")
flag.StringVar(&opt.HostRoot, "host-root", "", "Directory prefix under which the host's tmp, etc. are mounted.")
flag.StringVar(&opt.cgroupsDir, "cgroups-dir", "", "cgroups root directory")
flag.StringVar(&opt.runDir, "run-dir", "", "Directory prefix for memtierd runtime environments")
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.BoolVar(&veryVerbose, "vv", false, "very verbose output")
flag.Parse()
Expand All @@ -478,6 +478,10 @@ func main() {
log.SetLevel(logrus.TraceLevel)
}

if opt.runDir == "" {
opt.runDir = filepath.Join(os.TempDir(), "nri-memtierd")
}

p := &plugin{
ctrMemtierdEnv: map[string]*memtierdEnv{},
}
Expand All @@ -493,6 +497,8 @@ func main() {
}
}

p.cgroupsDir = opt.cgroupsDir

if p.cgroupsDir == "" {
if err := p.detectCgroupsDir(); err != nil {
log.Fatalf("cannot find cgroup2 mount point. %s", err)
Expand Down
25 changes: 17 additions & 8 deletions cmd/plugins/memtierd/nri-memtierd-deployment.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ spec:
- "45"
- --config
- /etc/nri/memtierd/config.yaml
- --host-root
- /host
- --run-dir
- /run-dir
- --cgroups-dir
- /sys/fs/cgroup
- -v
image: IMAGE_PLACEHOLDER
imagePullPolicy: IfNotPresent
Expand All @@ -41,9 +43,11 @@ spec:
mountPath: /etc/nri/memtierd
- name: nri-sockets-vol
mountPath: /var/run/nri
- name: host-vol
mountPath: /host
- name: host-bitmap
- name: run-dir-vol
mountPath: /run-dir
- name: cgroups-vol
mountPath: /sys/fs/cgroup
- name: idlepage-vol
mountPath: /sys/kernel/mm/page_idle/bitmap
volumes:
- name: memtierd-config-vol
Expand All @@ -53,13 +57,18 @@ spec:
hostPath:
path: /var/run/nri
type: Directory
- name: host-vol
- name: run-dir-vol
hostPath:
path: /
path: /var/run/nri-memtierd
type: DirectoryOrCreate
- name: cgroups-vol
hostPath:
path: /sys/fs/cgroup
type: Directory
- name: host-bitmap
- name: idlepage-vol
hostPath:
path: /sys/kernel/mm/page_idle/bitmap
type: File
---
apiVersion: v1
kind: ConfigMap
Expand Down
26 changes: 18 additions & 8 deletions deployment/overlays/memtierd/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ spec:
- "45"
- --config
- /etc/nri/memtierd/config.yaml
- --host-root
- /host
- --run-dir
- /run-dir
- --cgroups-dir
- /sys/fs/cgroup
- -v
image: IMAGE_PLACEHOLDER
imagePullPolicy: IfNotPresent
Expand All @@ -41,9 +43,12 @@ spec:
mountPath: /etc/nri/memtierd
- name: nri-sockets-vol
mountPath: /var/run/nri
- name: host-vol
mountPath: /host
- name: host-bitmap
# # Uncomment to access memtierd.output files from host
# - name: run-dir-vol
# mountPath: /run-dir
- name: cgroups-vol
mountPath: /sys/fs/cgroup
- name: idlepage-vol
mountPath: /sys/kernel/mm/page_idle/bitmap
volumes:
- name: memtierd-config-vol
Expand All @@ -53,10 +58,15 @@ spec:
hostPath:
path: /var/run/nri
type: Directory
- name: host-vol
# # Uncomment to access memtierd.output files from host
# - name: run-dir-vol
# hostPath:
# path: /var/run/nri-memtierd
# type: DirectoryOrCreate
- name: cgroups-vol
hostPath:
path: /
path: /sys/fs/cgroup
type: Directory
- name: host-bitmap
- name: idlepage-vol
hostPath:
path: /sys/kernel/mm/page_idle/bitmap
24 changes: 24 additions & 0 deletions deployment/overlays/memtierd/sample-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ data:
mover:
intervalms: 20
bandwidth: 50
- name: track-working-set-size
allowswap: false
memtierdconfig: |
policy:
name: age
config: |
intervalms: 20000
pidwatcher:
name: cgroups
config: |
cgroups:
- $CGROUP2_ABS_PATH
tracker:
name: idlepage
config: |
pagesinregion: 512
maxcountperregion: 1
scanintervalms: 20000
routines:
- name: statactions
config: |
intervalms: 60000
intervalcommand: ["policy", "-dump", "accessed", "0,1m,30m,2h,24h,0"]
intervalcommandrunner: memtier
24 changes: 16 additions & 8 deletions test/e2e/files/nri-memtierd-deployment.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ spec:
- "45"
- --config
- /etc/nri/memtierd/config.yaml
- --host-root
- /host
- --run-dir
- /run-dir
- --cgroups-dir
- /sys/fs/cgroup
- -vv
image: IMAGE_PLACEHOLDER
imagePullPolicy: IfNotPresent
Expand All @@ -41,9 +43,11 @@ spec:
mountPath: /etc/nri/memtierd
- name: nri-sockets-vol
mountPath: /var/run/nri
- name: host-vol
mountPath: /host
- name: host-bitmap
- name: run-dir-vol
mountPath: /run-dir
- name: cgroups-vol
mountPath: /sys/fs/cgroup
- name: idlepage-vol
mountPath: /sys/kernel/mm/page_idle/bitmap
volumes:
- name: memtierd-config-vol
Expand All @@ -53,11 +57,15 @@ spec:
hostPath:
path: /var/run/nri
type: Directory
- name: host-vol
- name: run-dir-vol
hostPath:
path: /
path: /var/run/nri-memtierd
type: DirectoryOrCreate
- name: cgroups-vol
hostPath:
path: /sys/fs/cgroup
type: Directory
- name: host-bitmap
- name: idlepage-vol
hostPath:
path: /sys/kernel/mm/page_idle/bitmap
---
Expand Down