本文介绍了在Linux上虚拟内存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想深入了解在OS Linux的虚拟内存管理。

I'm trying to understand in depth the virtual memory management on OS Linux.

我真的不明白操作系统如何确定虚拟机的大小的过程。

I don't really understand how the OS determine the size of the VM for a process.

我知道,一个32位的x86操作系统能够为3 GB的虚拟机ADRESS空间放弃...它总是正确的?

I know that an 32-bits x86 OS can give up to 3 GB of vm adress space... Is it always true ?

在我的情况,我有大约110 MB的物理内存和32位Linux和我的主要过程有一个VM ADRESS空间约660 MB。然而,只有50兆是在物理内存(我的方法的RSS),所以我的物理RAM未满。剩下的是自由,几乎全是使用页面缓存。这似乎是一个正常的行为。

In my case, i have about 110 MB physical memory with and 32-bits Linux, and my main process have a vm adress space about 660 MB. However, only 50 MB are in physical memory (the RSS of my process), so my physical RAM isn't full. The rest is free and almost the whole is used by page cache. That's seems to be a normal behaviour.

如果我检查/ proc / my_process_PID / SMAP,有几个8 MB匿名VMA。

If i check /proc/my_process_PID/smap, there are several 8 MB anonymous VMA.

我的实际问题是,我需要在code进行其它附加10 MB的malloc,但不幸的是OOM杀手杀死我的过程(外存储器)...我认为有没有更多的可用自由在虚拟机的堆页,是不是?是否有一个严重的内存泄露的地方?

My actual problem is that i need to make a additionnal 10 MB malloc in the code, but unfortunately OOM-Killer kills my process (out-of-memory) ... I think there are no more free available pages in the vm for the Heap, isn't it ? Is there an huge memory leak somewhere ?

为什么OS不致以过程VM的大小呢?

Why the OS doesn't extend my process vm size so ?

有关信息的虚拟机的大小是无限的:-v的ulimit:无限

For information the vm size is unlimited : ulimit -v : unlimited

推荐答案

您可以为每个进程的虚拟内存3GB(约,在很多32位Linux),并不断创造新的流程占用了千兆字节后的虚拟千兆字节记忆。有一个在内核中一个小的开销,但虚拟内存很便宜。您正在使用的地址空间量可能不是重要的,它可能不会触发OOM杀手。

You can have 3GB of virtual memory per process (approximately, on many 32-bit Linux), and keep on creating new processes taking up gigabytes upon gigabytes of virtual memory. There's a small overhead in the kernel, but virtual memory is very cheap. The amount of address space you're using is probably not important, and it probably won't trigger the OOM killer.

不过,你的系统只有这么多的内存。当你开始的使用的在你的地址空间的页面(写他们),内核被迫寻找物理内存映射他们。如果没有物理RAM,内核可以从驱逐RAM其它页面 - 要么换出来还是丢弃。但是,如果它不能驱逐任何页面,则触发OOM杀手。

However, your system only has so much RAM. As you start using pages in your address space (writing to them), the kernel is forced to find physical RAM to map them to. If there's no physical RAM, the kernel can evict other pages from RAM -- either swap them out or discard them. But if it can't evict any pages, then it triggers the OOM killer.

暗战的地址空间会引起的malloc 来回报我的系统上的 NULL ,而不是触发OOM杀手

Running out of address space will cause malloc to return NULL on my system, instead of triggering the OOM killer.

这听起来像你的进程只是使用太多的内存。 RSS是不是内存量的过程中使用,它只是在物理RAM的量现在的。如果你的程序有一个内存泄漏和持续增长,RSS最终会停止增长 - 因为你使用每一个新页面,内核会从你的过程中驱赶一页。

It sounds like your process is simply using too much RAM. RSS isn't the amount of memory your process uses, it's just the amount that's in physical RAM right now. If your process has a memory leak and keeps growing, RSS will eventually stop growing -- because for every new page you use, the kernel will evict one page from your process.

尝试使用内存设置,例如 Valgrind的。这将帮助你梳理一下内存,你应该担心(mallocs),什么内存,你可以忽略(共享库和其它内存映射文件)。内核(和/ proc中)不会给你足够的细节。

Try using a memory profiler, like Valgrind. This will help you sort out what memory you should be worried about (mallocs) and what memory you can ignore (shared libraries and other memory mapped files). The kernel (and /proc) won't give you enough detail.

这篇关于在Linux上虚拟内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 14:50