All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] libudev: Allocate udev_device->envp lazily
Date: Tue, 21 Oct 2008 13:01:41 +0000	[thread overview]
Message-ID: <48FDD2B5.8090609@tuffmail.co.uk> (raw)
In-Reply-To: <48FDAADD.3000809@tuffmail.co.uk>

Bob Beers wrote:
> one small question ...
>
> On Tue, Oct 21, 2008 at 6:11 AM, Alan Jenkins
> <alan-jenkins@tuffmail.co.uk> wrote:
>   
>> Allocate udev_device->envp lazily
>>
>> It's a pity to allocate 128 words when we don't need them.
>> Measured 2% _user_ cpu time reduction on EeePC coldplug.
>>
>> Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
>>
>> diff --git a/udev/lib/libudev-device.c b/udev/lib/libudev-device.c
>> index b54c727..69ab1f7 100644
>> --- a/udev/lib/libudev-device.c
>> +++ b/udev/lib/libudev-device.c
>> @@ -31,6 +31,8 @@
>>  #include "libudev.h"
>>  #include "libudev-private.h"
>>
>> +#define ENVP_SIZE 128
>> +
>>  struct udev_device {
>>        int refcount;
>>        struct udev *udev;
>> @@ -46,7 +48,7 @@ struct udev_device {
>>        struct udev_list_node devlinks_list;
>>        int devlinks_uptodate;
>>        struct udev_list_node properties_list;
>> -       char *envp[128];
>> +       char **envp;
>>        int envp_uptodate;
>>        char *driver;
>>        int driver_set;
>> @@ -611,8 +613,11 @@ void udev_device_unref(struct udev_device *udev_device)
>>        free(udev_device->devpath_old);
>>        free(udev_device->physdevpath);
>>        udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
>> -       for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
>> -               free(udev_device->envp[i]);
>> +       if (udev_device->envp != NULL) {
>> +               for (i = 0; i < ENVP_SIZE && udev_device->envp[i] != NULL; i++)
>> +                       free(udev_device->envp[i]);
>> +               free(udev_device->envp);
>> +       }
>>        info(udev_device->udev, "udev_device: %p released\n", udev_device);
>>        free(udev_device);
>>  }
>> @@ -1014,14 +1019,18 @@ char **udev_device_get_properties_envp(struct udev_device *udev_device)
>>                unsigned int i;
>>                struct udev_list_entry *list_entry;
>>
>> -               for (i = 0; i < ARRAY_SIZE(udev_device->envp) && udev_device->envp[i] != NULL; i++)
>> -                       free(udev_device->envp[i]);
>> +               if (udev_device->envp) {
>> +                       for (i = 0; i < 128 && udev_device->envp[i] != NULL; i++)
>>     
>
> should this 128 also be ENVP_SIZE?
>   

Yes, sorry.  I see Kay fixed it already though :)

Alan

      parent reply	other threads:[~2008-10-21 13:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 10:11 [PATCH] libudev: Allocate udev_device->envp lazily Alan Jenkins
2008-10-21 11:07 ` Kay Sievers
2008-10-21 11:48 ` Alan Jenkins
2008-10-21 12:00 ` Kay Sievers
2008-10-21 13:00 ` Bob Beers
2008-10-21 13:01 ` Alan Jenkins [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48FDD2B5.8090609@tuffmail.co.uk \
    --to=alan-jenkins@tuffmail.co.uk \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.