Local array size limitation in kernel

Local array size limitation in kernel

Post by Timur Aydi » Sun, 17 Jun 2001 05:09:57



Hi,

I am developing a kernel module that takes chunks of data, each up to 16
kbytes, from a user mode process. The module stores the data temporarily in
a char array that is defined locally in a function:

int get_data(char* puser)
{
    char temp[16384];

    /* copy data from user's pointer to temp */

   /* Acquire spinlock */

   /* process data in temp */

   /* copy processed temp to card memory */

   /* release spinlock */

Quote:}

If I use this module, the system becomes very unstable and the symtoms vary
greatly each time. Sometimes, the system freezes, sometimes the process
becomes a zombie, sometimes certain features of the windows manager stop
working, while everything else is fine.

I though that this could be a stack problem and I tried kmalloc'ing the temp
buffer, processing the data and then kfree'ing the temp buffer:

int get_data(char* puser)
{
    char* temp;

   /* kmalloc 16384 bytes of memory at temp */

    /* copy data from user's pointer to temp */

   /* Acquire spinlock */

   /* process data in temp */

   /* copy processed temp to card memory */

   /* release spinlock */

   /* kfree allocated memory at temp */

Quote:}

This time, the module worked flawlessly and the system remained stable. How
would one method not work and the other would work? I wanted to use a local
array to avoid the overhead associated with kmalloc and kfree, but
apparently something is wrong with doing that.

Is there a limitation on how large local arrays can be in the kernel?

And by the way, the data copied is 8191 bytes, so that buffer is only half
full.

Timur.

 
 
 

Local array size limitation in kernel

Post by Ulrich Weiga » Sun, 17 Jun 2001 06:19:13



>This time, the module worked flawlessly and the system remained stable. How
>would one method not work and the other would work? I wanted to use a local
>array to avoid the overhead associated with kmalloc and kfree, but
>apparently something is wrong with doing that.
>Is there a limitation on how large local arrays can be in the kernel?

The total size of the kernel stack (on i386) is about 6k.  This must
be enough for the complete call chain inside the kernel *plus* the
complete call chain of any interrupt handler that might get triggered
while your code is executing.

Practically speaking this means that except under rare conditions,
you should never use more that about 1k of local variables on the
stack ...

--
  Dr. Ulrich Weigand


 
 
 

1. Limitation of array size

Dear all,

        I am new to linux kernel programming and I would like
to know if there is a limitation on the size of array declared
inside a function in the kernel because I experienced the crash
of the system when I try to declare a char array of size greater
than 8192.

        Thank in adv.

With regards,
Wong Tsang

2. mmap

3. hard disk size limitation for kernel 2.2

4. Attempts to TCP ports 110,1080,6670,12345,20034,etc.

5. Linux has limitation on boot kernel (vmlinuz) size?

6. g3 wallstreet does not want to boot

7. Size limitations kernel

8. IP masquarading scripts needed for kernel 2.4.9

9. Array Limitation/Field Separator

10. file size limitations in 2.6

11. BIOS disk size limitation vs Linux and Windows

12. Is there a limitation of "malloc" size?

13. Solaris 9 x86 SCSI drive size limitation?