Re: [PATCH 2.6.11-rc3-mm2] connector: Add a fork connector

From: Andrew Morton (akpm_at_osdl.org)
Date: 02/23/05

  • Next message: Andrew Morton: "Re: [rft/update] r8169 changes in 2.6.x"
    Date:	Wed, 23 Feb 2005 01:07:47 -0800
    To: Guillaume Thouvenin <guillaume.thouvenin@bull.net>
    
    

    Guillaume Thouvenin <guillaume.thouvenin@bull.net> wrote:
    >
    > Hello,
    >
    > This patch replaces the relay_fork module and it implements a fork
    > connector in the kernel/fork.c:do_fork() routine. The connector sends
    > information about parent PID and child PID over a netlink interface. It
    > allows to several user space applications to be informed when a fork
    > occurs in the kernel. The main drawback is that even if nobody listens,
    > message is send. I don't know how to avoid that.

    We really should find a way to fix that. Especially if we want all the
    distributors to enable the connector in their builds (we do).

    What happened to the idea of sending an on/off message down the netlink
    socket?

    > +#ifdef CONFIG_FORK_CONNECTOR
    > +#define FORK_CN_INFO_SIZE 64
    > +static inline void fork_connector(pid_t parent, pid_t child)
    > +{
    > + struct cb_id fork_id = {CN_IDX_FORK, CN_VAL_FORK};

    This can be static const, which will save some stack and cycles.

    > + static __u32 seq; /* used to test if we lost message */
    > +
    > + if (cn_already_initialized) {
    > + struct cn_msg *msg;
    > + size_t size;
    > +
    > + size = sizeof(*msg) + FORK_CN_INFO_SIZE;
    > + msg = kmalloc(size, GFP_KERNEL);
    > + if (msg) {
    > + memset(msg, '\0', size);

    Do we really need to memset the whole thing?

    > + memcpy(&msg->id, &fork_id, sizeof(msg->id));
    > + msg->seq = seq++;

    `seq' needs a lock to protect it. Or use atomic_add_return(), maybe.

    > + msg->ack = 0; /* not used */
    > + /*
    > + * size of data is the number of characters
    > + * printed plus one for the trailing '\0'
    > + */
    > + msg->len = snprintf(msg->data, FORK_CN_INFO_SIZE-1,
    > + "%i %i", parent, child) + 1;

    scnprintf() would be more appropriate here, even though it should be a "can't
    happen".

    > + cn_netlink_send(msg, CN_IDX_FORK);
    > +
    > + kfree(msg);

    `msg' is only 84 bytes and do_fork() has a shallow call graph. Make `msg'
    a local?

    -
    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/


  • Next message: Andrew Morton: "Re: [rft/update] r8169 changes in 2.6.x"

    Relevant Pages

    • Re: [PATCH 2.6.11-rc3-mm2] connector: Add a fork connector
      ... >> information about parent PID and child PID over a netlink interface. ... >> allows to several user space applications to be informed when a fork ... The main drawback is that even if nobody listens, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [patch 1/2] fork_connector: add a fork connector
      ... > by the time do_exitoccurs the parent may have disappeared ... forking parent pid in another task_struct field at fork time (didn't ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: mremap() bug IMHO not in 2.2
      ... > Just guessing, but would a zero-length vma be rounded up to a page, and ... vma's (fork() and exit()) simply knows that a vma can never be ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [Lse-tech] [patch] sched-domain cleanups, sched-2.6.5-rc2-mm2-A3
      ... > multithreaded OpenMP STREAM running its childs first on the same node ... i believe the fix we want is to pre-balance the context at fork() time. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: deferred rss update instead of sloppy rss
      ... Linus Torvalds wrote: ... >>The problem is then that the proc filesystem must do an extensive scan ... Then, at fork, you just finish the forkwith ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)