[PLUG] multiple CPU's and process assignment

Chris Jantzen chris at maybe.net
Tue Jan 27 21:50:03 UTC 2004


On Tue, Jan 27, 2004 at 07:17:00PM -0800, Josh Orchard wrote:
> > On Tue, Jan 27, 2004 at 02:26:50PM -0800, Josh Orchard wrote:
> >> I have a linux box with multiple CPU's.  How do I assign a process
> >> to
> >> one cpu?
> >
> > The default Linux kernel doesn't have processor affinity (yet--there
> > are patches, if you're interested). Your processes will be balanced
> > across both CPU's automatically.
> 
> That is nice.  But I don't want the OS to automatically balance.  I
> want to select which processor the process will use.  I do this on our
> windows servers assigning the affinity in the task manager.  I'm sure
> there is some way in Linux.  I know I need the SMP processor for linux
> but don't know how to tell the OS to only have this process use a
> particular process only.

Yeah, I know.

> Is there such a way?  A tool?  A config file?  Not possible?

It is possible, though you'll need heavy patching in 2.4 and moderate
patching with a 2.6 kernel.

Aside: If you really do have >= 8 processors, skip the following
paragraph as you likely know it already. Others on the list may find
it interesting. And while I think I'm right, I'm not a CE, just a
CS/Math. :-)

It's not been a highly motivated feature, because in SMP systems that
are 4-way and below, you really won't see much of a performance
difference with user-controlled processor affinity. The only small
benefit you'll get is avoiding some cache flushes. Linux already does
a good job minimizing TLB flushes (and you'll get those even in UP
systems -- it's a fact of life for "multitasking"). And on small SMP
systems, the hardware will do cacheline snooping between the
processors, minimizing a CPU jump cost. (As I understand it.) In other
words, SMP hardware is *designed* for processor hopping.

Now, what you have in Windows is a throw down from larger enterprise
situations where all this really does matter, i.e., you shouldn't use
it in Windows for quads and below, either. Like Linux, increasingly,
Windows can run on really big systems. When your RAM isn't close
enough to a processor group such that they can snoop or when RAM
fetches are going to be longer, it does make sense to hint to the
scheduler that certain applications should be held together in the
same processor(s).

If you still really, really want to, I can do some further research
for you. It will be non-trivial until well into late-2.6 or 2.8
timeframe.

Again: As I Understand It.(tm) I've followed the kernel-traffic
summaries, and I understand that all of this is covered very well in
various flavors of the kernel, but that the mainline release is still
much more conservative with respect to NUMA features.

As far as how it works, iirc in one of the patches it was something
simple like:

If we assume the process pid in question is, say "543"; and assume you
want to bind it to processor "13", you would do

echo 13 > /proc/543/processor_affinity

(Oddly, I have a PPro system who's MPS tables list the two CPU's as
"0" and "13" and none else. And /proc/cpuinfo lists them like that. Go
figure.)

-- 
chris kb7rnl =->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.pdxlinux.org/pipermail/plug/attachments/20040127/5db374c8/attachment.asc>


More information about the PLUG mailing list