[RFC] fast atomic ps

From: Borislav Deianov (borislav@lix.polytechnique.fr)
Date: Wed Apr 05 2000 - 17:42:27 EST


Hi,

A while ago there was a patch by Erik Andersen that implemented a
/dev/ps device as a small functional replacement of /proc for embedded
systems. I'd like to propose another way of implementing such a device
that is also small and solves a couple of other problems as well:

- Reading and parsing the entire /proc tree is quite slow, as a result
top uses way too much CPU time on busy systems;

- If there is a lot of process activity (creation and death) while the
/proc tree is being read, the resulting view of the system is often
inconsistent. Imagine, for example, a program which does this:

        while(1) {
                for (i=0; i<1000; i++);
                if (fork())
                        exit(0);
        }

It's possible that ps fails to show _any_ copies of this nasty if the
pid changes from high to low at exactly the right time.

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:

- when you open the device, the driver allocates some memory and
        copies all the data from /proc atomically;
- you can read the data at your leisure, it doesn't change
        under you (in most cases a single read call is enough);
- the memory for the snapshot is released when the device is closed;
- many processes can open the device at the same time, they get
        separate snapshots.

I've attached a very preliminary implementation of the kernel driver
and a proof of concept ps that uses it. If there's interest I'll code
a more complete patch.

Best wishes,
Borislav





-
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:15 EST