日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

proc文件系统探索 之 根目录下的文件[七]

發(fā)布時(shí)間:2025/6/15 windows 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 proc文件系统探索 之 根目录下的文件[七] 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

主要參考內(nèi)核文檔和紅帽文檔對(duì)
> cat /proc/meminfo?? 讀出的內(nèi)核信息進(jìn)行解釋,
下篇文章會(huì)簡(jiǎn)單對(duì)讀出該信息的代碼進(jìn)行簡(jiǎn)單的分析。

MemTotal: 507480 kB
MemFree: 10800 kB
Buffers: 34728 kB
Cached: 98852 kB
SwapCached: 128 kB
Active: 304248 kB
Inactive: 46192 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 507480 kB
LowFree: 10800 kB
SwapTotal: 979956 kB
SwapFree: 941296 kB
Dirty: 32 kB
Writeback: 0 kB
AnonPages: 216756 kB
Mapped: 77560 kB
Slab: 22952 kB
SReclaimable: 15512 kB
SUnreclaim: 7440 kB
PageTables: 2640 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 1233696 kB
Committed_AS: 828508 kB
VmallocTotal: 516088 kB
VmallocUsed: 5032 kB
VmallocChunk: 510580 kB

相應(yīng)選項(xiàng)中文意思想各位高手已經(jīng)知道,如果翻譯有什么錯(cuò)誤,請(qǐng)務(wù)必指出:

MemTotal: 所有可用RAM大小 (即物理內(nèi)存減去一些預(yù)留位和內(nèi)核的二進(jìn)制代碼大小)

MemFree: LowFree與HighFree的總和,被系統(tǒng)留著未使用的內(nèi)存

Buffers: 用來給文件做緩沖大小

Cached: 被高速緩沖存儲(chǔ)器(cache memory)用的內(nèi)存的大小(等于 diskcache minus SwapCache ).

SwapCached:被高速緩沖存儲(chǔ)器(cache memory)用的交換空間的大小已經(jīng)
被交換出來的內(nèi)存,但仍然被存放在swapfile中。用來在需要的時(shí)候很快的
被替換而不需要再次打開I/O端口。

Active: 在活躍使用中的緩沖或高速緩沖存儲(chǔ)器頁面文件的大小,除非非常必要否則不會(huì)被移作他用.

Inactive: 在不經(jīng)常使用中的緩沖或高速緩沖存儲(chǔ)器頁面文件的大小,可能被用于其他途徑.

HighTotal:
HighFree: 該區(qū)域不是直接映射到內(nèi)核空間。內(nèi)核必須使用不同的手法使用該段內(nèi)存。

LowTotal:
LowFree: 低位可以達(dá)到高位內(nèi)存一樣的作用,而且它還能夠被內(nèi)核用來記錄
一些自己的數(shù)據(jù)結(jié)構(gòu)。Among many other things, it is where
everything from the Slab is allocated.? Bad things happen
when you’re out of lowmem.

SwapTotal: 交換空間的總大小

SwapFree: 未被使用交換空間的大小

Dirty: 等待被寫回到磁盤的內(nèi)存大小。

Writeback: 正在被寫回到磁盤的內(nèi)存大小。

AnonPages:未映射頁的內(nèi)存大小

Mapped: 設(shè)備和文件等映射的大小。

Slab: 內(nèi)核數(shù)據(jù)結(jié)構(gòu)緩存的大小,可以減少申請(qǐng)和釋放內(nèi)存帶來的消耗。

SReclaimable:可收回Slab的大小

SUnreclaim:不可收回Slab的大小(SUnreclaim+SReclaimable=Slab)

PageTables:管理內(nèi)存分頁頁面的索引表的大小。

NFS_Unstable:不穩(wěn)定頁表的大小

Bounce:

CommitLimit: Based on the overcommit ratio(‘vm.overcommit_ratio’),
this is the total amount of? memory currently available to
be allocated on the system. This limit is only adhered to
if strict overcommit accounting is enabled (mode 2 in
‘vm.overcommit_memory’).
The CommitLimit is calculated with the following formula:
CommitLimit = (‘vm.overcommit_ratio’ * Physical RAM) + Swap
For example, on a system with 1G of physical RAM and 7G
of swap with a `vm.overcommit_ratio` of 30 it would
yield a CommitLimit of 7.3G.
For more details, see the memory overcommit documentation
in vm/overcommit-accounting.

