[PATCH linux-2.6.12-rc2-mm3] smc91c92_cs: Reduce stack usage in smc91c92_event()

Denis Vlasenko vda at port.imtp.ilyichevsk.odessa.ua
Tue Apr 26 08:54:50 EDT 2005


> > IOW, I wouldn't do this:
> > 
> > struct big {
> >        large_t large;
> >        huge_t huge;
> > };
> > 
> > int f() {
> >        struct big *local;
> >        local = kmalloc(sizeof(big),...);
> >        ...
> > }
> > 
> > int g() {
> >        struct big *local;
> >        local = kmalloc(sizeof(big),...);
> >        ...
> > }
> > 
> > For one, what will happen when you will need to add
> > another local in one function only?
> 
> struct another_local_struct *another_local;
> another_local = kmalloc(sizeof(sruct another_local_struct),...);

two kmalloc. two pointers, two registers used for them. On i386
we have only 6 available registers (sometimes 7 with omit-stack-ptr).

I did look on the resulting assembly. Single pointer
for all kmalloc based locals is looking very nice.

> or if single kmalloc is preferred, then:
> 
> struct another_big_struct {
>   struct old_big_struct old_big;
>   struct new_big_struct new_big;
> } ;

I assume you will have
"struct another_big_struct *local;"

Then you will also need to replace
	local->some_var => local->old_big->some_var
everywhere for each member of old_big.

In other words: it is not very easy for you
to add new members to kmalloc'ed locals
(or to move some remaining on-stack locals to
kmalloc space).

On the contrary, I will need to do only this:

int g() {
        struct {
                large_t large;
                huge_t huge;
+               struct new_big_struct n;
        } *local;
        local = kmalloc(sizeof(*local),...);
        ...
}

Just one line! (+ of course any changes for which new_big_struct
was introduced in the first place).
--
vda




More information about the linux-pcmcia mailing list