Re: devctl (alike?) for devfs



On Tue, May 13, 2008 at 10:04:56PM +0300, Andriy Gapon wrote:
on 12/05/2008 00:48 Kostik Belousov said the following:
No, we do not have a leak, but we have somewhat non-obvious behaviour.

The cdev structure is freed only after the last reference to cdev is
gone. Typical holder of the reference is the devfs vnode. In the normal
usage, the vnode is present until both the device is destroyed _and_
devfs_populate_loop() run is performed. This function actually reclaim
the vnodes for destroyed devices, that causes last reference to cdev to
be dropped and memory freed.

The populate loop is called syncronously from the upper levels. The
easiest method to trigger it is to do ls /dev, since it is called from
the devfs_lookupx().

Thank you for the explanation! ls did trigger DESTROY notifications.
But this arbitrary delay between device entry going away and
notification about about it is a little bit "uncool".

So I re-wrote the patch to post notifications about deleted devices with
si_refcount > 0 in a fashion similar to how si_refcount=0 devices are
freed. I put those cdev-s onto a special list (re-/ab-using si_siblings
LIST link field) and bump their si_refcount to prevent them from getting
destroyed before the notification is sent (it would need si_name).
Then, in dev_unlock_and_free() I send notifications and call dev_rel on
the devices.

I am not entirely satisfied with the code:
1. I don't like the way I move LIST elements from one head to the other,
this should be a macro in queue.h
2. I am not sure about the names I picked
3. I slightly don't like a fact that parent-child destroy notifications
are sent in reverse order because of my simplistic LIST usage.

I looked at your previous patch, and it seems it is much simpler to
do drop the devmtx once more then to try to abuse free lists.
In the destroy_devl(), after the

while (dev->si_threadcount != 0) {
/* Use unique dummy wait ident */
msleep(&csw, &devmtx, PRIBIO, "devdrn", hz / 10);
}

loop, add

mtx_unlock(&devmtx);
if (!cold)
devctl_notify("DEVFS", dev->si_name, "DESTROY", NULL);
mtx_lock(&devmtx);

Attachment: pgpJyXrqkPL52.pgp
Description: PGP signature



Relevant Pages

  • Re: devctl (alike?) for devfs
    ... The cdev structure is freed only after the last reference to cdev is ... Typical holder of the reference is the devfs vnode. ... in dev_unlock_and_freeI send notifications and call dev_rel on the devices. ... I slightly don't like a fact that parent-child destroy notifications are sent in reverse order because of my simplistic LIST usage. ...
    (freebsd-hackers)
  • Re: does python have useless destructors?
    ... >> between disposing at the end of the function or when some containing ... and in CPython that happens at the moment the last reference is ... C Python destroys an object when no references are left. ... IronPython destroy objects when the underlying garbage collector feels like ...
    (comp.lang.python)
  • Re: Application crashes on handled error. Why?
    ... but terminate events on those objects are not fired. ... call no more than one method and destroy immediately. ... >> I am not too happy about zapping a reference to a Parent in a Child ...
    (microsoft.public.vb.general.discussion)
  • Re: Function Returning a local object???
    ... > class MFVec { ... > MFVec(float x, float y); ... not destroy it). ... a invalid reference. ...
    (comp.lang.cpp)
  • Re: Strange Problems with VBA
    ... This causes a conflict when you try to rename a form to the ... "Forms" collection or run the test form and save a reference to the object ... it you can find the reference and destroy the form and set it's reference to ... "David C. Holley" wrote in message ...
    (microsoft.public.office.developer.vba)