Chromium:Browser Process对Render Process的内存管理策略

内存管理:

Chromium没有对单个进程进行内存的管理和大小限定,但是会根据内存大小对render process的个数进行限制。
(Android系统有自己的内存管理机制,所以Chromium不对Android系统做处理)
内存管理策略如下:
最小进程数:3
最大进程数:82
进程数计算方法:物理内存/(2*单个进程内存占用估计值)
单个进程内存占用估计值:64位系统60MB,32位系统40MB
Chromium代码实现中对内存管理实现如下:

#if defined(OS_ANDROID)
  // On Android we don't maintain a limit of renderer process hosts - we are
  // happy with keeping a lot of these, as long as the number of live renderer
  // processes remains reasonable, and on Android the OS takes care of that.
  return std::numeric_limits::max();
#endif

  // On other platforms, we calculate the maximum number of renderer process
  // hosts according to the amount of installed memory as reported by the OS.
  // The calculation assumes that you want the renderers to use half of the
  // installed RAM and assuming that each WebContents uses ~40MB.  If you modify
  // this assumption, you need to adjust the ThirtyFourTabs test to match the
  // expected number of processes.
  //
  // With the given amounts of installed memory below on a 32-bit CPU, the
  // maximum renderer count will roughly be as follows:
  //
  //   128 MB -> 3
  //   512 MB -> 6
  //  1024 MB -> 12
  //  4096 MB -> 51
  // 16384 MB -> 82 (kMaxRendererProcessCount)

  static size_t max_count = 0;
  if (!max_count) {
    const size_t kEstimatedWebContentsMemoryUsage =
#if defined(ARCH_CPU_64_BITS)
        60;  // In MB
#else
        40;  // In MB
#endif
    max_count = base::SysInfo::AmountOfPhysicalMemoryMB() / 2;
    max_count /= kEstimatedWebContentsMemoryUsage;

    const size_t kMinRendererProcessCount = 3;
    max_count = std::max(max_count, kMinRendererProcessCount);
    max_count = std::min(max_count, kMaxRendererProcessCount);
  }
  return max_count;

命令行修改render process数量:
Content_switches.cc: const char kRendererProcessLimit[] = “renderer-process-limit”
Browser_main_loop.cc:

#if !defined(OS_IOS)
  if (parsed_command_line_.HasSwitch(switches::kRendererProcessLimit)) {
    std::string limit_string = parsed_command_line_.GetSwitchValueASCII(
        switches::kRendererProcessLimit);
    size_t process_limit;
    if (base::StringToSizeT(limit_string, &process_limit)) {
      RenderProcessHost::SetMaxRendererProcessCount(process_limit);
    }
  }
#endif

打开chrome的task manager可以看到浏览器各个进程的情况,在浏览器地址栏输入:about:memory可以查看详细内存占用情况。
进程内存占用情况实现可以在metrics_memory_details.cc、site_details.cc中查看

你可能感兴趣的:(Chromium)