qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Weil <1898011@bugs.launchpad.net>
To: qemu-devel@nongnu.org
Subject: [Bug 1898011] Re: mmap MAP_NORESERVE of 2^42 bytes consumes 16Gb of actual RAM
Date: Thu, 28 Jan 2021 09:49:21 -0000	[thread overview]
Message-ID: <161182736157.7685.8190541280553547402.malone@gac.canonical.com> (raw)
In-Reply-To: 160153380394.6201.10648910301442382269.malonedeb@soybean.canonical.com

The problem occurs for example with any program which was compiled with
the address sanitizer.

A simple hello program compiled with "gcc -fsanitize=address hello.c" is
sufficient to show the problem. Just run it with "qemu-x86_64 a.out". It
will be killed by the Linux kernel OOM handler even on a server with 64
GB RAM.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1898011

Title:
  mmap MAP_NORESERVE of 2^42 bytes consumes 16Gb of actual RAM

Status in QEMU:
  Confirmed

Bug description:
  Run this program:

  #include <sys/mman.h>
  #include <stdio.h>
  int main() {
          for (int i = 30; i <= 44; i++) {
                  fprintf(stderr, "trying 2**%d\n", i);
                  mmap((void*)0x600000000000,1ULL << i,
                          PROT_NONE,
                          MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0);
          }
  }

  (tried qemu-x86_64 and qemu-aarch64, 4.2.1 and trunk/5.1.50)

  On each iteration qemu will consume 2x more physical RAM, 
  e.g. when mapping 2^42 it will have RSS of 16Gb.

  On normal linux it works w/o consuming much RAM, due to MAP_NORESERVE.

  Also: qemu -strace prints 0 instead of the correct size starting from size=2^32
  and prints -2147483648 for size=2^31. 

  mmap(0x0000600000000000,1073741824,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0)
  = 0x0000600000000000

  mmap(0x0000600000000000,-2147483648,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0)
  = 0x0000600000000000

  mmap(0x0000600000000000,0,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED|MAP_NORESERVE,-1,0)
  = 0x0000600000000000

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1898011/+subscriptions


  parent reply	other threads:[~2021-01-28 10:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01  6:30 [Bug 1898011] [NEW] mmap MAP_NORESERVE of 2^42 bytes consumes 16Gb of actual RAM Kostya Serebryany
2020-10-02 22:34 ` [Bug 1898011] " Richard Henderson
2021-01-28  9:49 ` Stefan Weil [this message]
2021-01-28  9:59 ` Alex Bennée
2021-05-13 12:10 ` Thomas Huth
2021-05-13 12:49 ` Richard Henderson
2021-05-14 10:05 ` Thomas Huth

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=161182736157.7685.8190541280553547402.malone@gac.canonical.com \
    --to=1898011@bugs.launchpad.net \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).