Skip to contentSkip to conversation

sched: automated per tty task groups

PATCH Superseded Mike Galbraith 41 participants 264 messages Oct 19, 2010 – Jan 4, 2011 2 messages not in the archive Page 2 of 2

Subsystems (8)
lore
Share & tools
lore
#223 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Jesper Juhl
Quoted 44 lines · Jesper Juhl
Quoted 12 lines · Colin Walters
Quoted 3 lines · Linus Torvalds

The semantics of "nice" are not - and have never been - to put things into process scheduling groups of their own.

Again, I obviously understand that - the point is to explore the space of changes here and consider what would (and wouldn't) break. And actually, what would improve.

Quoted 1 line

This is very much documented. People rely on it.

Quoted 11 lines

Well, we established my Fedora 14 system doesn't. You said "no one" uses "nice" interactively. So...that leaves - who? If you were saying to me something like "I know Yahoo has some code in their data centers which uses a range of nice values; if we made this change, all of a sudden they'd get more CPU contention..." Or like, "I'm pretty sure Maemo uses very low nice values for some UI code". But you so far haven't really done that, it's just been (mostly) assertions/handwaving. Now you obviously have a lot more experience that gives those assertions and handwaving a lot of credibility - but all we need is one concrete example to shut me up =)

[...]

I'll give you two re-world examples from two (closed source, but still) apps we develop at my current employer.

The first one is a server/network monitoring app where there are lots of child processes devoted to performing checks, storing data, displaying results etc. Most of these processes just run at the default nice level. One of the processes sometimes has a need for a cryptographic key pair and it can generate this when it needs it, but it's better if one is reaily available, so we have a seperate child process running that maintains a small pool of new key pairs - this process runs at a high nice level since it should not take CPU time away from the rest of the processes (it's not important, it's just a small optimization), the need for key pairs comes at large intervals, so the pool will almost never be depleted even if this process doesn't get very much CPU time for a long time and besides, if the pool ever gets depleted its no disaster since the consumer will then just generate a key pair when needed and burn the required CPU.

Quoted 8 lines

The second is a backup aplication where one child process is in charge of doing background disk scanning, compression and encryption. This process is not interactive, it must result in minimal interference with whatever the user is currently using the machine for as his primary task and time-to-completion is not really that important. So, this process runs at a rather high nice level to avoid stealing CPU from the users primary task(s).

Ohh and a third example. On my home laptop I got sufficiently annoyed with 'updatedb' starting up from cron while I was in the middle of something so that cron job now runs updatedb with 'nice 19' and also uses ionice so it runs at the 'best effort' class and with priority 7 (lowest).

Signature · 3 lines
Jesper Juhl <[email protected]>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
#224 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Linus Torvalds
Quoted 3 lines · Linus Torvalds

Nice levels are _not_ about group scheduling. They're about priorities. And since the cgroup code doesn't even support priority levels for the groups, it's a really *horrible* match.

It does in fact, nice maps to a weight, we then schedule so that each entity (be it task or group) gets a proportional amount of time relative to the other entities (of the same parent).

The scheduler basically solves the following differential equation:
dt_i = w_i * dt / \Sum_j w_j

For tasks we map nice to weight like:

static const int prio_to_weight[40] = {

 /* -20 */     88761,     71755,     56483,     46273,     36291,
 /* -15 */     29154,     23254,     18705,     14949,     11916,
 /* -10 */      9548,      7620,      6100,      4904,      3906,
 /*  -5 */      3121,      2501,      1991,      1586,      1277,
 /*   0 */      1024,       820,       655,       526,       423,
 /*   5 */       335,       272,       215,       172,       137,
 /*  10 */       110,        87,        70,        56,        45,
 /*  15 */        36,        29,        23,        18,        15,

};

For groups we expose the weight directly in cgroupfs://cpu.shares with a default equivalent to nice-0 (1024).

So 'nice make -j9' will run make and all its children with weight=110, if this task hierarchy has ~9 runnable tasks it will get about as much time as a single nice-0 competing task.

[ 9*110 = 990, 1*1024 = 1024, which gives: 49% vs 51% ]

Now group scheduling is in fact closely related to nice, the only thing group scheduling does is:

w_i = \unit * \Prod_j { w_i,j / \Sum_k w_k,j }, where:

j \elem i and its parents
k \elem entities of group j (where a task is a trivial group)

Where we compute a task's effective weight (w_i) by multiplying it with the effective weight of their ancestors.

Suppose a grouped make -j9 against 1 competing task (all nice-0 or equivalent), and make's 9 active children [a..i] in the group G:

        R
      /   \
     t     G
          / \
         a...i

So w_t = 1024, w_G = 1024 and w_[a..i] = 1024.

Now, per the above the effective weight (weight as in the root group) of each grouped task is:

w_[a..i] = 1024 * 1024/2048 * 1024/9216 ~= 56
w_t = 1024 * 1024/2048 = 512

[ \Sum w_[a..i] = 512, vs 512 gives: 50% vs 50% ]

So effectively: nice make -j9, and stuffing the make -j9 in a group are roughly equivalent.

The only difference between groups and nice is the interface, with nice you set the weight directly, with groups you set it implicitly, depending on the runnable task state.

#225 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Colin Walters

Greets.

I applaud your efforts to continue addressing interactivity and responsiveness but, I know I'm going to regret this, I feel strongly enough to speak up about this change.

Quoted 5 lines · On Sun, 5 Dec 2010 10:43:44 Colin Walters wrote:
Quoted 1 line · Linus Torvalds

What's your point again? It's a heuristic.

So if it's a heuristic the OS can get wrong,

This is precisely what I see as the flaw in this approach. The whole reason you have CFS now is that we had a scheduler which was pretty good for all the other things in the O(1) scheduler, but needed heuristics to get interactivity right. I put them there. Then I spent the next few years trying to find a way to get rid of them. The reason is precisely what Colin says above. Heuristics get it wrong sometimes. So no matter how smart you think your heuristics are, it is impossible to get it right 100% of the time. If the heuristics make it better 99% of the time, and introduce disastrous corner cases, regressions and exploits 1% of the time, that's unforgivable. That's precisely what we had with the old O(1) scheduler and that's what you got rid of when you put CFS into mainline. The whole reason CFS was better was it was mostly fair and concentrated on ensuring decent latency rather than trying to guess what would be right, so it was predictable and reliable.

So if you introduce heuristics once again into the scheduler to try and improve the desktop by unfairly distributing CPU, you will go back to where you once were. Mostly better but sometimes really badly wrong. No matter how smart you think you can be with heuristics they cannot be right all the time. And there are regressions with these tty followed by per session group patches. Search forums where desktop users go and you'll see that people are afraid to speak up on lkml but some users are having mplayer and amarok skipping under light load when trying them. You want to program more intelligence in to work around these regressions, you'll just get yourself deeper and deeper into the same quagmire. The 'quick fix' you seek now is not something you should be defending so vehemently. The "I have a solution now" just doesn't make sense in this light. I for one do not welcome our new heuristic overlords.

If you're serious about really improving the desktop from within the kernel, as you seem to be with this latest change, then make a change that's predictable and gets it right ALL the time and is robust for the future. Stop working within all the old fashioned concepts and allow userspace to tell the kernel what it wants, and give the user the power to choose. If you think this is too hard and not doable, or that the user is too uninformed or want to modify things themselves, then allow me to propose a relatively simple change that can expedite this.

There are two aspects to getting good desktop behaviour, enough CPU and low latency. 'nice' by your own admission is too crude and doesn't really describe how either of these should really be modified. Furthermore there are 40 levels of it and only about 4 or 5 are ever used. We also know that users don't even bother using it.

What I propose is a new syscall latnice for "latency nice". It only need have 4 levels, 1 for default, 0 for latency insensitive, 2 for relatively latency sensitive gui apps, and 3 for exquisitely latency sensitive uses such as audio. These should not require extra privileges to use and thus should also not be usable for "exploiting" extra CPU by default. It's simply a matter of working with lower latencies yet shorter quota (or timeslices) which would mean throughput on these apps is sacrificed due to cache trashing but then that's not what latency sensitive applications need. These can then be encouraged to be included within the applications themselves, making this a more long term change. 'Firefox' could set itself 2, 'Amarok' and 'mplayer' 3, and 'make' - bless its soul - 0, and so on. Keeping the range simple and defined will make it easy for userspace developers to cope with, and users to fiddle with.

But that would only be the first step. The second step is to take the plunge and accept that we DO want selective unfairness on the desktop, but where WE want it, not where the kernel thinks we might want it. It's not an exploit if my full screen HD video continues to consume 80% of the CPU while make is running - on a desktop. Take a leaf out of other desktop OSs and allow the user to choose say levels 0, 1, or 2 for desktop interactivity with a simple /proc/sys/kernel/interactive tunable, a bit like the "optimise for foreground applications" seen elsewhere. This could then be used to decide whether to use the scheduling hints from latnice to either just ensure low latency but keep the same CPU usage - 0, or actually give progressively more CPU for latniced tasks as the interactive tunable is increased. Then distros can set this on installation and make it part of the many funky GUIs to choose between the different levels. This then takes the user out of the picture almost entirely, yet gives them the power to change it if they so desire.

The actual scheduler changes required to implement this are absurdly simple and doable now, and will not cost in overhead the way cgroups do. It also should cause no regressions when interactive mode is disabled and would have no effect till changes are made elsewhere, or the users use the latnice utility.

Move away from the fragile heuristic tweaks and find a longer term robust solution.

Regards,
Con

Signature · 4 lines
-ck

P.S. I'm very happy for someone else to do it. Alternatively you could include 
BFS and I'd code it up for that in my spare time.
#226 lore raw

Re: [PATCH v4] sched: automated per session task groups

Quoted 9 lines · Con Kolivas

Greets.

I applaud your efforts to continue addressing interactivity and responsiveness but, I know I'm going to regret this, I feel strongly enough to speak up about this change.

Quoted 2 lines · On Sun, 5 Dec 2010 10:43:44 Colin Walters wrote:

On Sat, Dec 4, 2010 at 5:39 PM, Linus Torvalds
<[email protected]> wrote:

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

What's your point again? It's a heuristic.

So if it's a heuristic the OS can get wrong,

This is precisely what I see as the flaw in this approach. The whole reason you have CFS now is that we had a scheduler which was pretty good for all the other things in the O(1) scheduler, but needed heuristics to get interactivity right. I put them there.

Actually, Linus laid the foundation with sleeper fairness, Ingo expanded it to requeue "interactive" tasks in the active array, and you tweaked the result.

Quoted 10 lines

Then I spent the next few years trying to find a way
to get rid of them. The reason is precisely what Colin says above. Heuristics get it wrong sometimes. So no matter how smart you think your heuristics are, it is impossible to get it right 100% of the time. If the heuristics make it better 99% of the time, and introduce disastrous corner cases, regressions and exploits 1% of the time, that's unforgivable. That's precisely what we had with the old O(1) scheduler and that's what you got rid of when you put CFS into mainline. The whole reason CFS was better was it was mostly fair and concentrated on ensuring decent latency rather than trying to guess what would be right, so it was predictable and reliable.

And it still is Con. I didn't rewrite the thing, I just added an automated task grouping. Session to session fairness is just as holy as any sacred cow definition of fair you care to trot out.

Quoted 8 lines

So if you introduce heuristics once again into the scheduler to try and improve the desktop by unfairly distributing CPU, you will go back to where you once were. Mostly better but sometimes really badly wrong. No matter how smart you think you can be with heuristics they cannot be right all the time. And there are regressions with these tty followed by per session group patches. Search forums where desktop users go and you'll see that people are afraid to speak up on lkml but some users are having mplayer and amarok skipping under light load when trying them.

Shrug. I can't debug what isn't reported.

Quoted 6 lines

You want to program more
intelligence in to work around these regressions, you'll just get yourself deeper and deeper into the same quagmire. The 'quick fix' you seek now is not something you should be defending so vehemently. The "I have a solution now" just doesn't make sense in this light. I for one do not welcome our new heuristic overlords.

I for one don't welcome childish name calling.

Quoted 15 lines

If you're serious about really improving the desktop from within the kernel, as you seem to be with this latest change, then make a change that's predictable and gets it right ALL the time and is robust for the future. Stop working within all the old fashioned concepts and allow userspace to tell the kernel what it wants, and give the user the power to choose. If you think this is too hard and not doable, or that the user is too uninformed or want to modify things themselves, then allow me to propose a relatively simple change that can expedite this.

There are two aspects to getting good desktop behaviour, enough CPU and low latency. 'nice' by your own admission is too crude and doesn't really describe how either of these should really be modified. Furthermore there are 40 levels of it and only about 4 or 5 are ever used. We also know that users don't even bother using it.

Quoted 13 lines

What I propose is a new syscall latnice for "latency nice". It only need have 4 levels, 1 for default, 0 for latency insensitive, 2 for relatively latency sensitive gui apps, and 3 for exquisitely latency sensitive uses such as audio. These should not require extra privileges to use and thus should also not be usable for "exploiting" extra CPU by default. It's simply a matter of working with lower latencies yet shorter quota (or timeslices) which would mean throughput on these apps is sacrificed due to cache trashing but then that's not what latency sensitive applications need. These can then be encouraged to be included within the applications themselves, making this a more long term change. 'Firefox' could set itself 2, 'Amarok' and 'mplayer' 3, and 'make' - bless its soul - 0, and so on. Keeping the range simple and defined will make it easy for userspace developers to cope with, and users to fiddle with.

An automated per session task group is an evil heuristic, so we should use kinda sorta sensitive, really REALLY sensitive, don't give a damn, or no frickin' clue... to make 100% accurate non-heuristic scheduling decisions instead? Did I get that right?

Goodbye.

-Mike

#227 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Con Kolivas
Quoted 6 lines · Con Kolivas

Greets.

I applaud your efforts to continue addressing interactivity and responsiveness but, I know I'm going to regret this, I feel strongly enough to speak up about this change.

Quoted 8 lines
Quoted 5 lines · On Sun, 5 Dec 2010 10:43:44 Colin Walters wrote:
Quoted 1 line · Linus Torvalds

What's your point again? It's a heuristic.

So if it's a heuristic the OS can get wrong,

This is precisely what I see as the flaw in this approach. [...]

I think you are misunderstanding Mike's auto-group scheduling feature.

The scheduling itself is not 'heuristics'.

It is the _composition of a group_ that has a heuristic default. (We use the 'tty' to act as the grouping)

But that can be changed: the cgroup interfaces can be (and are) used by Gnome to create different groups. They can be used by users as well, using cgroup tooling.

What the kernel does is that it provides sane defaults.

Quoted 4 lines

[...]

Move away from the fragile heuristic tweaks and find a longer term robust solution.

This is not some kernel heuristic that cannot be modified - which was the main problem of the O(1) scheduler. This is a common-sense default that can be overriden by user-space if it wants to.

So i definitely think you are confusing the two cases.

Thanks,

Ingo

#228 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Colin Walters
Quoted 10 lines · Colin Walters

Speaking of the scheduler documentation - note that its sample shell code contains exactly the problem showing what's wrong with auto-grouping-by-tty, which is:

# firefox &	# Launch firefox and move it to "browser" group

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

as someone who starts firefox from a terminal session all the time, I always want to start it from it's own dedicated session, if for no other reason that it spits out a TON of error messages over time, and I don't want them popping up in a window where I'm doing something else.

so this is a very bad example.

David Lang

#229 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Colin Walters
Quoted 11 lines · Colin Walters

[...]
Speaking of the scheduler documentation - note that its sample shell code contains exactly the problem showing what's wrong with auto-grouping-by-tty, which is:

# firefox& # Launch firefox and move it to "browser" group

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

Btw, most people don't do that anymore. They don't use terminals. They click the application icons on their desktops and start menus or double click the executables in their file managers. So it's not a matter of opening a second terminal tab, because the first one isn't even open.

To have a fluid desktop one shouldn't require to hack with terminal commands.

#230 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 6 lines
Quoted 4 lines

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

Btw, most people don't do that anymore. They don't use terminals. They

Its a regression for those who do - and often have good reason to do. This is of course why you don't put policy in the kernel and the original patch was bogus anyway.

Quoted 2 lines

To have a fluid desktop one shouldn't require to hack with terminal commands.

Which is the classic mentality that ruins the big bloated GNOME Linux desktop "It works my way and every other way is wrong so go screw". Of course the other half of the problem is exactly that - firefox was once a small browser, its now a bloated monster too so the scheduler is quite sensible to pick on it.

Alan

#231 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 10 lines · On Sun, 5 Dec 2010 15:12:20 +0000 Alan Cox <[email protected]> wrote:
Quoted 2 lines

To have a fluid desktop one shouldn't require to hack with terminal commands.

Which is the classic mentality that ruins the big bloated GNOME Linux desktop "It works my way and every other way is wrong so go screw". Of course the other half of the problem is exactly that - firefox was once a small browser, its now a bloated monster too so the scheduler is quite sensible to pick on it.

Alan

Your rant about big bloated GNOME is... well just a rant. You will never be able to change it. You can just hope, that over time the evolutionary aspects of open source development will fix it.

There is nothing wrong with trying to provide ease of use. Graphical interfaces that are well designed are easier to use.
Most command-line people just can't cope with the unstable nature of interfaces in the graphical world.

CLI's are mostly better from an ergonomic view (old people, heavy working hackers and other power users) because they provide a stable focus point.

But this comes at some cost because the human mind is (originally) not tuned for text processing and remembering abstract things like 'words'. It's unique ability to adapt itself to this is.. extraordinary. Most hackers probably don't realize this, but images/icons and other graphical interfaces are more similar to real life and are thus easier to use for 'unadapted' people.

"Master minds" that can remember numbers with [really-big-number] of digits often use a trick to do this: They associate every digit-pair with an everyday item. When they learn the number, they construct a story using those items. This story is what they then later use to restore the original number. All that is because humans can remember real life things better than digits or words.

Regards,
Flo

#232 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 3 lines

Your rant about big bloated GNOME is... well just a rant. You will never be able to change it. You can just hope, that over time the evolutionary aspects of open source development will fix it.

They already are - its dying slowly but surely.

Quoted 2 lines

There is nothing wrong with trying to provide ease of use. Graphical interfaces that are well designed are easier to use.

Interesting how you associate ease of use with being bloated and oversize.

Quoted 2 lines

Most command-line people just can't cope with the unstable nature of interfaces in the graphical world.

Ah of course. How sweet, your response to a point about the arrogance of certain desktop attitudes is to lecture, and make bogus pronouncements about command-line people. You might want to put the shovel away instead.

Quoted 3 lines

CLI's are mostly better from an ergonomic view (old people, heavy working hackers and other power users) because they provide a stable focus point.

And a bit of pop psychology to go with it. I assume you are trying to talk about internalised and externalised models ?

Quoted 1 line

Most hackers probably don't realize this, but images/icons and other

No of course not we are all dim, thank you for using small words. I am actually familiar with the real models here btw and there are a couple of rather important basics you are missing

- Different people have different strengths in different areas - these don't specifically line up with the senses. There isn't vast amounts of evidence to support computing people are all strong in a particular area either. You'll see in studies that some of them prefer to diagram and flowchart, some write text, some have kinesthetic models (movement and flow). I don't doubt there are others who sense it in different ways.

- Visual and textual data communicate different things more effectively (as do sounds, smells, movements, ....) and are processed with different natural preferences by different people

- Oh and there is no evidence I've ever seen to suggest old people are more text oriented.

So any notion of CLI's or GUI's being better for [class of people] is generally naïve. It depends what is being done, who is doing it and the situation.

If you really want to understand the trade-offs in a graphical world watch some good CAD operators for an hour. They'll use the same tools in very different ways - some very command line, some heavily mouse/trackball, others graphical but with hotkeys, and they'll often shift approach according to task.

Quoted 2 lines

graphical interfaces are more similar to real life and are thus easier to use for 'unadapted' people.

If you wish to see an unadapted person you probably want to go look at amazonian tribes. Bit different.

But then the GUI world is the world that put "logout" under "start" 8) and thinks that "Insert OLE Object" is a good thing to put on a menu.

