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

Allow /dev/shm size to be specified #699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
48 changes: 40 additions & 8 deletions cmd/mps-control-daemon/mount/mount-shm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,55 @@ import (
"fmt"
"os"
"os/exec"
"regexp"

"github.com/urfave/cli/v2"
"k8s.io/mount-utils"
)

type options struct {
shmSize string
}

// NewCommand constructs a mount command.
func NewCommand() *cli.Command {
// Create the 'generate-cdi' command
return &cli.Command{
Name: "mount-shm",
Usage: "Set up the /dev/shm mount required by the MPS daemon",
Action: mountShm,
opts := options{}

c := cli.Command{
Name: "mount-shm",
Usage: "Set up the /dev/shm mount required by the MPS daemon",
Before: func(ctx *cli.Context) error {
return validateFlags(ctx, &opts)
},
Action: func(ctx *cli.Context) error {
return mountShm(ctx, &opts)
},
Comment on lines +37 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I has assumed we would do this as a configuration parameter in the config file

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had that in mind too and was looking into that as a follow up to this commit.

Would you ONLY expose it in the config file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we definitely want it in the config -- I don't have a strong opinion about whether it is also a command line flag. Probably not though, since other MPS options aren't.

}

c.Flags = []cli.Flag{
&cli.StringFlag{
Name: "dev-shm-size",
Usage: "Specify the size of the tmpfs that will be created at for use by the MPS daemon",
Value: "65536k",
Destination: &opts.shmSize,
EnvVars: []string{"MPS_DEV_SHM_SIZE"},
},
}

return &c
}

func validateFlags(c *cli.Context, opts *options) error {
format := "[0-9]+[kmg%]?"
if !regexp.MustCompile(format).MatchString(opts.shmSize) {
return fmt.Errorf("dev-shm-size does not match format %q: %q", format, opts.shmSize)
}

return nil
}

// mountShm creates a tmpfs mount at /mps/shm to be used by the mps control daemon.
func mountShm(c *cli.Context) error {
func mountShm(c *cli.Context, opts *options) error {
mountExecutable, err := exec.LookPath("mount")
if err != nil {
return fmt.Errorf("error finding 'mount' executable: %w", err)
Expand All @@ -54,8 +86,8 @@ func mountShm(c *cli.Context) error {
return fmt.Errorf("error creating directory %v: %w", shmDir, err)
}

// TODO: What should the size of the shm be
mountOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=65536k"}
sizeArg := fmt.Sprintf("size=%v", opts.shmSize)
mountOptions := []string{"rw", "nosuid", "nodev", "noexec", "relatime", sizeArg}
if err := mounter.Mount("shm", shmDir, "tmpfs", mountOptions); err != nil {
return fmt.Errorf("error mounting %v as tmpfs: %w", shmDir, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ spec:
command: [mps-control-daemon, mount-shm]
securityContext:
privileged: true
env:
{{- if typeIs "string" .Values.mps.devShmSize }}
- name: MPS_DEV_SHM_SIZE
value: {{ .Values.mps.devShmSize }}
{{- end }}
volumeMounts:
- name: mps-root
mountPath: /mps
Expand Down
6 changes: 6 additions & 0 deletions deployments/helm/nvidia-device-plugin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@ mps:
# directories.
# Pipe directories will be created at {{ mps.root }}/{{ .ResourceName }}
root: "/run/nvidia/mps"
# devShmSize specifies the size in bytes of the tmpfs created for the MPS
# control daemon.
# The format should match that of the size argument (excluding the size=)
# prefix when mounting a tmpfs:
# See https://man7.org/linux/man-pages/man5/tmpfs.5.html
devShmSize: null