[Top][All Lists]

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

[Qemu-devel] [Bug 1836558] Re: Qemu-ppc Memory leak creating threads

From: Alex Bennée
Subject: [Qemu-devel] [Bug 1836558] Re: Qemu-ppc Memory leak creating threads
Date: Mon, 15 Jul 2019 16:50:06 -0000

Nope we think we have identified the leak. On CPU realize
(ppc_cpu_realize) the translator sets up its tables
(create_ppc_opcodes). This will happen for each thread created. This
would be fine but linux_user cpu_copy function then does:

    memcpy(new_env, env, sizeof(CPUArchState));

which will blindly overwrite the tables in CPUArchState (CPUPPCState)
causing the leak. The suggestion is the data should be moved to
PowerPCCPU (as it is internal to the translator) and avoid being smashed
by the memcpy. However longer term we should replace the memcpy with an
arch aware smart copy.

You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

  Qemu-ppc Memory leak creating threads

Status in QEMU:

Bug description:
  When creating c++ threads (with c++ std::thread), the resulting binary
  has memory leaks when running with qemu-ppc.

  Eg the following c++ program, when compiled with gcc, consumes more
  and more memory while running at qemu-ppc. (does not have memory leaks
  when compiling for Intel, when running same binary on real powerpc CPU
  hardware also no memory leaks).

  (Note I used function getCurrentRSS to show available memory, see
  runtime-using-c; calls commented out here)

  Compiler: powerpc-linux-gnu-g++ (Debian 8.3.0-2) 8.3.0 (but same problem with 
older g++ compilers even 4.9)
  Os: Debian 10.0 ( Buster) (but same problem seen on Debian 9/stetch)
  qemu: qemu-ppc version 3.1.50


  #include <iostream>
  #include <thread>
  #include <chrono>

  using namespace std::chrono_literals;

  // Create/run and join a 100 threads.
  void Fun100()
  //    auto b4 = getCurrentRSS();
  //    std::cout << getCurrentRSS() << std::endl;
      for(int n = 0; n < 100; n++)
          std::thread t([]
              std::this_thread::sleep_for( 10ms );
  //        std::cout << n << ' ' << getCurrentRSS() << std::endl;
      std::this_thread::sleep_for( 500ms ); // to give OS some time to wipe 
  //    auto after = getCurrentRSS();
      std::cout << b4 << ' ' << after << std::endl;

  int main(int, char **)
      Fun100();  // memory used keeps increasing

To manage notifications about this bug go to:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]