the userspace solution for control groups - linux kongress 2010

70
The userspace solution for control groups Linux Kongress 2010 Dhaval Giani [email protected] RETIS Lab, Scuola Superiore Sant’Anna September 2010 Dhaval Giani The userspace solution for control groups

Upload: others

Post on 12-Sep-2021

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The userspace solution for control groups - Linux Kongress 2010

The userspace solution for control groups

Linux Kongress 2010

Dhaval [email protected]

RETIS Lab, Scuola Superiore Sant’Anna

September 2010

Dhaval Giani The userspace solution for control groups

Page 2: The userspace solution for control groups - Linux Kongress 2010

Control Groups

What are cgroups?

Well, the last talk should have covered it

Dhaval Giani The userspace solution for control groups

Page 3: The userspace solution for control groups - Linux Kongress 2010

Control Groups

What are cgroups?Well, the last talk should have covered it

Dhaval Giani The userspace solution for control groups

Page 4: The userspace solution for control groups - Linux Kongress 2010

Control Groups

cgroups should die.

-Peter Zijlstra

Dhaval Giani The userspace solution for control groups

Page 5: The userspace solution for control groups - Linux Kongress 2010

Control Groups

Next time something is added to the kernel please mark it as ”Hey,please don’t use it, this is only here so that you don’t use it.Thanks!” Maybe then dumb-ass folks like me will notice and

refrain from using it.

-Lennart Poettering

Dhaval Giani The userspace solution for control groups

Page 6: The userspace solution for control groups - Linux Kongress 2010

libcgroup

Looks to provide a programming interface without theprogrammer having to care about how cgroups are setup.

Tools

Library

Dhaval Giani The userspace solution for control groups

Page 7: The userspace solution for control groups - Linux Kongress 2010

libcgroup

Looks to provide a programming interface without theprogrammer having to care about how cgroups are setup.

Tools

Library

Dhaval Giani The userspace solution for control groups

Page 8: The userspace solution for control groups - Linux Kongress 2010

libcgroup

Looks to provide a programming interface without theprogrammer having to care about how cgroups are setup.

Tools

Library

Dhaval Giani The userspace solution for control groups

Page 9: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 10: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies

unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 11: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 12: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 13: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication.

Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 14: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 15: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 16: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 17: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 18: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

cgconfigparser - Used for parsing a configuration file andmaintaining persistence across reboots.

cgclear - Used to destroy all control group hierarchies unlessyou use Fedora where it does not touch systemd hierarchies

cgexec - Used to start a process in a cgroup

cgred - Automatic classification daemon originally based onuser classfication. Now enhanced for process basedclassification as well.

cgset/cgget - List cgroup values

lscgroup - List all cgroups

Some more

cgsnapshot - Under review right now, to generateconfigurations from current setup.

Dhaval Giani The userspace solution for control groups

Page 19: The userspace solution for control groups - Linux Kongress 2010

libcgroup - tools

Basically trying to cover a good set of requirements from theadministrator’s point of view.

Dhaval Giani The userspace solution for control groups

Page 20: The userspace solution for control groups - Linux Kongress 2010

libcgroup - library

Three main types of API

cgroup manipulation API

data structure manipulation API

configuration API

Dhaval Giani The userspace solution for control groups

Page 21: The userspace solution for control groups - Linux Kongress 2010

libcgroup - library

Three main types of API

cgroup manipulation API

data structure manipulation API

configuration API

Dhaval Giani The userspace solution for control groups

Page 22: The userspace solution for control groups - Linux Kongress 2010

libcgroup - library

Three main types of API

cgroup manipulation API

data structure manipulation API

configuration API

Dhaval Giani The userspace solution for control groups

Page 23: The userspace solution for control groups - Linux Kongress 2010

libcgroup - library

Three main types of API

cgroup manipulation API

data structure manipulation API

configuration API

Dhaval Giani The userspace solution for control groups

Page 24: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 25: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 26: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 27: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 28: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 29: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 30: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

The manipulation API

cgroup init

cgroup create cgroup

cgroup modify cgroup

cgroup delete cgroup

cgroup get cgroup

some more

Dhaval Giani The userspace solution for control groups

Page 31: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure

which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 32: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 33: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 34: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 35: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 36: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used to modify the cgroup data structure which is the main datastructure describing the cgroup

cgroup new cgroup

cgroup add controller

cgroup add value family

cgroup [sg]et uid gid

Dhaval Giani The userspace solution for control groups

Page 37: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used by cgconfigparser and cgclear.

Used to load the configuration file, both for the superuser and theregular user (the so called cascaded configurations).Not yet implemented for cgclear, but its on its way.

Dhaval Giani The userspace solution for control groups

Page 38: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used by cgconfigparser and cgclear.Used to load the configuration file, both for the superuser and the

regular user (the so called cascaded configurations).

Not yet implemented for cgclear, but its on its way.

Dhaval Giani The userspace solution for control groups

Page 39: The userspace solution for control groups - Linux Kongress 2010

libcgroup API

Used by cgconfigparser and cgclear.Used to load the configuration file, both for the superuser and the

regular user (the so called cascaded configurations).Not yet implemented for cgclear, but its on its way.

Dhaval Giani The userspace solution for control groups

Page 40: The userspace solution for control groups - Linux Kongress 2010

Issues

Written by kernel developers!

So thread safe as opposed to thread aware!The locking model is being modified atgit://libcg.git.sf.net/gitroot/libcg/libcgroup-context.git

Dhaval Giani The userspace solution for control groups

Page 41: The userspace solution for control groups - Linux Kongress 2010

Issues

Written by kernel developers!So thread safe

as opposed to thread aware!The locking model is being modified atgit://libcg.git.sf.net/gitroot/libcg/libcgroup-context.git

Dhaval Giani The userspace solution for control groups

Page 42: The userspace solution for control groups - Linux Kongress 2010

Issues

Written by kernel developers!So thread safe as opposed to thread aware!

The locking model is being modified atgit://libcg.git.sf.net/gitroot/libcg/libcgroup-context.git

Dhaval Giani The userspace solution for control groups

Page 43: The userspace solution for control groups - Linux Kongress 2010

Issues

Written by kernel developers!So thread safe as opposed to thread aware!The locking model is being modified atgit://libcg.git.sf.net/gitroot/libcg/libcgroup-context.git

Dhaval Giani The userspace solution for control groups

Page 44: The userspace solution for control groups - Linux Kongress 2010

Issues

Key Goal - Subsystem Independent Programming.

OrProgrammer should not care how subsystems are mounted.

Dhaval Giani The userspace solution for control groups

Page 45: The userspace solution for control groups - Linux Kongress 2010

Issues

Key Goal - Subsystem Independent Programming.Or

Programmer should not care how subsystems are mounted.

Dhaval Giani The userspace solution for control groups

Page 46: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Programmer does not need to bother where cgroups aremounted

But the how still has to be bothered about

Blame the cgroup developers for that

Dhaval Giani The userspace solution for control groups

Page 47: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Programmer does not need to bother where cgroups aremounted

But the how still has to be bothered about

Blame the cgroup developers for that

Dhaval Giani The userspace solution for control groups

Page 48: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Programmer does not need to bother where cgroups aremounted

But the how still has to be bothered about

Blame the cgroup developers for that

Dhaval Giani The userspace solution for control groups

Page 49: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider the following two scenarios

mount -t cgroup -o memory,cpuset cgroup /cgroup

and

mount -t cgroup -o cpuset cpuset /cgroup/cpuset

mount -t cgroup -o memory memory /cgroup/memory

What is the main difference between the two from a programmer’spoint of view?

Dhaval Giani The userspace solution for control groups

Page 50: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider the following two scenarios

mount -t cgroup -o memory,cpuset cgroup /cgroup

and

mount -t cgroup -o cpuset cpuset /cgroup/cpuset

