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

RFC: libcontainer: add rdmacg support #1612

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
&PerfEventGroup{},
&FreezerGroup{},
&NameGroup{GroupName: "name=systemd", Join: true},
&RdmaGroup{},
}
HugePageSizes, _ = cgroups.GetHugePageSize()
)
Expand Down
68 changes: 68 additions & 0 deletions libcontainer/cgroups/fs/rdma.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// +build linux

package fs

import (
"fmt"
"strconv"

"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs"
)

type RdmaGroup struct {
}

func (s *RdmaGroup) Name() string {
return "rdma"
}

func (s *RdmaGroup) Apply(d *cgroupData) error {
_, err := d.join("rdma")
if err != nil && !cgroups.IsNotFound(err) {
return err
}
return nil
}

func (s *RdmaGroup) Set(path string, cgroup *configs.Cgroup) error {
for _, rdmaLimit := range cgroup.Resources.RdmaLimits {
var handleLimit, objectLimit string

if rdmaLimit.HcaHandleLimit == -1 {
handleLimit = "max"
} else {
handleLimit = strconv.FormatInt(rdmaLimit.HcaHandleLimit, 10)
}

if rdmaLimit.HcaObjectLimit == -1 {
objectLimit = "max"
} else {
objectLimit = strconv.FormatInt(rdmaLimit.HcaObjectLimit, 10)
}

if err := writeFile(path, "rdma.current", fmt.Sprintf("%s hca_handle=%s hca_object=%s", rdmaLimit.InterfaceName, handleLimit, objectLimit)); err != nil {
return err
}
}

return nil
}

func (s *RdmaGroup) Remove(d *cgroupData) error {
return removePath(d.path("rdma"))
}

func (s *RdmaGroup) GetStats(path string, stats *cgroups.Stats) error {
str, err := readFile(path, "rdma.current")
if err != nil {
return err
}

var interfaceName string
var rdmaStats cgroups.RdmaStats
fmt.Sscanf(str, "%s hca_handle=%d hca_object=%d", interfaceName, rdmaStats.HcaHandle, rdmaStats.HcaObject)
stats.RdmaStats[interfaceName] = rdmaStats
return nil
}

1 change: 1 addition & 0 deletions libcontainer/cgroups/rootless/rootless.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var subsystems = []subsystem{
&fs.PerfEventGroup{},
&fs.FreezerGroup{},
&fs.NameGroup{GroupName: "name=systemd"},
&fs.RdmaGroup{},
}

type subsystem interface {
Expand Down
10 changes: 9 additions & 1 deletion libcontainer/cgroups/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,25 @@ type HugetlbStats struct {
Failcnt uint64 `json:"failcnt"`
}

type RdmaStats struct {
HcaHandle int64 `json:"hca_handle"`
HcaObject int64 `json:"hca_object"`
}

type Stats struct {
CpuStats CpuStats `json:"cpu_stats,omitempty"`
MemoryStats MemoryStats `json:"memory_stats,omitempty"`
PidsStats PidsStats `json:"pids_stats,omitempty"`
BlkioStats BlkioStats `json:"blkio_stats,omitempty"`
// the map is in the format "size of hugepage: stats of the hugepage"
HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"`
// RdmaStats is a map from interface name to its stats
RdmaStats map[string]RdmaStats `json:"rmda_stats,omitempty"`
}

func NewStats() *Stats {
memoryStats := MemoryStats{Stats: make(map[string]uint64)}
hugetlbStats := make(map[string]HugetlbStats)
return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats}
rdmaStats := make(map[string]RdmaStats)
return &Stats{MemoryStats: memoryStats, HugetlbStats: hugetlbStats, RdmaStats: rdmaStats}
}
1 change: 1 addition & 0 deletions libcontainer/cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var subsystems = subsystemSet{
&fs.NetPrioGroup{},
&fs.NetClsGroup{},
&fs.NameGroup{GroupName: "name=systemd"},
&fs.RdmaGroup{},
}

const (
Expand Down
3 changes: 3 additions & 0 deletions libcontainer/configs/cgroup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ type Resources struct {

// Set class identifier for container's network packets
NetClsClassid uint32 `json:"net_cls_classid_u"`

// Limit of RDMA related resources
RdmaLimits []*RdmaLimit `json:"rdma_limits"`
}
12 changes: 12 additions & 0 deletions libcontainer/configs/rdma_limit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package configs

type RdmaLimit struct {
// A name of interface that supports RDMA.
InterfaceName string `json:"interface_name"`

// Limit of HCA Handle. -1 means max.
HcaHandleLimit int64 `json:"hca_handle_limit"`

// Limit of HCA Object. -1 means max.
HcaObjectLimit int64 `json:"hca_object_limit"`
}