Re: Do I need kswapd if I don't have swap?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

intresting this is your printf's dont line up with what has
been printed.

the linux kernel uses an overcommit memory managment mathod
which allows a machine to appear to have
more ram that it thinks this is where to swap becomes
usefull.

However several other things will use this same memory
managment type which is in kwapd so it becomes required.

What i would think that could be happening is that
the program starts to allocate memory using malloc then the
memory only becomes maps to the process when you touch it with
buf[j] = j % 256;

But when you alloc an extra page on the next call to malloc it
will touch the page the kernel will try to map pysical memory
to the virtal page which it cannot find because it cannot
since it cannot free any memory because there is no swap space
it will end up in a possible loop.

What should really happen is that something should be killed
by the kernel's oom killer or the malloc should fail.
But if its overcommiting the malloc will never fail.

hope this helps a little

	James

On Sat, 22 Nov 2003, David Wuertele wrote:

> Running 2.4.18 in an embedded system (32MB RAM, no swap), malloc()
> goes bye-bye:
> 
>   /* Malloc as much as possible, then return */
>   #include <stdio.h>
>   #define UNIT 1024		/* one kilobyte */
>   int main ()
>   {
>     unsigned int j, totalmalloc=0, totalwrote=0, totalread=0;
>     while (1) {
>       unsigned char *buf = (unsigned char *) malloc (UNIT);
>       if (!buf) return 0;
>       totalmalloc += UNIT; fprintf (stderr, "%u ", totalmalloc);
>       for (j=0; j<UNIT; j++) buf[j] = j % 256;
>       totalwrote += UNIT; fprintf (stderr, "%u ", totalwrote);
>       for (j=0; j<UNIT; j++) if (buf[j] != (j % 256)) return -1;
>       totalread += UNIT; fprintf (stderr, "%u\n", totalread);
>     }
>   }
> 
> I expected this program to malloc most of my embedded MIPS's 32MB of
> system RAM, then eventually return with a -1 or a -2.  Unfortunately,
> it hangs having finally printed:
> 
>   M26916864
>   W26916864
>   R26916864
> 
> The malloc call isn't even returning.  What could explain that?
> 
> I don't have swap space configured, and I notice several kernel
> threads that I figure might be assuming I have swap.  For example:
> 
>       3 root     S    [ksoftirqd_CPU0]
>       4 root     S    [kswapd]
>       5 root     S    [bdflush]
>       6 root     S    [kupdated]
>       7 root     S    [mtdblockd]
> 
> Do I need any of these if I don't have swap?  Are there any special
> kernel configs I should be doing if I don't have swap?
> 
> Thanks,
> Dave
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux