linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Do I need kswapd if I don't have swap?
@ 2003-11-23  1:35 David Wuertele
  2003-11-23  2:10 ` Måns Rullgård
  2003-11-23  3:22 ` Valdis.Kletnieks
  0 siblings, 2 replies; 4+ messages in thread
From: David Wuertele @ 2003-11-23  1:35 UTC (permalink / raw)
  To: linux-kernel

Using 2.4.18 on my 32MB RAM embedded MIPS system, 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Do I need kswapd if I don't have swap?
  2003-11-23  1:35 Do I need kswapd if I don't have swap? David Wuertele
@ 2003-11-23  2:10 ` Måns Rullgård
  2003-11-23  3:22 ` Valdis.Kletnieks
  1 sibling, 0 replies; 4+ messages in thread
From: Måns Rullgård @ 2003-11-23  2:10 UTC (permalink / raw)
  To: linux-kernel

David Wuertele <dave-gnus@bfnet.com> writes:

> 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 can't help you there.

> 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?

Swap space is really just special case of disk caching.  Many pages
will be backed by regular files, such as the text segment of most
processes.  Swap is used for pages that don't have a corresponding
disk file.  Not configuring any swap is perfectly normal, and
shouldn't cause any problems.  After all, swap is normally enabled by
some system boot script, so it has to be able to start without any
swap space.  For the record, I've been running without swap for a long
time on a system with enough real RAM.

-- 
Måns Rullgård
mru@kth.se


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Do I need kswapd if I don't have swap?
  2003-11-23  1:35 Do I need kswapd if I don't have swap? David Wuertele
  2003-11-23  2:10 ` Måns Rullgård
@ 2003-11-23  3:22 ` Valdis.Kletnieks
  1 sibling, 0 replies; 4+ messages in thread
From: Valdis.Kletnieks @ 2003-11-23  3:22 UTC (permalink / raw)
  To: David Wuertele; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

On Sat, 22 Nov 2003 17:35:57 PST, David Wuertele <dave-gnus@bfnet.com>  said:

>     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);
>     }

>   M26916864
>   W26916864
>   R26916864

Hmm.. the output doesn't match the fprintf()s. Doesn't give me
warm fuzzies...

> The malloc call isn't even returning.  What could explain that?

Alternate theory - the last time through the loop, you get to the fprintf() of
totalread, you go INTO that call, the output makes it out, but some final
malloc() call *within fprintf* or something fails due to being out of memory
(or any number of other failure modes due to being almost but not totally out
of memory), so you never return to start the next iteration of the loop.


[-- Attachment #2: Type: application/pgp-signature, Size: 226 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Do I need kswapd if I don't have swap?
       [not found] <URy0.Sx.3@gated-at.bofh.it>
@ 2003-11-24  7:37 ` Ihar 'Philips' Filipau
  0 siblings, 0 replies; 4+ messages in thread
From: Ihar 'Philips' Filipau @ 2003-11-24  7:37 UTC (permalink / raw)
  To: David Wuertele; +Cc: Linux Kernel Mailing List


   Can you try 2.6?

   AFAIK 2.4 has no callpath to return ENOMEM to user space. (probably 
in couple of months I will reach this issue on my systems and test it 
completely).

   kswapd is universal process to write-out information to disk - and in 
Linux pages has no any difference as kswapd concerned. It just dumbly 
write them out. If you will disable kswapd - files modified by mean of 
mmap() most likely will never be written back to disk. (Here I am (most 
likely) wrong - probably some of the vm gurus can correct me). That's 
actually why Linux has problems with disk cache and disk cache can 
easily swap the task doing i/o.

   If you want to work-around this situation - enable OOM. it will just 
kill your process instead.


David Wuertele wrote:
> Using 2.4.18 on my 32MB RAM embedded MIPS system, 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?
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-11-24  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-23  1:35 Do I need kswapd if I don't have swap? David Wuertele
2003-11-23  2:10 ` Måns Rullgård
2003-11-23  3:22 ` Valdis.Kletnieks
     [not found] <URy0.Sx.3@gated-at.bofh.it>
2003-11-24  7:37 ` Ihar 'Philips' Filipau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).