Committed_AS: The amount of memory presently allocated on
the system.
The committed memory is a sum of all of the memory which
has been allocated by processes, even if it has not been
“used” by them as of yet. A process which malloc()’s 1G
of memory, but only touches 300M of it will only show up
as using 300M of memory even if it has the address space
allocated for the entire 1G. This 1G is memory which has
been “committed” to by the VM and can be used at any time
by the allocating application. With strict overcommit
enabled on the system (mode 2 in ‘vm.overcommit_memory’),
allocations which would exceed the CommitLimit (detailed
above) will not be permitted. This is useful if one needs
to guarantee that processes will not fail due to lack of
memory once that memory has been successfully allocated.

VmallocTotal: 可以vmalloc虛擬內(nèi)存大小

VmallocUsed: 已經(jīng)被使用的虛擬內(nèi)存大小。

VmallocChunk: largest contigious block of vmalloc area which is free

下面簡(jiǎn)單來個(gè)例子,看看已用內(nèi)存和物理內(nèi)存大小..

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int MemInfo(char* Info, int len);
int main()
{
char buf[128];
memset(buf, 0, 128);
MemInfo(buf, 100);
printf("%s", buf);
return 0;
}
int MemInfo(char* Info, int len)
{
char sStatBuf[256];
FILE* fp;
int flag;
int TotalMem;
int UsedMem;
char* line;
if(system("free -m | awk '{print $2,$3}' > mem"));
memset(sStatBuf, 0, 256);
fp = fopen("mem", "rb");
if(fp < 0)
{
return -1;
}
fread(sStatBuf,1, sizeof(sStatBuf) , fp);

line = strstr(sStatBuf, “\n”);
TotalMem = atoi(line);
line = strstr(line, ” “);
UsedMem = atoi(line);
memset(sStatBuf, 0, 256);
sprintf(sStatBuf, “Used %dM/Total %dM\n”, UsedMem, TotalMem);
if(strlen(sStatBuf) > len)
{
return -1;
}
memcpy(Info, sStatBuf, strlen(sStatBuf));
return 0;
}
結(jié)果:Used 488M/Total 495M

上面文章對(duì)meminfo里的信息做出簡(jiǎn)單的解釋了
那么內(nèi)核怎么把meminfo信息動(dòng)態(tài)反應(yīng)到meminfo文件中呢
在內(nèi)核 linux/fs/proc/proc_misc.c中

static int meminfo_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
struct sysinfo i;
int len;
unsigned long committed;
unsigned long allowed;
struct vmalloc_info vmi;
long cached;

#define K(x) ((x) << (PAGE_SHIFT - 10))
/**
*該宏作用把存儲(chǔ)單位傳換成 kb
*/

si_meminfo(&i);
si_swapinfo(&i);
/**
*這兩個(gè)函數(shù)是對(duì)struct sysinfo結(jié)構(gòu)進(jìn)行初始化的
*/

committed = atomic_read(&vm_committed_space);
allowed = ((totalram_pages - hugetlb_total_pages())
* sysctl_overcommit_ratio / 100) + total_swap_pages;

/**
*其中這項(xiàng)根據(jù)上篇文章CommitLimit解釋計(jì)算的
*/

cached = global_page_state(NR_FILE_PAGES) -
total_swapcache_pages - i.bufferram;
if (cached < 0)
cached = 0;

get_vmalloc_info(&vmi);
/*
* Tagged format, for easy grepping and expansion.
*/