Alan

#233 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 6 lines · On Sun, 5 Dec 2010 19:48:11 +0000 Alan Cox <[email protected]> wrote:
Quoted 3 lines

Your rant about big bloated GNOME is... well just a rant. You will never be able to change it. You can just hope, that over time the evolutionary aspects of open source development will fix it.

They already are - its dying slowly but surely.

But maybe they will start slimming it down and all will be well...

Quoted 4 lines
Quoted 2 lines

There is nothing wrong with trying to provide ease of use. Graphical interfaces that are well designed are easier to use.

Interesting how you associate ease of use with being bloated and oversize.

Didn't want to imply that. But I think I maybe assumed wrongly that your usage of 'bloat' and 'oversize' was an overstatement and you were ranting inherently at the complexity of graphical user interfaces..

Quoted 7 lines
Quoted 3 lines

Most command-line people just can't cope with the unstable nature of interfaces in the graphical world.

Ah of course. How sweet, your response to a point about the arrogance of certain desktop attitudes is to lecture, and make bogus pronouncements about command-line people. You might want to put the shovel away instead.

You seem to be angry. What's the problem? I find your reaction strange.

Isn't that a valid point?

I really have problems with graphical programs and tools where you have to click on the left side of the window on some 'X' Icon in Ubuntu and right top corner on fluxbox. and on the third desktop setup ratpoison is running with some super special key combos and all you can do is strg-backspace, except it's disabled.

