mdev -i ready for testing

Isaac Dunham ibid.ag at gmail.com
Sat Apr 4 04:50:18 UTC 2015


On Sat, Mar 21, 2015 at 03:49:13PM +0000, Isaac Dunham wrote:
> > 
> > >Well, I've poked at this a little this evening.
> > >
> > >See
> > >https://github.com/idunham/busybox
> > >(in branch mdev) if you're curious about details.
> 
> This is ready for testing now: it works for me and I've tidied
> it up a bit.

And I experimented with using the environment again, and have something
that seems more suitable.
See below for an explanation.
Same repo, different branch (branch "experimental").

> On Fri, Mar 20, 2015 at 10:04:19AM +0100, Laurent Bercot wrote:
> >  A few comments:
> > 
> >  - Original mdev relies on getenv/putenv to handle environment
> > variables; that's okay, because it's a short-lived program.
> > But mdev -i is a long-lived program, so using and modifying its
> > own environment for every event is conceptually unsatisfying, and
> > ends up in a lot of unnecessary malloc/free/reallocs. It would be
> > faster and more memory-efficient to allow handle_event to work with
> > the raw string containing the VAR=VALUE\0 pairs.
> >  I realize it may require modifying all the getenv() invocations in
> > the rest of mdev, but I believe it's worth it. (Heavy getenv()
> > usage in mdev was one of the parts that made me postpone my plans of
> > modifying it myself...)
> 
> I've done this, at a cost of at least 70 bytes (it's actually over 100
> bytes for just that bit, minus about 30 bytes for some tidying up.)
> 
> There's one getenv() call that's left in handle_event(), but that's
> deliberate: SEQNUM only applies to the hotplugger.
> 
> I *think* I could simplify mdev -s and make it feature-equivalent to
> hotplugging by rewriting fileAction() to read a uevent file, replace
> \n with \0, and call handle_event().

..and I realized the problem here.
The point of loading variables into the environment is that we want
helper programs to have access to them.
mdev -i *cannot* ignore environment rules like mdev -s currently does,
or we would lose the ability to autoload modules.

So we could load variables as needed (right before starting a helper)
while using a buffer, which is probably *another* ~50-100 bytes since
it's adding a conditional "load variables" section;
or we can load the buffer into the environment in the first place, use
getenv(), and *save* at least a hundred bytes.

However, it wasn't a waste, because there was a lot of refactoring that
resulted. That seems to have reduced the cost of mdev -i to ~485 bytes,
besides making a simpler "mdev -s" more practical...

Speaking of that, I've adjusted "mdev -s" so that it will load the uevent
file and use the same codepath as "mdev -i" (FEATURE_MDEV_NEWSCAN is the
config symbol).
This costs 0 bytes with mdev -i disabled, and shrinks mdev by 129 bytes
with mdev -i enabled.

Practically speaking, this means that you don't have to worry about
missing variables that apply to the current event:
MODALIAS et al. are set, even when you run mdev -s.
Of course that will necessarily slow things down on boot if you use 
$VAR=.* rules, since you need to run regexec repeatedly.

Code is in git://github.com/idunham/busybox, branch experimental.

And I'm a bit tired and an amateur programmer, so there may still be
stuff that needs tidying up; but it works for me.

Thanks,
Isaac Dunham



More information about the busybox mailing list