[英]private memory of an empty python process forked by Python multiprocessing
I'm creating several child processes via Python multiprocessing, but these child processes use a lot heap private memory even when they're empty processes. 我正在通过Python多处理创建多个子进程,但是这些子进程即使在为空进程时也会占用大量堆专用内存。 This situation is getting worse when running on RHEL with THP(Transparent Hugepage) enabled. 在启用了THP(透明大页面)的RHEL上运行时,这种情况变得越来越糟。
Here is a simple example to demo this: 这是一个演示的简单示例:
import os
import multiprocessing
print parent process's heap memory in /proc/<pid>/smaps
def emptyProcess():
print child process's heap memory in /proc/<pid>/smaps
return
multiprocessing.Process(name='p1', target=emptyProcess).start()
Output: 输出:
parent: pid: 20920: rss:8228864, shr:2781184, priv:5447680, swap:0, pss:6154240
child: pid: 20921: rss:6397952, shr:5472256, priv:925696, swap:0, pss:3381248
what's in child process's priv memory (925696B, or 664KB in heap)? 子进程的专用内存(925696B,或堆中的664KB)中有什么?
Parent process heap memory: 父进程堆内存:
006cc000-00be4000 rw-p 00000000 00:00 0 [heap] 006cc000-00be4000 rw-p 00000000 00:00 0 [堆]
Size: 5216 kB 大小:5216 kB
Rss: 4120 kB Rss:4120 kB
Pss: 4120 kB pss:4120 kB
Shared_Dirty: 0 kB Shared_Dirty:0 kB
Private_Dirty: 4120 kB 私人肮脏:4120 kB
Referenced: 4120 kB 参考:4120 kB
Anonymous: 4120 kB 匿名:4120 kB
AnonHugePages: 0 kB 页面数:0 kB
KernelPageSize: 4 kB 内核页面大小:4 kB
Child process heap memory: 子进程堆内存:
006cc000-00be4000 rw-p 00000000 00:00 0 [heap] 006cc000-00be4000 rw-p 00000000 00:00 0 [堆]
Size: 5216 kB 大小:5216 kB
Rss: 4396 kB Rss:4396 kB
Pss: 2530 kB 积分:2530 kB
Shared_Dirty: 3732 kB Shared_Dirty:3732 kB
Private_Dirty: 664 kB 私人_脏:664 kB
Referenced: 676 kB 参考:676 kB
Anonymous: 4396 kB 匿名:4396 kB
AnonHugePages: 0 kB 页面数:0 kB
KernelPageSize: 4 kB 内核页面大小:4 kB
One of the primary things in each process is the Python interpreter / VM. 每个过程中的主要内容之一是Python解释器/ VM。 If this were a C program, you'd see a much different picture, but even with an "empty" Python process, you still incur the overhead of an interpreter unless you use threading. 如果这是C程序,您会看到截然不同的画面,但是即使使用“空” Python进程,除非使用线程,否则仍会产生解释器的开销。 Each Python interpreter has a chunk of heap, stack and code, and Python's multiprocessing is a wrapper (as far as I know) around Linux processes; 每个Python解释器都有大量的堆,堆栈和代码,Python的多重处理是Linux进程的包装(据我所知)。 so basically you are dealing with fork()
. 所以基本上您正在处理fork()
。 Forking a new process means you get a new Python interpreter. 分叉新进程意味着您将获得一个新的Python解释器。 Even though the OS is pretty smart about Copy On Write, the overhead of the Python interpreters add up. 即使操作系统对于“写时复制”非常聪明,但Python解释器的开销还是会增加的。
My recommendation would be to try Python threads, or switch this to a non-interpreted language to reduce the process overhead. 我的建议是尝试使用Python线程,或将其切换为非解释语言以减少进程开销。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.