len = sprintf(page,
“MemTotal: %8lu kB\n”
“MemFree: %8lu kB\n”
“Buffers: %8lu kB\n”
“Cached: %8lu kB\n”
“SwapCached: %8lu kB\n”
“Active: %8lu kB\n”
“Inactive: %8lu kB\n”
#ifdef CONFIG_HIGHMEM
“HighTotal: %8lu kB\n”
“HighFree: %8lu kB\n”
“LowTotal: %8lu kB\n”
“LowFree: %8lu kB\n”
#endif
“SwapTotal: %8lu kB\n”
“SwapFree: %8lu kB\n”
“Dirty: ????%8lu kB\n”
“Writeback: %8lu kB\n”
“AnonPages: %8lu kB\n”
“Mapped: %8lu kB\n”
“Slab: ???? %8lu kB\n”
“SReclaimable: %8lu kB\n”
“SUnreclaim: %8lu kB\n”
“PageTables: %8lu kB\n”
“NFS_Unstable: %8lu kB\n”
“Bounce: %8lu kB\n”
“CommitLimit: %8lu kB\n”
“Committed_AS: %8lu kB\n”
“VmallocTotal: %8lu kB\n”
“VmallocUsed: %8lu kB\n”
“VmallocChunk: %8lu kB\n”,
K(i.totalram),
K(i.freeram),
K(i.bufferram),
K(cached),
K(total_swapcache_pages),
K(global_page_state(NR_ACTIVE)),
K(global_page_state(NR_INACTIVE)),
#ifdef CONFIG_HIGHMEM
K(i.totalhigh),
K(i.freehigh),
K(i.totalram-i.totalhigh),
K(i.freeram-i.freehigh),
#endif
K(i.totalswap),
K(i.freeswap),
K(global_page_state(NR_FILE_DIRTY)),
K(global_page_state(NR_WRITEBACK)),
K(global_page_state(NR_ANON_PAGES)),
K(global_page_state(NR_FILE_MAPPED)),
K(global_page_state(NR_SLAB_RECLAIMABLE) +
global_page_state(NR_SLAB_UNRECLAIMABLE)),
K(global_page_state(NR_SLAB_RECLAIMABLE)),
K(global_page_state(NR_SLAB_UNRECLAIMABLE)),
K(global_page_state(NR_PAGETABLE)),
K(global_page_state(NR_UNSTABLE_NFS)),
K(global_page_state(NR_BOUNCE)),
K(allowed),
K(committed),
(unsigned long)VMALLOC_TOTAL >> 10,
vmi.used >> 10,
vmi.largest_chunk >> 10
);
len += hugetlb_report_meminfo(page + len);

return proc_calc_metrics(page, start, off, count, eof, len);
#undef K
}

其中sysinfo結(jié)構(gòu)在 linux/kernel.h? 定義:

struct sysinfo {
long uptime; /* 啟動(dòng)到現(xiàn)在經(jīng)過的時(shí)間 */
unsigned long loads[3];
/* 1, 5, and 15 minute load averages */
unsigned long totalram; /* 總的可用的內(nèi)存大小 */
unsigned long freeram; /* 還未被使用的內(nèi)存大小 */
unsigned long sharedram; /* 共享的存儲(chǔ)器的大小*/
unsigned long bufferram; /* 的存儲(chǔ)器的大小 */
unsigned long totalswap; /* 交換區(qū)大小 */
unsigned long freeswap; /* 還可用的交換區(qū)大小 */
unsigned short procs; /* 當(dāng)前進(jìn)程數(shù)目 */
unsigned short pad; /* explicit padding for m68k */
unsigned long totalhigh; /* 總的高內(nèi)存大小 */
unsigned long freehigh; /* 可用的高內(nèi)存大小 */
unsigned int mem_unit; /* 以字節(jié)為單位的內(nèi)存大小 */
char _f[20-2*sizeof(long)-sizeof(int)];
};

而global_page_state()函數(shù)中的常量定義在 linux/mmzone.h

enum zone_stat_item {
/* First 128 byte cacheline (assuming 64 bit words) */
NR_FREE_PAGES,
NR_INACTIVE,
NR_ACTIVE,
NR_ANON_PAGES, /* Mapped anonymous pages */
NR_FILE_MAPPED, /* pagecache pages mapped into pagetables.
only modified from process context */

NR_FILE_PAGES,
NR_FILE_DIRTY,
NR_WRITEBACK,
/* Second 128 byte cacheline */
NR_SLAB_RECLAIMABLE,
NR_SLAB_UNRECLAIMABLE,
NR_PAGETABLE, /* used for pagetables */
NR_UNSTABLE_NFS, /* NFS unstable pages */
NR_BOUNCE,
NR_VMSCAN_WRITE,
#ifdef CONFIG_NUMA
NUMA_HIT, /* allocated in intended node */
NUMA_MISS, /* allocated in non intended node */
NUMA_FOREIGN, /* was intended here, hit elsewhere */
NUMA_INTERLEAVE_HIT, /* interleaver preferred this zone */
NUMA_LOCAL, /* allocation from local node */
NUMA_OTHER, /* allocation from other node */
#endif
NR_VM_ZONE_STAT_ITEMS
};

其中通過global_page_state()函數(shù)根據(jù) zone_stat_item 結(jié)構(gòu)的常量得到不同區(qū)大小,會(huì)跟 vm_stat[NR_VM_ZONE_STAT_ITEMS]對(duì)應(yīng)起來。
vm_stat[]是統(tǒng)計(jì)各區(qū)的大小。

內(nèi)核 linux/vmstat.h定義:

static inline unsigned long global_page_state(enum zone_stat_item item)
{
long x = atomic_long_read(&vm_stat[item]);
#ifdef CONFIG_SMP
if (x < 0)
x = 0;
#endif
return x;
}

