Messages in this thread | | | Date | Tue, 22 Aug 2006 11:55:40 -0700 | From | Paul Jackson <> | Subject | Re: [PATCH 7/7] CPU controller V1 - (temporary) cpuset interface |
| |
Mike wrote: > By cat'ing each task pid > (including init's) to root (or mikeg) task's file?
I guess you meant: echo'ing not: cat'ing
Lets say for example one has cpusets: /dev/cpuset /dev/cpuset/foo
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 do /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 option:
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 do sed -nu p < /dev/cpuset/foo/tasks > /dev/cpuset/tasks done
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@sgi.com> 1.925.600.0401 - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |