简体   繁体   English

linux中确切的总内存使用情况等于系统监视器

[英]exact total memory usage in linux that equals to system monitor

By getting Memtotal and Memfree values from "/proc/meminfo" and subtracting them we must get the Used Memory in Linux. 通过从“ / proc / meminfo”获取Memtotal和Memfree值并减去它们,我们必须获得Linux中的Used Memory。 Most of threads and web pages that I have visited have guided through this approach to compute the Total Memory Usage in Linux. 我访问过的大多数线程和网页都通过这种方法进行了指导,以计算Linux中的总内存使用量。 But by implementing this method, I get different results with GNOME System Monitor! 但是通过实现此方法,我使用GNOME System Monitor获得了不同的结果! My result is greater than that (approximately double). 我的结果大于该值(大约两倍)。 So what is the method that GNOME System Monitor uses? 那么GNOME系统监视器使用什么方法?

GNOME system monitor uses libgtop to retrieve memory information for various platforms. GNOME系统监视器使用libgtop检索各种平台的内存信息。 For Linux it uses sysdeps/linux/mem.c 2 where the routine is as follows: 对于Linux,它使用sysdeps/linux/mem.c 2 ,其中的例程如下:

Strings like "MemTotal" are headings in /proc/meminfo . 诸如“ MemTotal”之类的字符串是/proc/meminfo中的标题。

…    
    buf->total  = get_scaled(buffer, "MemTotal:");
    buf->free   = get_scaled(buffer, "MemFree:");
    buf->used   = buf->total - buf->free;
    buf->shared = 0;
    buf->buffer = get_scaled(buffer, "Buffers:");
    buf->cached = get_scaled(buffer, "Cached:");

    buf->user = buf->total - buf->free - buf->cached - buf->buffer;

The memory reported in the application is buf->user . 应用程序中报告的内存为buf->user More precisely in src/load-graph.cpp 1 by: 更精确地在src/load-graph.cpp 1中,方法是:

mempercent  = (float)mem.user  / (float)mem.total;
set_memory_label_and_picker(GTK_LABEL(graph->labels.memory),
                            GSM_COLOR_BUTTON(graph->mem_color_picker),
                            mem.user, mem.total, mempercent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM