Discussion:
memory leakage
farajian amin
2010-02-10 10:04:44 UTC
Permalink
Dear All,

I have experienced a memory leakage when i use busybox-1.14.1 on Snapgear linux( for leon architecture) (kernel 2.6.21.1). I am not quite sure that if this is a busybox problem or kernel. The problem is as follows:

when we run the following script in busybox (ash) , the memory leak appears , and kill all mem at end.
---------------------------------
#!/bin/ash
while [ 1 ];
do
GATEWAY=`iproute | grep default | awk '{print $3}'
done

---------------------------------

Of course we are not going to run this script in an endless loop without sleep, but we run it in specific periods of time.
Note1: when we run "iproute | grep default " with out awk and GATEWAY variable THERE IS NO memory leakage.
Note2: when we run "iproute | grep default | awk'{print$3}' without saving it in GATEWAY variable there is memory leakage.
Note3: when we run "iproute | grep default" and save its out put in GATEWAY variable THERE IS memory leakage.

we have checked busybox 1.15.3 and we faced the same problem.

Is it a kernel or busybox shell problem?

Thanks in Advance.
Amin Farajian
Rob Landley
2010-02-10 11:03:32 UTC
Permalink
Post by farajian amin
Dear All,
I have experienced a memory leakage when i use busybox-1.14.1 on Snapgear
linux( for leon architecture) (kernel 2.6.21.1). I am not quite sure that
when we run the following script in busybox (ash) , the memory leak appears
, and kill all mem at end. ---------------------------------
#!/bin/ash
while [ 1 ];
do
GATEWAY=`iproute | grep default | awk '{print $3}'
done
To properly diagnose it, you could throw "top -n1" in the loop and see how
much memory usage grows. (Unfortunately, I don't see a way to tell busybox
top to sort by memory usage from the command line, the way hitting "m" when
it's interactive does. You'll probably need "top -n1 -b" and something to
parse the output. On the device side of things would be good if you're
talking to the device through a serial console and it takes a while to
trigger...)

That should tell you if a long-lived process (such as ash) is leaking memory.

There are a bunch of advanced techniques, of course, but that's a first quick
smoketest.

Building "screen" for your target (or dropbear) is another nice way to get
diagnostic info, although they'll drive it into OOM sooner since they use up
memory themselves, and I dunno how friendly either is to a nommu system.

If you can eliminate userspace processes, then that leaves a kernel leak.
Those are fiddlier, but they're not a busybox issue so we get to plead the 5th
about 'em here...

Rob
--
Latency is more important than throughput. It's that simple. - Linus Torvalds
Denys Vlasenko
2010-02-10 15:11:01 UTC
Permalink
Post by Rob Landley
Post by farajian amin
Dear All,
I have experienced a memory leakage when i use busybox-1.14.1 on Snapgear
linux( for leon architecture) (kernel 2.6.21.1). ?I am not quite sure that
when we run the following script in busybox (ash) , the memory leak appears
, and kill all mem at end. ---------------------------------
#!/bin/ash
while [ 1 ];
do
? ? GATEWAY=`iproute | grep default | awk '{print $3}'
done
To properly diagnose it, you could throw "top -n1" in the loop and see how
much memory usage grows. ?(Unfortunately, I don't see a way to tell busybox
top to sort by memory usage from the command line, the way hitting "m" when
it's interactive does. ?You'll probably need "top -n1 -b" and something to
BTW try hitting 's', it's way better than 'm' :)
Post by Rob Landley
parse the output. ?On the device side of things would be good if you're
talking to the device through a serial console and it takes a while to
trigger...)
No need to parse anything. There is an applet (which you found "useless"
some years ago) which makes this sort of monitoring easy:

# nmeter '%t %c mem %m free %[mf] processes %[pn]'
16:10:05 UU........ mem 526m free 1.4g processes 276
16:10:06 U......... mem 526m free 1.4g processes 276
16:10:07 .......... mem 526m free 1.4g processes 276
...


--
vda
Rob Landley
2010-02-11 03:05:24 UTC
Permalink
Post by Denys Vlasenko
No need to parse anything. There is an applet (which you found "useless"
# nmeter '%t %c mem %m free %[mf] processes %[pn]'
16:10:05 UU........ mem 526m free 1.4g processes 276
16:10:06 U......... mem 526m free 1.4g processes 276
16:10:07 .......... mem 526m free 1.4g processes 276
...
This functionality is built into the stock version of top, but nobody ever
bothered to make a UI to access it from the command line in busybox's version.
Instead, busybox has a utility that isn't in stock Linux distros, which
duplicates functionality from top but which requires learning a new printf-
like syntax to make it work.

Not my first choice of a design approach, no. Still, as long as it's already
there that guy might find it useful...

Rob
--
Latency is more important than throughput. It's that simple. - Linus Torvalds
Doug Clapp
2010-02-11 21:25:45 UTC
Permalink
Post by Rob Landley
Post by Denys Vlasenko
No need to parse anything. There is an applet (which you found "useless"
# nmeter '%t %c mem %m free %[mf] processes %[pn]'
16:10:05 UU........ mem 526m free 1.4g processes 276
16:10:06 U......... mem 526m free 1.4g processes 276
16:10:07 .......... mem 526m free 1.4g processes 276
...
This functionality is built into the stock version of top, but nobody ever
bothered to make a UI to access it from the command line in busybox's version.
Instead, busybox has a utility that isn't in stock Linux distros, which
duplicates functionality from top but which requires learning a new printf-
like syntax to make it work.
Not my first choice of a design approach, no. Still, as long as it's already
there that guy might find it useful...
Rob
What about using the applet free to monitor memory usage? If using a
recent-enough version of busybox, watch could be used to repeat the
invocation periodically. Otherwise a while loop could do the same; for
example:

# while [ 1 ] ; do date;free; sleep 5; done
Thu Feb 11 16:04:58 EST 2010
total used free shared buffers
Mem: 482988 450564 32424 0 22132
Swap: 131064 131056 8
Total: 614052 581620 32432
Thu Feb 11 16:05:03 EST 2010
total used free shared buffers
Mem: 482988 450532 32456 0 22132
Swap: 131064 131056 8
Total: 614052 581588 32464
Thu Feb 11 16:05:08 EST 2010
total used free shared buffers
Mem: 482988 450540 32448 0 22132
Swap: 131064 131056 8
Total: 614052 581596 32456
^C


The original request gave the offending command sequence as

GATEWAY=`iproute | grep default | awk '{print $3}'



To my mind that contains one extra command. For efficiency I would write

GATEWAY=`iproute | awk '/default/{print $3}' `

Using busybox 1.15.3 I just ran that sequence numerous times and saw no
memory leakage that I could detect with the free command. I used
busybox ash, busybox iproute and busybox awk, as well as busybox free.
My kernel is 2.6.25.16 running on an AMD Sempron processor.

Doug Clapp

Loading...