下面根據(jù)struct sysinfo結(jié)構(gòu),簡(jiǎn)單分析CPU和內(nèi)存使用信息。
#include <stdio.h>
#include <linux/unistd.h> /* 包含調(diào)用 _syscallX 宏等相關(guān)信息*/
#include <linux/kernel.h> /* 包含sysinfo結(jié)構(gòu)體信息*/
int main(int argc, char *agrv[])
{
struct sysinfo s_info;
int error;
error = sysinfo(&s_info);
printf(“\n\ncode error=%d\n”,error);
printf(“Uptime = %ds\nLoad: 1 min%d / 5 min %d / 15 min %d\n”
“RAM: total %d / free %d /shared%d\n”
“Memory in buffers = %d\nSwap:total%d/free%d\n”
“Number of processes = %d\n”,
s_info.uptime, s_info.loads[0],
s_info.loads[1], s_info.loads[2],
s_info.totalram, s_info.freeram,
s_info.totalswap, s_info.freeswap,
s_info.procs);
return 0;
}
結(jié)果:
code error=0
Uptime = 8329s
Load: 1 min37152 / 5 min 37792 / 15 min 48672
RAM: total 519659520 / free 9031680 /shared1003474944
Memory in buffers = 937451520
Swap:total223/free-1078732672
Number of processes = -1078732608


轉(zhuǎn)載于:https://blog.51cto.com/sunzeduo/1562203

總結(jié)

以上是生活随笔為你收集整理的proc文件系统探索 之 根目录下的文件[七]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 在线播放不卡av | 99riav3国产精品视频 | 成人免费做受小说 | 在线观看毛片视频 | 性欧美激情 | 极品国产在线 | 国产精久久一区二区三区 | 欧美另类videosbestsex日本 | 国产一区在线观看视频 | 午夜av片| 国产精品yy | 亚洲永久精品在线观看 | 日日鲁鲁鲁夜夜爽爽狠狠视频97 | 国产成人精品综合在线观看 | 男女扒开双腿猛进入爽爽免费 | 天堂аⅴ在线最新版在线 | 无码熟妇αⅴ人妻又粗又大 | 久久亚洲av永久无码精品 | 免费在线观看a级片 | 午夜在线视频 | 美女黄色av| 精品国产免费无码久久久 | 亚洲自拍p | a毛片毛片av永久免费 | 日本一区二区色 | 青青青国产视频 | 在线一区二区三区四区五区 | 波多野结衣先锋影音 | 麻豆av网址| 中文字幕免费在线观看视频 | 69精品一区二区三区 | 日韩影院一区二区 | 蜜桃视频在线观看一区 | 裸体美女免费视频网站 | 日韩在线观看不卡 | 亚洲第一激情 | 日韩欧美精品久久 | 99色图| а√天堂资源在线 | 日韩美一级片 | 毛片内射| 99亚洲国产精品 | 亚洲毛片网 | 日本在线观看一区二区三区 | 手机看片中文字幕 | 人妻与黑人一区二区三区 | 久久黄色视屏 | 成人av在线一区二区 | 黄色av地址 | 草久在线| 日本成人在线视频网站 | 日韩欧美自拍偷拍 | 暖暖视频日本 | 色干干| 国产又黄又粗又长 | 女人的黄色片 | 成人精品免费网站 | 亚洲精品综合在线 | 夫妻黄色片 | 秋霞午夜伦理 | 人人草人人看 | 日本精品网站 | 国产成人精品一区二区无码呦 | 日本a级片视频 | www.国产一区二区 | 国产精品国产三级国产传播 | 日韩中文免费 | 第一页在线视频 | 精品一区二区日韩 | 国产农村妇女精品久久久 | 国产真人做爰视频免费 | 日本一级片在线播放 | 邪恶久久| 91久久网| 天堂中文网在线 | 色一情一乱一区二区三区 | 中日韩精品视频在线观看 | 影音先锋中文字幕在线播放 | 亚洲一区二区91 | 69久人妻无码精品一区 | 人妻丝袜一区 | 激情视频在线观看免费 | 95国产精品 | 少妇搡bbbb搡bbb搡小说 | 黄页视频在线免费观看 | 在线观看一区二区三区视频 | 99re6在线观看| 午夜在线观看视频 | 亚洲激情电影在线 | 日韩电影一区二区三区四区 | 国产成人无码久久久精品天美传媒 | 成人区人妻精品一区二区网站 | 制中文字幕音影 | 亚洲乱码中文字幕 | 日韩夜夜操 | 国产精品一区二区自拍 | 欧美无人区码suv | 欧美在线中文字幕 | 老司机午夜av |