All of lore.kernel.org
 help / color / mirror / Atom feed
* qemu-x86_64 runs out of memory
@ 2022-09-13  9:35 Andreas Schwab
  2022-09-13 10:53 ` Richard Henderson
  2022-09-13 14:33 ` Alex Bennée
  0 siblings, 2 replies; 4+ messages in thread
From: Andreas Schwab @ 2022-09-13  9:35 UTC (permalink / raw)
  To: qemu-devel

$ cat mmap.c
#include <stdio.h>
#include <sys/mman.h>

int
main (void)
{
  void *A;
  size_t L = 0, U, Max = 0;
  for (U = 1; ; U *= 2)
    {
      A = mmap (0, U, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
      if (A == (void *) -1)
	break;
      else
	munmap (A, U);
    }
  while (L + 1 < U)
    {
      size_t M = L + (U - L) / 2;
      A = mmap (0, M, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
      if (A == (void *) -1)
	U = M;
      else
	{
	  Max = M;
	  munmap(A, M);
	  L = M;
	}
    }
  printf ("%zx\n", Max);
}
$ cc -O2 -g -Wall -std=gnu11 -g     mmap.c   -o mmap
$ ./mmap 
7f672e5ff000
$ qemu-x86_64 ./mmap
Killed

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


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

* Re: qemu-x86_64 runs out of memory
  2022-09-13  9:35 qemu-x86_64 runs out of memory Andreas Schwab
@ 2022-09-13 10:53 ` Richard Henderson
  2022-09-26 11:39   ` Li Zhang
  2022-09-13 14:33 ` Alex Bennée
  1 sibling, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2022-09-13 10:53 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel

On 9/13/22 10:35, Andreas Schwab wrote:
> $ cat mmap.c
> #include <stdio.h>
> #include <sys/mman.h>
> 
> int
> main (void)
> {
>    void *A;
>    size_t L = 0, U, Max = 0;
>    for (U = 1; ; U *= 2)
>      {
>        A = mmap (0, U, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
>        if (A == (void *) -1)
> 	break;
>        else
> 	munmap (A, U);
>      }
>    while (L + 1 < U)
>      {
>        size_t M = L + (U - L) / 2;
>        A = mmap (0, M, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
>        if (A == (void *) -1)
> 	U = M;
>        else
> 	{
> 	  Max = M;
> 	  munmap(A, M);
> 	  L = M;
> 	}
>      }
>    printf ("%zx\n", Max);
> }
> $ cc -O2 -g -Wall -std=gnu11 -g     mmap.c   -o mmap
> $ ./mmap
> 7f672e5ff000
> $ qemu-x86_64 ./mmap
> Killed
> 

I suspect this is the same as

   https://gitlab.com/qemu-project/qemu/-/issues/290

Needs a reorg of memory region tracking for {linux,bsd}-user.


r~


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

* Re: qemu-x86_64 runs out of memory
  2022-09-13  9:35 qemu-x86_64 runs out of memory Andreas Schwab
  2022-09-13 10:53 ` Richard Henderson
@ 2022-09-13 14:33 ` Alex Bennée
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Bennée @ 2022-09-13 14:33 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: qemu-devel


Andreas Schwab <schwab@suse.de> writes:

> $ cat mmap.c
> #include <stdio.h>
> #include <sys/mman.h>
>
> int
> main (void)
> {
>   void *A;
>   size_t L = 0, U, Max = 0;
>   for (U = 1; ; U *= 2)
>     {
>       A = mmap (0, U, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
>       if (A == (void *) -1)
> 	break;
>       else
> 	munmap (A, U);
>     }
>   while (L + 1 < U)
>     {
>       size_t M = L + (U - L) / 2;
>       A = mmap (0, M, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
>       if (A == (void *) -1)
> 	U = M;
>       else
> 	{
> 	  Max = M;
> 	  munmap(A, M);
> 	  L = M;
> 	}
>     }
>   printf ("%zx\n", Max);
> }
> $ cc -O2 -g -Wall -std=gnu11 -g     mmap.c   -o mmap
> $ ./mmap 
> 7f672e5ff000
> $ qemu-x86_64 ./mmap
> Killed

This is probably the same as bug: https://gitlab.com/qemu-project/qemu/-/issues/967

-- 
Alex Bennée


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

* Re: qemu-x86_64 runs out of memory
  2022-09-13 10:53 ` Richard Henderson
@ 2022-09-26 11:39   ` Li Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Li Zhang @ 2022-09-26 11:39 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Andreas Schwab, qemu-devel

I did some investigation and when I mmap 2TB memory, the PageDesc is
allocated with 12GB.
The count of PageDesc is about  0x80000 and the size of PageDesc is 24Bytes.
So memory costs about 12GB.  If the size of PageDesc data is reduced,
the memory should be reduced significantly.

If more and more memory is mapped, and the page table entrieds is very
huge. So it still causes OOM if the host memory is not big enough.


On Tue, Sep 13, 2022 at 12:59 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 9/13/22 10:35, Andreas Schwab wrote:
> > $ cat mmap.c
> > #include <stdio.h>
> > #include <sys/mman.h>
> >
> > int
> > main (void)
> > {
> >    void *A;
> >    size_t L = 0, U, Max = 0;
> >    for (U = 1; ; U *= 2)
> >      {
> >        A = mmap (0, U, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
> >        if (A == (void *) -1)
> >       break;
> >        else
> >       munmap (A, U);
> >      }
> >    while (L + 1 < U)
> >      {
> >        size_t M = L + (U - L) / 2;
> >        A = mmap (0, M, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
> >        if (A == (void *) -1)
> >       U = M;
> >        else
> >       {
> >         Max = M;
> >         munmap(A, M);
> >         L = M;
> >       }
> >      }
> >    printf ("%zx\n", Max);
> > }
> > $ cc -O2 -g -Wall -std=gnu11 -g     mmap.c   -o mmap
> > $ ./mmap
> > 7f672e5ff000
> > $ qemu-x86_64 ./mmap
> > Killed
> >
>
> I suspect this is the same as
>
>    https://gitlab.com/qemu-project/qemu/-/issues/290
>
> Needs a reorg of memory region tracking for {linux,bsd}-user.
>
>
> r~
>


-- 

Best Regards
-Li


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

end of thread, other threads:[~2022-09-26 11:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13  9:35 qemu-x86_64 runs out of memory Andreas Schwab
2022-09-13 10:53 ` Richard Henderson
2022-09-26 11:39   ` Li Zhang
2022-09-13 14:33 ` Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.