mount -t cgroup -o memory memory /cgroup/memory

What is the main difference between the two from a programmer’spoint of view?

Dhaval Giani The userspace solution for control groups

Page 51: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider the following two scenarios

mount -t cgroup -o memory,cpuset cgroup /cgroup

and

mount -t cgroup -o cpuset cpuset /cgroup/cpuset

mount -t cgroup -o memory memory /cgroup/memory

What is the main difference between the two from a programmer’spoint of view?

Dhaval Giani The userspace solution for control groups

Page 52: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider the following two scenarios

mount -t cgroup -o memory,cpuset cgroup /cgroup

and

mount -t cgroup -o cpuset cpuset /cgroup/cpuset

mount -t cgroup -o memory memory /cgroup/memory

What is the main difference between the two from a programmer’spoint of view?

Dhaval Giani The userspace solution for control groups

Page 53: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider the following two scenarios

mount -t cgroup -o memory,cpuset cgroup /cgroup

and

mount -t cgroup -o cpuset cpuset /cgroup/cpuset

mount -t cgroup -o memory memory /cgroup/memory

What is the main difference between the two from a programmer’spoint of view?

Dhaval Giani The userspace solution for control groups

Page 54: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Simple solution

Copy the values from the parent

Dhaval Giani The userspace solution for control groups

Page 55: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Simple solutionCopy the values from the parent

Dhaval Giani The userspace solution for control groups

Page 56: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider another scenario

mount -t cgroup -o cpu,cpuset cgroup /cgroup

Well, the simple solution does fail quite spectacularly

Dhaval Giani The userspace solution for control groups

Page 57: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider another scenario

mount -t cgroup -o cpu,cpuset cgroup /cgroup

Well, the simple solution does fail quite spectacularly

Dhaval Giani The userspace solution for control groups

Page 58: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Consider another scenario

mount -t cgroup -o cpu,cpuset cgroup /cgroup

Well, the simple solution does fail quite spectacularly

Dhaval Giani The userspace solution for control groups

Page 59: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

We do have another problem

Programmer still needs to know the internals of the subsystem hewants to manipulate

Dhaval Giani The userspace solution for control groups

Page 60: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

We do have another problemProgrammer still needs to know the internals of the subsystem he

wants to manipulate

Dhaval Giani The userspace solution for control groups

Page 61: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Layer 2

Subsystem specific programming

Possibility of callbacks

Hiding some of the subsystem complexity

Dhaval Giani The userspace solution for control groups

Page 62: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Layer 2

Subsystem specific programming

Possibility of callbacks

Hiding some of the subsystem complexity

Dhaval Giani The userspace solution for control groups

Page 63: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Layer 2

Subsystem specific programming

Possibility of callbacks

Hiding some of the subsystem complexity

Dhaval Giani The userspace solution for control groups

Page 64: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

Layer 2

Subsystem specific programming

Possibility of callbacks

Hiding some of the subsystem complexity

Dhaval Giani The userspace solution for control groups

Page 65: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

But is that the complete solution?

Not really

We need to modify both the kernel and the userspace!

Dhaval Giani The userspace solution for control groups

Page 66: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

But is that the complete solution?

Not really

We need to modify both the kernel and the userspace!

Dhaval Giani The userspace solution for control groups

Page 67: The userspace solution for control groups - Linux Kongress 2010

Subsystem Independent Programming

But is that the complete solution?

Not really

We need to modify both the kernel and the userspace!

Dhaval Giani The userspace solution for control groups

Page 68: The userspace solution for control groups - Linux Kongress 2010

libcgroup

Not a bad start, but still a long way to go!

Dhaval Giani The userspace solution for control groups

Page 69: The userspace solution for control groups - Linux Kongress 2010

Questions?

Dhaval Giani The userspace solution for control groups

Page 70: The userspace solution for control groups - Linux Kongress 2010

Thank you!

Dhaval Giani The userspace solution for control groups