With CLI programs I don't have those problems. I just strg-c most of the time, if even necessary.

Quoted 7 lines
Quoted 4 lines

CLI's are mostly better from an ergonomic view (old people, heavy working hackers and other power users) because they provide a stable focus point.

And a bit of pop psychology to go with it. I assume you are trying to talk about internalised and externalised models ?

*head scratch*

Quoted 6 lines
Quoted 2 lines

Most hackers probably don't realize this, but images/icons and other

No of course not we are all dim, thank you for using small words. I am actually familiar with the real models here btw and there are a couple of rather important basics you are missing

I find your tone inappropriate. I was not trying to insult you or anything.

Quoted 8 lines

- Different people have different strengths in different areas - these don't specifically line up with the senses. There isn't vast amounts of evidence to support computing people are all strong in a particular area either. You'll see in studies that some of them prefer to diagram and flowchart, some write text, some have kinesthetic models (movement and flow). I don't doubt there are others who sense it in different ways.

Why do you think I did imply something other? I was talking about humans in general. Language is an abstract concept. It's not something we intuitivly know when we are born, we have to learn it.

I was getting at the fact that the brain adapts towards it's usage. People doing lot's of sport do have less trouble learning a new kind of sport.
People that do hack a lot on computers have less trouble learning to use a new tool.
A physics professor has less trouble understanding a new theory about the beginning of the world.

People working a lot with programming languages and on the commandline are more used to it. Other people find interfaces that resemble real world items easier to use, because they aren't used to inputting commands in text form.

Quoted 10 lines

- Visual and textual data communicate different things more effectively (as do sounds, smells, movements, ....) and are processed with different natural preferences by different people

- Oh and there is no evidence I've ever seen to suggest old people are more text oriented.

So any notion of CLI's or GUI's being better for [class of people] is generally naïve. It depends what is being done, who is doing it and the situation.

Indeed. I didn't try to classify people at all. I'm kind of sad you would assume that.

Quoted 7 lines

If you really want to understand the trade-offs in a graphical world watch some good CAD operators for an hour. They'll use the same tools in very different ways - some very command line, some heavily mouse/trackball, others graphical but with hotkeys, and they'll often shift approach according to task.

Quoted 5 lines
Quoted 2 lines

graphical interfaces are more similar to real life and are thus easier to use for 'unadapted' people.

If you wish to see an unadapted person you probably want to go look at amazonian tribes. Bit different.

I guess that is what I mean.

Quoted 3 lines

But then the GUI world is the world that put "logout" under "start" 8) and thinks that "Insert OLE Object" is a good thing to put on a menu.

:-)

Quoted 2 lines

Alan

Regards,
Flo

#234 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

In reply to Alan Cox
Quoted 10 lines · Alan Cox
Quoted 6 lines
Quoted 4 lines

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

Btw, most people don't do that anymore. They don't use terminals. They

Its a regression for those who do - and often have good reason to do. This is of course why you don't put policy in the kernel and the original patch was bogus anyway.

What is a very clear regression is a threaded app (say firefox) vs a single threaded app, particularly on UP. The per thread scheduling model wins hands down there, because the scheduler very heavily favors the threaded application. Take that unfairness away, and you have an undeniable regression. Yes, it's not black and white, never is.

-Mike

#235 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 12 lines · Mike Galbraith
Quoted 10 lines · Alan Cox
Quoted 6 lines
Quoted 4 lines

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

Btw, most people don't do that anymore. They don't use terminals. They

Its a regression for those who do - and often have good reason to do. This is of course why you don't put policy in the kernel and the original patch was bogus anyway.

Quoted 5 lines

What is a very clear regression is a threaded app (say firefox) vs a single threaded app, particularly on UP. The per thread scheduling model wins hands down there, because the scheduler very heavily favors the threaded application. Take that unfairness away, and you have an undeniable regression. Yes, it's not black and white, never is.

P.S. You also have an obvious _progression_ from the perspective of the single threaded application, which may just as well be interactive.

#236 lore raw

Re: [PATCH v4] Regression: sched: automated per session task groups

Quoted 13 lines · Mike Galbraith
Quoted 12 lines · Mike Galbraith
Quoted 10 lines · Alan Cox
Quoted 6 lines
Quoted 4 lines

As soon as you do that from the same terminal that you're going to launch the "make" from, you're back to total lossage. Are you going to explain to a student that "oh, you need to create a new gnome-terminal tab and launch firefox from that"?

Btw, most people don't do that anymore. They don't use terminals. They

Its a regression for those who do - and often have good reason to do. This is of course why you don't put policy in the kernel and the original patch was bogus anyway.

Quoted 8 lines
Quoted 5 lines

What is a very clear regression is a threaded app (say firefox) vs a single threaded app, particularly on UP. The per thread scheduling model wins hands down there, because the scheduler very heavily favors the threaded application. Take that unfairness away, and you have an undeniable regression. Yes, it's not black and white, never is.

P.S. You also have an obvious _progression_ from the perspective of the single threaded application, which may just as well be interactive.

P.P.S :)

systemd will have the same regressions/progressions. It doesn't matter one whit whether it's kernel/userland making policy. If distro-X includes either one, or neither, they are guaranteed to be wrong :)

#237 lore raw

Re: [PATCH v4] sched: automated per session task groups

In reply to Colin Walters
Quoted 5 lines · Colin Walters

Look around...where? On what basis are you making that claim? I did a quick web search for "unix background process", and this tutorial (in the first page of Google search results) aimed at grad students who use Unix at college definitely describes "nice make":
http://acs.ucsd.edu/info/jobctrl.shtml

The fact that something is documented doesn't mean the documentation actually is correct.

There exists a Linux guide written by somebody (who has enough of a rep that you can safely say "should have known better") who didn't understand the difference between traditional Unix and Linux, nor what the original concept was, and it documented the proper way to take a system down quickly as:

# sync;sync;sync;halt

Of course, the *original* was:

# sync
# sync
# sync
# halt

And the whole point of 3 syncs was that the typing time of the second and third sync's chewed up the time till the first sync finished. Of course, sync;sync doesn't start the first sync and then make you type. And it overlooked that the Linux sync is a lot more synchronous than the ATT Unix sync, which returned as soon as the I/O was scheduled, not completed.

#238 lore raw
In reply to Mike Galbraith
Quoted 10 lines · Mike Galbraith
Quoted 6 lines

