linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Wichert Akkerman <wichert@soil.nl>
To: linux-mm@kvack.org, riel@conectiva.com.br
Subject: Running out of memory in 1 easy step
Date: Thu, 14 Sep 2000 14:59:04 +0200	[thread overview]
Message-ID: <20000914145904.B18741@liacs.nl> (raw)

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


I have a small test program that consistently can't allocate more
memory using mmap after 458878 allocations, no matter how much memory
I allocate per call (tried with 8, 80, 800 and 4000 bytes per call):
mmap returns ENOMEM. The machine has plenty memory available (2Gb
and no other processes are running except standard daemons) so there
should be enough memory.

Some added printk statements in mm/mmap.c do_mmap_pgoff() revealed
this happens at the following bit of code:

        /* Obtain the address to map to. we verify (or select) it and ensure
         * that it represents a valid section of the address space.
         */
        if (flags & MAP_FIXED) {
                if (addr & ~PAGE_MASK)
                        return -EINVAL;
        } else {
                addr = get_unmapped_area(addr, len);
                if (!addr) {
                        printk("do_mmap_pgoff: cannot allocate unmapped memory, returning ENOMEM\n");
                        return -ENOMEM;
                }
        }

Silly test program is attached (I didn't write it, so don't punish me for
the ugly code :).

Wichert.

-- 
  _________________________________________________________________
 / Generally uninteresting signature - ignore at your convenience  \
| wichert@liacs.nl                    http://www.liacs.nl/~wichert/ |
| 1024D/2FA3BC2D 576E 100B 518D 2F16 36B0  2805 3CB8 9250 2FA3 BC2D |


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mem3.c --]
[-- Type: text/x-csrc, Size: 877 bytes --]

#include <unistd.h>
#include <sys/mman.h>
  
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main(){
  int k;
   unsigned int m,p;
   const int mem=800000000;
   int len;
   double **dptr;

   m=sizeof(double)+sizeof(double*);
   len=mem/m;
printf("Will allocate %d bytes in %d blocks\n", mem, len);
   dptr = (double **) malloc(sizeof(double*)*len) ;
   for(k=0; k<len; k++) {
     dptr[k] = (double *) mmap(NULL, 500*sizeof(double), PROT_READ|PROT_WRITE, (MAP_PRIVATE|MAP_ANONYMOUS), -1, 0);
     if(dptr[k]==MAP_FAILED) {
	printf("Allocation error: %s\n", strerror(errno));
       printf("k: %d\n",k);
       printf("Alloc Null\n");
getchar();
       exit(-1);
     }
     *(dptr[k]) = rand();
   }
   for(k=len-1; k>=0; k--) {
     printf("value: %d",*(dptr[k]));
   }
   fprintf(stderr,"k=%d mem=%d MB\n",k,mem/1000000);
   exit (0);
 }


             reply	other threads:[~2000-09-14 12:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-14 12:59 Wichert Akkerman [this message]
2000-09-14 15:56 ` Andi Kleen
2000-09-14 16:08   ` Wichert Akkerman
2000-09-14 18:43     ` Andi Kleen
2000-09-14 19:20       ` Wichert Akkerman
2000-09-14 23:03         ` Mark Hahn
2000-09-15 13:22 Mark_H_Johnson
2000-09-15 16:35 ` Mark Hahn
2000-09-15 16:53 Mark_H_Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000914145904.B18741@liacs.nl \
    --to=wichert@soil.nl \
    --cc=linux-mm@kvack.org \
    --cc=riel@conectiva.com.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox