NOMMU: stack versus malloc?

Jate Sujjavanich jsujjavanich at syntech-fuelmaster.com
Tue Oct 9 22:07:53 UTC 2007


The m68knommu device (Coldfire 5235) I've been working on has 16 MB of
SDRAM, so fragmentation has been more of an issue for me than overall
memory usage on uClinux. I say do things to reduce the memory usage
without increasing fragmentation. On a system with less memory, it will
eventually make your usable memory smaller no matter what total you have
free.

If you have a large buffer that must be used very often, I think you
should malloc it once, make it static/force it into the data section, or
place it on the stack. If it will be used only rarely, you might get
away with with malloc'ing the small number of times it's used.

Incidentally, the dreaded "unable to allocate memory" due to
fragmentation reared its ugly head when I was debugging busybox/msh
yesterday. After I restarted msh around 10 times.

- Jate S.

-----Original Message-----
From: busybox-bounces at busybox.net [mailto:busybox-bounces at busybox.net]
On Behalf Of Denys Vlasenko
Sent: Tuesday, October 09, 2007 4:34 PM
To: Bernhard Fischer
Cc: busybox at busybox.net
Subject: Re: NOMMU: stack versus malloc?

On Tuesday 09 October 2007 20:41, Bernhard Fischer wrote:
> On Tue, Oct 09, 2007 at 02:56:49PM -0400, Mike Frysinger wrote:
> >On Tuesday 09 October 2007, Denys Vlasenko wrote:
> >> A question to people who work with NOMMU machines:
> >>
> >> Obviously, having small stack usage is important for small, NOMMU 
> >> machines.
> >>
> >> However, after a certain point you cannot just eliminate stack 
> >> usage, you must move it to other storage.
> >>
> >> For example, lineedit.c currently eats 12k+ if stack.
> >>
> >> I can convert it into malloc use.
> >>
> >> Question: is it better or actually worse?
> >> Line editing is invoked repeatedly, and repeated malloc/free of 
> >> random-sized blocks can increase fragmentation
> >> -> increase memory consumption.
> >
> >it really depends on the size of the consumption ... on nommu, the 
> >default stack is 4k, so i'd say if you're talking about more than 1k,

> >it should be a malloc ...

Ick... We have lots of ~4k stack users... and Makefile sets stack to 20k
IIRC, correct me if I'm wrong:

# Busybox is a stack-fatty so make sure we increase default size # TODO:
use "make stksizes" to find & fix big stack users # (we stole
scripts/checkstack.pl from the kernel... thanks guys!) FLTFLAGS += -s
20000

> AFAIK there was RESERVE_CONFIG_BUFFER for (potentially big) stack
users.

Yes. But it looks like _nobody_ benefits from big objects on stack.
So I intend to gradually move big stack users to malloc.
--
vda
_______________________________________________
busybox mailing list
busybox at busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox



 
 
************************************************************************
************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals &
computer viruses.
************************************************************************
************






More information about the busybox mailing list