kernel/sched_autogroup.c line 72

Quoted 2 lines
kernel/sched_autogroup.c new file +2 -0
+   if (p->flags & PF_EXITING)
+           return false;

Hmm, why? Perhaps PF_EXITING was needed in the previous version to avoid the race with release_task(). But now it is always safe to use signal->autogroup.

That came into existence when I stress tested previous version in PREEMPT_RT (boom). I see no good reason to bother an exiting task though, so would prefer to leave it as is.

PREEMPT_RT has a slightly different exit path IIRC. If that was the only thing you saw it explode on we could leave the check out for now and revisit it in the -rt patches when and if it pops up. Hmm?

#239 lore raw
Quoted 8 lines · Peter Zijlstra
Quoted 7 lines · Mike Galbraith
Quoted 6 lines

kernel/sched_autogroup.c line 72

Quoted 2 lines
kernel/sched_autogroup.c new file +2 -0
+   if (p->flags & PF_EXITING)
+           return false;

Hmm, why? Perhaps PF_EXITING was needed in the previous version to avoid the race with release_task(). But now it is always safe to use signal->autogroup.

Quoted 7 lines
Quoted 3 lines

That came into existence when I stress tested previous version in PREEMPT_RT (boom). I see no good reason to bother an exiting task though, so would prefer to leave it as is.

PREEMPT_RT has a slightly different exit path IIRC. If that was the only thing you saw it explode on we could leave the check out for now and revisit it in the -rt patches when and if it pops up. Hmm?

Yeah, I'm going to whack it. (and add your lockdep thingy)

-Mike

#240 lore raw
In reply to Mike Galbraith

Hi Mike,

drivers/tty/tty_io.c static void __proc_set_tty(struct task_s · line 3165

Quoted 9 lines · Mike Galbraith
drivers/tty/tty_io.c +1 -0
@@ -3160,6 +3160,7 @@ static void __proc_set_tty(struct task_s
 	put_pid(tsk->signal->tty_old_pgrp);
 	tsk->signal->tty = tty_kref_get(tty);
 	tsk->signal->tty_old_pgrp = NULL;
+	sched_autogroup_create_attach(tsk);
 }
 

This is a bit of a problem, as it's called in_atomic context and kmalloc's under GFP_KERNEL (which can sleep.) This results in sleep-under-spinlock prints when CONFIG_DEBUG_SPINLOCK_SLEEP=y.

I spent a bit of time thinking about how to fix that, but it's a bit difficult because of the nested spin_lock_irq in that bit of the tty_ioctl callchain.

I'll think about it some more tonight and follow-up if I can think of a way to fix it.

regards, Kyle

#241 lore raw
Quoted 4 lines · Kyle McMartin

This is a bit of a problem, as it's called in_atomic context and kmalloc's under GFP_KERNEL (which can sleep.) This results in sleep-under-spinlock prints when CONFIG_DEBUG_SPINLOCK_SLEEP=y.

Blame me, I threw that out as a single point where this can be done.

In fact, holding the signal spinlock was seen as a bonus, since that was used to serialize the access to the signal->autogroup access. Which I think is required.

But yes, it does create problems for the allocation. It could be done as just a GFP_ATOMIC, of course, and on allocation failure you'd just punt and not do it. Not pretty, but functional.

Linus

#242 lore raw
Quoted 10 lines · Linus Torvalds

Blame me, I threw that out as a single point where this can be done.

In fact, holding the signal spinlock was seen as a bonus, since that was used to serialize the access to the signal->autogroup access. Which I think is required.

But yes, it does create problems for the allocation. It could be done as just a GFP_ATOMIC, of course, and on allocation failure you'd just punt and not do it. Not pretty, but functional.

Yeah, I didn't look any deeper than kernel/sched.c::sched_create_group, but that would need to GFP_ATOMIC as well.

Looking at it now, so would alloc_rt_sched_group/alloc_fair_sched_group, and we're looking at an awful lot of sleepless allocations. Not sure that's a feasible plan.

--Kyle

#243 lore raw
In reply to Kyle McMartin
Quoted 16 lines · Kyle McMartin

Hi Mike,

drivers/tty/tty_io.c static void __proc_set_tty(struct task_s · line 3165

Quoted 9 lines · Mike Galbraith
drivers/tty/tty_io.c +1 -0
@@ -3160,6 +3160,7 @@ static void __proc_set_tty(struct task_s
 	put_pid(tsk->signal->tty_old_pgrp);
 	tsk->signal->tty = tty_kref_get(tty);
 	tsk->signal->tty_old_pgrp = NULL;
+	sched_autogroup_create_attach(tsk);
 }
 

This is a bit of a problem, as it's called in_atomic context and kmalloc's under GFP_KERNEL (which can sleep.) This results in sleep-under-spinlock prints when CONFIG_DEBUG_SPINLOCK_SLEEP=y.

Yeah, I got another report about that today.

-Mike

#244 lore raw
In reply to Linus Torvalds
Quoted 9 lines · Linus Torvalds
Quoted 2 lines · Linus Torvalds

This catless version looks very good to me

Oh, btw, maybe one comment: is CONFIG_SCHED_AUTOGROUP_DEBUG even worth having as a config option? The only thing it enables is the small /proc interface, and I don't see any downside to just always having that if you have AUTOGROUP enabled in the first place.

If the on/off is available, you can silently strand pinned tasks forever in an autogroup. So, I tied the on/off switch to the global move so the user won't be surprised.

-Mike

#245 lore raw
In reply to Mike Galbraith
Quoted 10 lines · Mike Galbraith

Implementation: each task struct contains an inherited pointer to a refcounted autogroup struct containing a task group pointer, the default for all tasks pointing to the init_task_group. When a task calls __proc_set_tty(), the task's reference to the default group is dropped, a new task group is created, and the task is moved out of the old group and into the new. Children thereafter inherit this task group, and increase it's refcount. Calls to __tty_hangup() and proc_clear_tty() move the caller back to the init_task_group, and possibly destroy the task group. On exit, reference to the current task group is dropped, and the task group is potentially destroyed. At runqueue selection time, iff a task has no cgroup assignment, it's current autogroup is used.

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct? Do we have any provisions for making sure that if a user has 8 or 10 windows open doing heavy work, the default group (with a lot of important daemons/etc in it) doesn't get starved with only a 1/10th share of the CPU? Or am I missing something here?

Quoted 1 line

+extern void sched_autogroup_detatch(struct task_struct *p);

sched_autogroup_detach() instead?

#246 lore raw
Quoted 3 lines · On Mon, Nov 15, 2010 at 2:41 PM, <[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

It's not clear exactly what the non-tty heuristics would be, but I do have a few suggestions:

- I think it might be a good idea to associate a task group with the
current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Now, for desktop use, that probably doesn't often matter, but even
for just the desktop it would mean that "system daemons" would at least get a group of their own, rather than be grouped with "everything else"

(As is, I think the autogroup thing already ends up protecting
system daemons more than _not_ having the autogroup, since it will basically mean that a "make -j64" won't be stealing all the CPU time from everybody else - even if the system daemons all end up in that single "default" group together with the non-tty graphical apps.)

- I suspect we could make kernel daemons be a group of their own.

Quoted 4 lines

 Do we have any provisions for making sure that if
a user has 8 or 10 windows open doing heavy work, the default group (with a lot of important daemons/etc in it) doesn't get starved with only a 1/10th share of the CPU? Or am I missing something here?

I think you're missing the fact that without the autogroups, it's _worse_. If you do "make -j64" without autogroups, those important daemons get starved by all that work. With the autogroups, they end up being protected by being in the default group.

So the fact that they are in the default group with lots of other users doesn't hurt, quite the reverse. User apps are likely to be in their own groups, so they affect system apps less than they do now.

But I do agree that we might be able to make that all much more explicit.

Linus

#247 lore raw
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · On Mon, Nov 15, 2010 at 2:41 PM, <[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

Quoted 7 lines

It's not clear exactly what the non-tty heuristics would be, but I do have a few suggestions:

- I think it might be a good idea to associate a task group with the
current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Or how about (just brainstorming here) a group per 'process group'?

Signature · 3 lines
Jesper Juhl <[email protected]>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
#248 lore raw
Quoted 13 lines · Jesper Juhl
Quoted 11 lines · Linus Torvalds
Quoted 3 lines · On Mon, Nov 15, 2010 at 2:41 PM, <[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

Quoted 8 lines
Quoted 7 lines

It's not clear exactly what the non-tty heuristics would be, but I do have a few suggestions:

- I think it might be a good idea to associate a task group with the
current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Or how about (just brainstorming here) a group per 'process group'?

I switched to per session, which on my system at least looks like more than enough granularity.

-Mike

#249 lore raw
Quoted 17 lines · Mike Galbraith
Quoted 16 lines · Jesper Juhl
Quoted 14 lines · Linus Torvalds
Quoted 3 lines · On Mon, Nov 15, 2010 at 2:41 PM, <[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

It's not clear exactly what the non-tty heuristics would be, but I do have a few suggestions:

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

- I think it might be a good idea to associate a task group with the
current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Or how about (just brainstorming here) a group per 'process group'?

I switched to per session, which on my system at least looks like more than enough granularity.

Sounds sane and it's closer to the original 'per tty' which was so successful.

Signature · 3 lines
Jesper Juhl <[email protected]>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.
#250 lore raw
In reply to Mike Galbraith
Quoted 15 lines · Mike Galbraith
Quoted 14 lines · Jesper Juhl
Quoted 12 lines · Linus Torvalds
Quoted 2 lines · On Mon, Nov 15, 2010 at 2:41 PM,<[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

It's not clear exactly what the non-tty heuristics would be, but I do have a few suggestions:

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines

- I think it might be a good idea to associate a task group with the
current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Or how about (just brainstorming here) a group per 'process group'?

I switched to per session, which on my system at least looks like more than enough granularity

Will that have an effect on software like Chromium which creates a fork for each tab? If a user opens Thunderbird and Chromium with 100 tabs, Thunderbird should probably get 50% CPU time instead of just 1%...

#251 lore raw
Quoted 3 lines · Konstantin Svist, le Sat 20 Nov 2010 14:02:32 -0800, a écrit :

Will that have an effect on software like Chromium which creates a fork for each tab? If a user opens Thunderbird and Chromium with 100 tabs, Thunderbird should probably get 50% CPU time instead of just 1%...

Chromium doesn't create a session or even a process group for each tab.

Samuel

#252 lore raw
In reply to Konstantin Svist
Quoted 21 lines · you
Quoted 20 lines · Mike Galbraith
Quoted 19 lines · Jesper Juhl
Quoted 17 lines · Linus Torvalds
Quoted 2 lines · On Mon, Nov 15, 2010 at 2:41 PM,<[email protected]> wrote:

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct?

Well, yes and no.

Yes, that's what the code currently does. But I did ask Mike (and he delivered) to try to make the code look and work in a way where the whole "tty thing" is just one of the heuristics.

It's not clear exactly what the non-tty heuristics would be, but I do

have a few suggestions:
- I think it might be a good idea to associate a task group with the

current "cred" of a process, and fall back on it in the absense of a tty-provided one.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Or how about (just brainstorming here) a group per 'process group'?

I switched to per session, which on my system at least looks like more than enough granularity

Will that have an effect on software like Chromium which creates a fork for each tab? If a user opens Thunderbird and Chromium with 100 tabs, Thunderbird should probably get 50% CPU time instead of just 1%...

At least on my machine, all of the chromium processes have the same session id.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
Thomas Fjellstrom
[email protected]
#253 lore raw
In reply to Jesper Juhl
Quoted 1 line · Jesper Juhl, le Sat 20 Nov 2010 20:33:21 +0100, a écrit :

Or how about (just brainstorming here) a group per 'process group'?

That'd be too heavy by Linus' measurement, as you have a process group for each shell command.

Samuel

#254 lore raw
In reply to [email protected]
Quoted 13 lines · On Mon, 2010-11-15 at 17:41 -0500, [email protected] wrote:
Quoted 10 lines · Mike Galbraith

Implementation: each task struct contains an inherited pointer to a refcounted autogroup struct containing a task group pointer, the default for all tasks pointing to the init_task_group. When a task calls __proc_set_tty(), the task's reference to the default group is dropped, a new task group is created, and the task is moved out of the old group and into the new. Children thereafter inherit this task group, and increase it's refcount. Calls to __tty_hangup() and proc_clear_tty() move the caller back to the init_task_group, and possibly destroy the task group. On exit, reference to the current task group is dropped, and the task group is potentially destroyed. At runqueue selection time, iff a task has no cgroup assignment, it's current autogroup is used.

Quoted 5 lines

So the set of all tasks that never call proc_set_tty() ends up in the same one big default group, correct? Do we have any provisions for making sure that if a user has 8 or 10 windows open doing heavy work, the default group (with a lot of important daemons/etc in it) doesn't get starved with only a 1/10th share of the CPU? Or am I missing something here?

Yes, all tasks never having had a tty association are relegated to the root task group, and no, there is no provision for the root task group getting more than it's fair share of CPU.

The patch is only intended to (hopefully) better suit the general case desktop. One size has zero chance of fitting all ;-)

Quoted 3 lines
Quoted 1 line

+extern void sched_autogroup_detatch(struct task_struct *p);

sched_autogroup_detach() instead?

Hm, why?

-Mike

-Mike

#255 lore raw
Quoted 7 lines · Mike Galbraith
Quoted 3 lines · On Mon, 2010-11-15 at 17:41 -0500, [email protected] wrote:
Quoted 1 line

+extern void sched_autogroup_detatch(struct task_struct *p);

sched_autogroup_detach() instead?

Hm, why?

You really aren't a good speller of that word, are you?

Linus

#256 lore raw
Quoted 10 lines · Linus Torvalds
Quoted 7 lines · Mike Galbraith
Quoted 3 lines · On Mon, 2010-11-15 at 17:41 -0500, [email protected] wrote:
Quoted 1 line

+extern void sched_autogroup_detatch(struct task_struct *p);

sched_autogroup_detach() instead?

Hm, why?

You really aren't a good speller of that word, are you?

<stare> d e t a c h... d e t a t....t? aw crap. Guess not.

Couldn't even see it.

-Mike

#257 lore raw

Hmm. Just found a bug. I'm not sure if it's the autogroup patches themselves, or whether it's just the cgroup code that the autogroup patch enables for me.

When I do

echo t > /proc/sysrq-trigger

(or "w") I get a NULL pointer dereference (offset 0x38 - decimal 56) in "cgroup_path+0x7", with a call trace of sched_debug_show, show_state_filter, sysrq_handle_showstate_blocked. I don't have the whole oops, because the machine is really dead at that point (presumably died holding the runqueue lock or some other critical resource), but if required I could take a photo of it. However, I bet it is repeatable, so I doubt you need it.

Anyway, that "cgroup_path+0x7" is the very first memory dereference:

    movq    56(%rdi), %rsi  # cgrp_5(D)->dentry, _________p1

so sched_debug_show() is apparently calling cgroup_path() with a NULL cgroup. I think it's "print_task()" that is to blame, it does

     cgroup_path(task_group(p)->css.cgroup, ..

without checking whether there _is_ any css.cgroup.

Peter, that looks like your code (commit d19ca30874f2)

Guys?

Linus

#258 lore raw
Quoted 7 lines · Linus Torvalds

so sched_debug_show() is apparently calling cgroup_path() with a NULL cgroup. I think it's "print_task()" that is to blame, it does

    cgroup_path(task_group(p)->css.cgroup, ..

without checking whether there _is_ any css.cgroup.

Right - previously the returned task_group would be always associated with a cgroup. Now, it may not be.

The original task_group() should be made accessible for anything that wants a real cgroup in the scheduler hierarchy, and called from the new task_group() function. Not sure what the best naming convention would be, maybe task_group() and effective_task_group() ?

Paul

#259 lore raw
Quoted 10 lines · Paul Menage
Quoted 7 lines · Linus Torvalds

so sched_debug_show() is apparently calling cgroup_path() with a NULL cgroup. I think it's "print_task()" that is to blame, it does

    cgroup_path(task_group(p)->css.cgroup, ..

without checking whether there _is_ any css.cgroup.

Quoted 7 lines

Right - previously the returned task_group would be always associated with a cgroup. Now, it may not be.

The original task_group() should be made accessible for anything that wants a real cgroup in the scheduler hierarchy, and called from the new task_group() function. Not sure what the best naming convention would be, maybe task_group() and effective_task_group() ?

effective_task_group() works for me. Autogroup (currently at least) only needs to interface with set_task_rq().

A tasty alternative would be to have autogroup be it's own subsystem, with full cgroup userspace visibility/tweakability. I have no idea if that's feasible though. I glanced at cgroup.c, but didn't see the dirt simple I wanted, and quickly ran away.

---
 kernel/sched.c |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
kernel/sched.c +13 -7
Index: linux-2.6/kernel/sched.c
===================================================================
@@ -606,27 +606,33 @@ static inline int cpu_of(struct rq *rq)
  */
 static inline struct task_group *task_group(struct task_struct *p)
 {
-	struct task_group *tg;
 	struct cgroup_subsys_state *css;
 
 	css = task_subsys_state_check(p, cpu_cgroup_subsys_id,
 			lockdep_is_held(&task_rq(p)->lock));
-	tg = container_of(css, struct task_group, css);
+	return container_of(css, struct task_group, css);
+}
 
-	return autogroup_task_group(p, tg);
+static inline struct task_group *effective_task_group(struct task_struct *p)
+{
+	return autogroup_task_group(p, task_group(p));
 }
 
 /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */
 static inline void set_task_rq(struct task_struct *p, unsigned int cpu)
 {
+#if (defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED))
+	struct task_group *tg = effective_task_group(p);
+#endif
+
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	p->se.cfs_rq = task_group(p)->cfs_rq[cpu];
-	p->se.parent = task_group(p)->se[cpu];
+	p->se.cfs_rq = tg->cfs_rq[cpu];
+	p->se.parent = tg->se[cpu];
 #endif
 
 #ifdef CONFIG_RT_GROUP_SCHED
-	p->rt.rt_rq  = task_group(p)->rt_rq[cpu];
-	p->rt.parent = task_group(p)->rt_se[cpu];
+	p->rt.rt_rq  = tg->rt_rq[cpu];
+	p->rt.parent = tg->rt_se[cpu];
 #endif
 }
 
#260 lore raw
Quoted 3 lines · Mike Galbraith

A tasty alternative would be to have autogroup be it's own subsystem, with full cgroup userspace visibility/tweakability.

What exactly do you envisage by that? Having autogroup (in its current incarnation) be a subsystem wouldn't really make sense - there's already a cgroup subsystem for partitioning CPU scheduler groups. If autogroups were integrated with cgroups I think that it would be as a way of automatically creating (and destroying?) groups based on tty connectedness.

We tried something like this with the ns subsystem, which would create/enter a new cgroup whenever a new namespace was created; in the end it turned out to be more of a nuisance than anything else.

People have proposed all sorts of in-kernel approaches for auto-creation of cgroups based on things like userid, process name, now tty, etc.

The previous effort for kernel process grouping (CKRM) started off with a complex in-kernel rules engine that was ultimately dropped and moved to userspace. My feeling is that userspace is a better place for this - as Lennart pointed out, you can get a similar effect with a few lines tweaking in a bash login script or a pam module that's much more configurable from userspace and keeps all the existing cgroup stats available.

Paul

#261 lore raw
In reply to Paul Menage
Quoted 10 lines · Paul Menage
Quoted 7 lines · Linus Torvalds

so sched_debug_show() is apparently calling cgroup_path() with a NULL cgroup. I think it's "print_task()" that is to blame, it does

    cgroup_path(task_group(p)->css.cgroup, ..

without checking whether there _is_ any css.cgroup.

Quoted 7 lines

Right - previously the returned task_group would be always associated with a cgroup. Now, it may not be.

The original task_group() should be made accessible for anything that wants a real cgroup in the scheduler hierarchy, and called from the new task_group() function. Not sure what the best naming convention would be, maybe task_group() and effective_task_group() ?

Right, that doesn't solve the full problem though.

/proc/sched_debug should show these automagic task_groups, its just that there's currently no way to properly name them, we can of course add something like a name field to the struct autogroup thing, but what do we fill it with? "autogroup-%d" and keep a sequence number for each autogroup?

Then the below task_group_path() thing can try the autogroup name scheme if it finds a NULL css.

Something like the below might avoid the explosion:

---
 kernel/sched_debug.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)
kernel/sched_debug.c +14 -14
index 2e1b0d1..9b5560f 100644
@@ -87,6 +87,19 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu,
 }
 #endif
 
+#if defined(CONFIG_CGROUP_SCHED) && \
+	(defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED))
+static void task_group_path(struct task_group *tg, char *buf, int buflen)
+{
+	/* may be NULL if the underlying cgroup isn't fully-created yet */
+	if (!tg->css.cgroup) {
+		buf[0] = '\0';
+		return;
+	}
+	cgroup_path(tg->css.cgroup, buf, buflen);
+}
+#endif
+
 static void
 print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 {
@@ -115,7 +128,7 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 		char path[64];
 
 		rcu_read_lock();
-		cgroup_path(task_group(p)->css.cgroup, path, sizeof(path));
+		task_group_path(task_group(p), path, sizeof(path));
 		rcu_read_unlock();
 		SEQ_printf(m, " %s", path);
 	}
@@ -147,19 +160,6 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
 	read_unlock_irqrestore(&tasklist_lock, flags);
 }
 
-#if defined(CONFIG_CGROUP_SCHED) && \
-	(defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED))
-static void task_group_path(struct task_group *tg, char *buf, int buflen)
-{
-	/* may be NULL if the underlying cgroup isn't fully-created yet */
-	if (!tg->css.cgroup) {
-		buf[0] = '\0';
-		return;
-	}
-	cgroup_path(tg->css.cgroup, buf, buflen);
-}
-#endif
-
 void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
 {
 	s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
#262 lore raw
Quoted 19 lines · Peter Zijlstra
Quoted 10 lines · Paul Menage
Quoted 7 lines · Linus Torvalds

so sched_debug_show() is apparently calling cgroup_path() with a NULL cgroup. I think it's "print_task()" that is to blame, it does

    cgroup_path(task_group(p)->css.cgroup, ..

without checking whether there _is_ any css.cgroup.

Quoted 7 lines

Right - previously the returned task_group would be always associated with a cgroup. Now, it may not be.

The original task_group() should be made accessible for anything that wants a real cgroup in the scheduler hierarchy, and called from the new task_group() function. Not sure what the best naming convention would be, maybe task_group() and effective_task_group() ?

Quoted 7 lines

Right, that doesn't solve the full problem though.

/proc/sched_debug should show these automagic task_groups, its just that there's currently no way to properly name them, we can of course add something like a name field to the struct autogroup thing, but what do we fill it with? "autogroup-%d" and keep a sequence number for each autogroup?

I was considering exactly that for /proc/N/cgroup visibility. Might get thumped if I re-use that file though.

Quoted 63 lines

Then the below task_group_path() thing can try the autogroup name scheme if it finds a NULL css.

Something like the below might avoid the explosion:

---
 kernel/sched_debug.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)
kernel/sched_debug.c +14 -14
index 2e1b0d1..9b5560f 100644
@@ -87,6 +87,19 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu,
 }
 #endif
 
+#if defined(CONFIG_CGROUP_SCHED) && \
+	(defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED))
+static void task_group_path(struct task_group *tg, char *buf, int buflen)
+{
+	/* may be NULL if the underlying cgroup isn't fully-created yet */
+	if (!tg->css.cgroup) {
+		buf[0] = '\0';
+		return;
+	}
+	cgroup_path(tg->css.cgroup, buf, buflen);
+}
+#endif
+
 static void
 print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 {
@@ -115,7 +128,7 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
 		char path[64];
 
 		rcu_read_lock();
-		cgroup_path(task_group(p)->css.cgroup, path, sizeof(path));
+		task_group_path(task_group(p), path, sizeof(path));
 		rcu_read_unlock();
 		SEQ_printf(m, " %s", path);
 	}
@@ -147,19 +160,6 @@ static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
 	read_unlock_irqrestore(&tasklist_lock, flags);
 }
 
-#if defined(CONFIG_CGROUP_SCHED) && \
-	(defined(CONFIG_FAIR_GROUP_SCHED) || defined(CONFIG_RT_GROUP_SCHED))
-static void task_group_path(struct task_group *tg, char *buf, int buflen)
-{
-	/* may be NULL if the underlying cgroup isn't fully-created yet */
-	if (!tg->css.cgroup) {
-		buf[0] = '\0';
-		return;
-	}
-	cgroup_path(tg->css.cgroup, buf, buflen);
-}
-#endif
-
 void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
 {
 	s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
#263 lore raw
In reply to Mathieu Desnoyers
Quoted 30 lines · Mathieu Desnoyers

* Mike Galbraith ([email protected]) wrote:
[...]

Quoted 15 lines
kernel/sched_autogroup.c new file +15 -0
+static void
+autogroup_attach_tty(struct task_struct *p, struct task_group **tg)
+{
+	struct tty_struct *tty = p->signal->tty;
+
+	if (!tty)
+		return;
+
+	*tg = p->signal->tty->tg;
+}
+
+static inline void
+autogroup_check_attach(struct task_struct *p, struct task_group **tg)
+{
+	if (!sysctl_sched_autogroup_enabled || *tg != &root_task_group ||

kernel/sched_autogroup.c line 47

Quoted 10 lines
kernel/sched_autogroup.c new file +10 -0
+			p->sched_class != &fair_sched_class)
+		return;
+
+	rcu_read_lock();
+
+	autogroup_attach_tty(p, tg);
+
+	rcu_read_unlock();
+}
+

Hi Mike,

Quoted 6 lines

This per-tty task grouping approach looks very promising. I'll give it a spin when I find the time. Meanwhile, a little question about locking here: how is the read lock supposed to protect from p->signal (and p->signal->tty) modifications ? What's the locking scheme here ? So maybe just simple rcu_dereference are missing, or maybe the tsk->sighand->siglock might be required. In all cases, I feel something is missing there.

My assumption is that no additional locking is needed. The tty is refcounted, dropped in release_task()->__exit_signal(), at which point the task is unhashed, is history. The tty can't go away until the last task referencing it goes away.

-Mike

#264 lore raw
In reply to Mike Galbraith
Quoted 1 line · Mike Galbraith

Comments, suggestions etc highly welcome.

I've tested your patch and it runs smoothly on my machine. However I had several NULL pointer dereference BUGs that happened when I left X or rebooted my system. I think this is caused by your patch. There is nothing in the logs unfortunately, but I scribbled down the following by hand (not the whole trace, I'm too lazy):

BUG: unable to handle NULL pointer dereference at 0..038
IP:   pick_next_task_fair 0xa7/0x1a0
...
Call Trace: schedule 

...

#265 lore raw
Quoted 10 lines · Markus Trippelsdorf
Quoted 1 line · Mike Galbraith

Comments, suggestions etc highly welcome.

I've tested your patch and it runs smoothly on my machine. However I had several NULL pointer dereference BUGs that happened when I left X or rebooted my system. I think this is caused by your patch. There is nothing in the logs unfortunately, but I scribbled down the following by hand (not the whole trace, I'm too lazy):

Quoted 5 lines
BUG: unable to handle NULL pointer dereference at 0..038
IP:   pick_next_task_fair 0xa7/0x1a0
...
Call Trace: schedule 

...

Hm. Not much I can do without the trace, but thanks for testing and reporting anyway, guess I need to do some heavy stress testing. I'm re-writing it as I write this anyway.

thanks,

-Mike