Re: [PATCH 7/7] CPU controller V1 - (temporary) cpuset interface
From: Paul Jackson
Date: Tue Aug 22 2006 - 14:53:33 EST
> By cat'ing each task pid
> (including init's) to root (or mikeg) task's file?
I guess you meant:
Lets say for example one has cpusets:
One cannot move the tasks in 'foo' to the top (root) cpuset by doing:
cat < /dev/cpuset/foo/tasks > /dev/cpuset/tasks # fails
That cat fails because the tasks file has to be written one pid at a
time, not in big buffered writes of multiple lines like cat does.
The usual code for doing this move is:
while read i
/bin/echo $i > /dev/cpuset/tasks
done < /dev/cpuset/foo/tasks
There is a cute trick that lets you move all the tasks in one cpuset to
another cpuset in a one-liner, by making use of the "sed -u" unbuffered
sed -nu p < /dev/cpuset/foo/tasks > /dev/cpuset/tasks # works
For serious production work, the above is still racey. A task could be
added to the 'foo' cpuset when another task in 'foo' forks while the
copying is being done. The following loop minimizes (doesn't perfectly
solve) this race:
while test -s /dev/cpsuet/foo/tasks
sed -nu p < /dev/cpuset/foo/tasks > /dev/cpuset/tasks
The above loop is still theoretically racey with fork, but seems to
work in practice.
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@xxxxxxx> 1.925.600.0401
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/