Re: [RFC] fast atomic ps

From: almesber@lrc.di.epfl.ch
Date: Fri Apr 07 2000 - 16:10:54 EST


Borislav Deianov wrote:
> In summary, I'd like something that is 1) small, 2) fast, 3) provides
> an atomic snapshot of all the information in /proc/<pid>/*. I propose
> a device /dev/procsnap that behaves as follows:

Fast and atomic isn't easy.

> - when you open the device, the driver allocates some memory and
> copies all the data from /proc atomically;

This is slow. You may have to force out user pages and shrink caches
to allocate all this. Also, it may be good to avoid holding
tasklist_lock during all this (for latency).

I'd drop the atomic requirement. You can do a few consistency checks
in user space to filter out the worst cases, e.g. process A forks B,
but you've read past A at the time you see B, so you don't have the
parent -> if you have processes without parent, re-read /proc and
only pick those (and their parents). You also need to tack parent
changes in the child.

If you want a reasonably efficient atomic read, you need to isolate
changes, e.g.

 - put a generation number into each task_struct
 - generation number is assigned at fork time, incremented whenever
   you open /dev/procsnap:
   *(int *) &filp->private_data = atomic_read(&global_gen_num);
   atomic_inc(&global_gen_num);
 - you only retrieve entries with
   tsk->gen_num <= *(int *) &filp->gen_num
 - deletion of processes with tsk->gen_num <= atomic_read(&global_gen_num)
   is delayed until after you close /dev/procsnap

The last item is expensive and allows obvious DoS attacks. You already
get fairly good consistency even without it, e.g. the "no parent" case
is already solved by not showing additions after open.

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, ICA, EPFL, CH       werner.almesberger@ica.epfl.ch /
/_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Apr 07 2000 - 21:00:19 EST