Why PIDs?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Why PIDs?

Post by gerryg400 »

How about doing it the other way. You have pointers as PIDs but the kernel validates the pointer for every system call. Basically, you can have a hash lookup of the pointer and if the pointer doesn't exist as a key, the pointer is invalid.
The problem with pointers as pids is that pointers get re-used too quickly. 2 processes may be waiting for a pointer pid. The first will perhaps get the right one, the second may get a re-used pointer. This is especially bad in kernels where data structures are recycled often for efficiency. Pids on the other hand are not re-used until every pid has been used.

Also, I'm not sure that there is a speed benefit. As you said, hashing and validation will be required on every system call. And there are some tricks to speed up bitmap search so that linear search in bitmaps is minimised.
If a trainstation is where trains stop, what is a workstation ?
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Why PIDs?

Post by OSwhatever »

gerryg400 wrote:
How about doing it the other way. You have pointers as PIDs but the kernel validates the pointer for every system call. Basically, you can have a hash lookup of the pointer and if the pointer doesn't exist as a key, the pointer is invalid.
The problem with pointers as pids is that pointers get re-used too quickly. 2 processes may be waiting for a pointer pid. The first will perhaps get the right one, the second may get a re-used pointer. This is especially bad in kernels where data structures are recycled often for efficiency. Pids on the other hand are not re-used until every pid has been used.

Also, I'm not sure that there is a speed benefit. As you said, hashing and validation will be required on every system call. And there are some tricks to speed up bitmap search so that linear search in bitmaps is minimised.
I was thinking about this problem and you could basically mangle the pointer. You can get the time stamp at the thread creation, store the timestamp. Using the time stamp you could use some obscure algorithm that encrypts the pointer. Then you definitely have a pretty unique threadID/pointer.

Ok, then it's not pointers anymore but more PIDs again but you have removed the step where you need to allocate a PID. At system calls you use the mangled pointer/PID in the hash lookup, then you decrypt it using the time stamp in order to get the proper pointer.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Why PIDs?

Post by Owen »

Oh good god.

If you have a hash table... why not just key off the PID and store the actual address of the process structure in it?

You seriously sound like the complicator
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: Why PIDs?

Post by OSwhatever »

Owen wrote:Oh good god.

If you have a hash table... why not just key off the PID and store the actual address of the process structure in it?

You seriously sound like the complicator
I think we're talking about the same thing actually, since that is what I suggested.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Why PIDs?

Post by gerryg400 »

OSwhatever, as you can see, once all problems are addressed the solutions converge. As I said there are very efficient ways to remove the need for long linear searches through the pid bitmap. For me the deciding factor in using the 'small integer pid' was the fact that 'small integer pids' are more readable. During debugging my O/S I became used to pid=1=memory_manager, pid=2=fs_manager, pid=3=console_manager etc.

And later on when, god willing, real users use your system, kill -9 1328 is nicer than kill -9 0xffffffffcf023b40
If a trainstation is where trains stop, what is a workstation ?
Post Reply