亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 6746 | 回復(fù): 19
打印 上一主題 下一主題

推薦一篇文章,希望對(duì)大家有幫助 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2006-01-11 16:45 |只看該作者 |倒序?yàn)g覽
該文章引用自http://forums.gentoo.org/viewtopic.php?p=1155852

Linux Memory Management or 'Why is there no free RAM?'
Revision 2.3
Copyright 2004 sapphirecat. The text of this post is licensed under a Creative Commons License.

Sections

Overview of memory management

The mysterious 880 MB limit on x86

The difference among VIRT, RES, and SHR in top output

The difference between buffers and cache

Swappiness (2.6 kernels)


1. Overview of memory management
Traditional Unix tools like 'top' often report a surprisingly small amount of free memory after a system has been running for a while. For instance, after about 3 hours of uptime, the machine I'm writing this on reports under 60 MB of free memory, even though I have 512 MB of RAM on the system. Where does it all go?

The biggest place it's being used is in the disk cache, which is currently over 290 MB. This is reported by top as "cached". Cached memory is essentially free, in that it can be replaced quickly if a running (or newly starting) program needs the memory.

The reason Linux uses so much memory for disk cache is because the RAM is wasted if it isn't used. Keeping the cache means that if something needs the same data again, there's a good chance it will still be in the cache in memory. Fetching the information from there is around 1,000 times quicker than getting it from the hard disk. If it's not found in the cache, the hard disk needs to be read anyway, but in that case nothing has been lost in time.

To see a better estimation of how much memory is really free for applications to use, run the command:
Code:
free -m

The -m option stands for megabytes, and the output will look something like this:
Code:
             total       used       free     shared    buffers     cached
Mem:           503        451         52          0         14        293
-/+ buffers/cache:        143        360
Swap:         1027          0       1027

The -/+ buffers/cache line shows how much memory is used and free from the perspective of the applications. Generally speaking, if little swap is being used, memory usage isn't impacting performance at all.

Notice that I have 512 MB of memory in my machine, but only 503 is listed as available by free. This is mainly because the kernel can't be swapped out, so the memory it occupies could never be freed. There may also be regions of memory reserved for/by the hardware for other purposes as well, depending on the system architecture.



2. The mysterious 880 MB limit on x86
By default, the Linux kernel runs in and manages only low memory. This makes managing the page tables slightly easier, which in turn makes memory accesses slightly faster. The downside is that it can't use all of the memory once the amount of total RAM reaches the neighborhood of 880 MB. This has historically not been a problem, especially for desktop machines.

To be able to use all the RAM on a 1GB machine or better, the kernel needs recompiled. Go into 'make menuconfig' (or whichever config is preferred) and set the following option:
Code:
Processor Type and Features ---->
High Memory Support ---->
(X) 4GB

This applies both to 2.4 and 2.6 kernels. Turning on high memory support theoretically slows down accesses slightly, but according to Joseph_sys and log, there is no practical difference.



3. The difference among VIRT, RES, and SHR in top output
VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card's RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) This will virtually always be less than the VIRT size, since most programs depend on the C library.

SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the case of libraries, it does not necessarily mean that the entire library is resident. For example, if a program only uses a few functions in a library, the whole library is mapped and will be counted in VIRT and SHR, but only the parts of the library file containing the functions being used will actually be loaded in and be counted under RES.



4. The difference between buffers and cache
Buffers are associated with a specific block device, and cover caching of filesystem metadata as well as tracking in-flight pages. The cache only contains parked file data. That is, the buffers remember what's in directories, what file permissions are, and keep track of what memory is being written from or read to for a particular block device. The cache only contains the contents of the files themselves.

Corrections and additions to this section welcome; I've done a bit of guesswork based on tracing how /proc/meminfo is produced to arrive at these conclusions.



5. Swappiness (2.6 kernels)
Since 2.6, there has been a way to tune how much Linux favors swapping out to disk compared to shrinking the caches when memory gets full.

ghoti adds:
When an application needs memory and all the RAM is fully occupied, the kernel has two ways to free some memory at its disposal: it can either reduce the disk cache in the RAM by eliminating the oldest data or it may swap some less used portions (pages) of programs out to the swap partition on disk.
It is not easy to predict which method would be more efficient.
The kernel makes a choice by roughly guessing the effectiveness of the two methods at a given instant, based on the recent history of activity.

Before the 2.6 kernels, the user had no possible means to influence the calculations and there could happen situations where the kernel often made the wrong choice, leading to thrashing and slow performance. The addition of swappiness in 2.6 changes this.
Thanks, ghoti!

Swappiness takes a value between 0 and 100 to change the balance between swapping applications and freeing cache. At 100, the kernel will always prefer to find inactive pages and swap them out; in other cases, whether a swapout occurs depends on how much application memory is in use and how poorly the cache is doing at finding and releasing inactive items.

The default swappiness is 60. A value of 0 gives something close to the old behavior where applications that wanted memory could shrink the cache to a tiny fraction of RAM. For laptops which would prefer to let their disk spin down, a value of 20 or less is recommended.

As a sysctl, the swappiness can be set at runtime with either of the following commands:
Code:
# sysctl -w vm.swappiness=30
# echo 30 >/proc/sys/vm/swappiness

The default when Gentoo boots can also be set in /etc/sysctl.conf:
Code:
# Control how much the kernel should favor swapping out applications (0-100)
vm.swappiness = 30


Some patchsets allow the kernel to auto-tune the swappiness level as it sees fit; they may not keep a user-set value.

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2006-01-12 09:21 |只看該作者
偶也轉(zhuǎn)一個(gè)(轉(zhuǎn)自kernelnewbies郵件列表)

On 10/17/05, Roy Smith <misterdabolina@xxxxxxxxx> wrote:
> Hi all,
>
> I want to refine a previous question of mine
> (and thank everybody who helped me!)
> about the virtual memory of the kenel itself.
>
> Where does the kernel keeps its own page tables ?
> are they all swapped-in all the time ?

The memory in the Kernel/Kernel Module will never be swapped-out !!!!

The kernel keeps the Virtual Address range from 3G (PAGE_OFFSET) to 4G
for it-self, in which it creates 1 to 1 mapping of physical memory
like 3G of Virtual Address points to 0 Physical Address and so on ....
till the 896MB Physical RAM or less than 896MB MAX avaialble RAM in
the System ... and for (3G + 896MB) to 4G is called as
VMALLOC_RESERVE, which is used in tempoarary mappings of the physical
memory above 896MB (HighMemory) .... and let say if system has 256MB
RAM then 3G to (3G + 256MB) Virtual Address will have direct mappings
and remaining 4G - (3G + 256MB) Virtual Address range is
VMALLOC_RESERVE .....

So the page table exists for 0 to 896MB of Physical RAM and for
accessing more than 896MB it temporary creates mappings with-in its
virtual address range already reserved for Highmemory mappings .....

> isn't it a lot of mostly-unused memory ?
>

No its not unused memory because in modern operating systems and in
Linux too the approach is not keep free memory there ... rather use
all memory for caching to speed-up the things and when some one needs
memory it simply fullfills the requirement from the memory already in
use for caching .... Although page structures and page tables uses and
required memory but that memory we can't avoid as those have to be
kept some where in memory for fast accessing .... and 0 to 896MB only
Physical Memory mapping/page tables are created to use the memory as
much less as possible for them .... because if the system has 32GB of
RAM and kernel create all the page-tables then u can think that more
than 32-times of memory required for keeping page-tables as compare to
keep them only for less than 1GB RAM ....

(I might not be so clear to explain and might be missing something, so
others plzz do make them correct)

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2006-01-12 12:40 |只看該作者
dfsf

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2006-01-12 12:42 |只看該作者
這兩天,我怎么都不能發(fā)貼,不知怎么搞的!唉...

現(xiàn)在許多人對(duì)linux的內(nèi)存使用量感到迷惑,老是覺得自己的機(jī)子內(nèi)存無緣無故的被用完了,我想看了上面的東西,你們應(yīng)該明白這是怎么回事。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2006-01-13 15:28 |只看該作者
原帖由 snow_insky 于 2006-1-12 12:42 發(fā)表
這兩天,我怎么都不能發(fā)貼,不知怎么搞的!唉...

現(xiàn)在許多人對(duì)linux的內(nèi)存使用量感到迷惑,老是覺得自己的機(jī)子內(nèi)存無緣無故的被用完了,我想看了上面的東西,你們應(yīng)該明白這是怎么回事。



Solaris也有類似的機(jī)制,幾乎所有現(xiàn)代系統(tǒng)都有。

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2006-01-13 15:59 |只看該作者
原來內(nèi)存被用的越多,意味著你的機(jī)器在處理上可以跑的更快一點(diǎn)?

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2006-01-13 16:03 |只看該作者
原帖由 hjxisking 于 2006-1-13 15:59 發(fā)表
原來內(nèi)存被用的越多,意味著你的機(jī)器在處理上可以跑的更快一點(diǎn)啊?

--編輯了半天, 本著厚道的原則, 自己刪掉了。

學(xué)習(xí)一點(diǎn)BIO的知識(shí)吧, 懂個(gè)大概再來批評(píng), 好嗎?

[ 本帖最后由 albcamus 于 2006-1-13 16:06 編輯 ]

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2006-01-14 14:33 |只看該作者
原帖由 hjxisking 于 2006-1-13 15:59 發(fā)表
原來內(nèi)存被用的越多,意味著你的機(jī)器在處理上可以跑的更快一點(diǎn)啊?


我想我們也應(yīng)該聽到這種反對(duì)的聲音,這樣才能討論嘛,謝謝!

是這樣的,查看linux系統(tǒng)中處于free狀態(tài)的內(nèi)存有兩個(gè)角度,一個(gè)是從內(nèi)核的角度來看,一個(gè)是從應(yīng)用層的角度來看的。

1.從內(nèi)核的角度來看free的內(nèi)存,就是內(nèi)核目前可以直接分配到,不需要額外的操作,這個(gè)free值是不包括系統(tǒng)中處于buffer和cache狀態(tài)的內(nèi)存;但是在內(nèi)核需要時(shí),或在系統(tǒng)運(yùn)行逐步推進(jìn)時(shí),buffer和cache狀態(tài)的內(nèi)存可以變?yōu)閒ree狀態(tài)的內(nèi)存。

2.從應(yīng)用層的角度來看系統(tǒng)處于free狀態(tài)的內(nèi)存,這個(gè)值是包括處于buffer和cache的,所以應(yīng)用層分配內(nèi)存時(shí),可以直接從buffer和cache中拿。

linux系統(tǒng)之所以提高這種機(jī)制,是因?yàn)榘褍?nèi)存都置為free狀態(tài),還不如把最近使用過的內(nèi)存緩存起來(如從磁盤中讀取的數(shù)據(jù)),這樣再次需要這些數(shù)據(jù)時(shí)可以直接從內(nèi)存中取,而不需要有一個(gè)漫長(zhǎng)的磁盤操作,這樣可以提高系統(tǒng)的整體性能。因?yàn)閒ree狀態(tài)的內(nèi)存中的內(nèi)容是不可用的,與其閑置還不如發(fā)揮它們的作用。而在系統(tǒng)需要時(shí),又可以快速的從這些可釋放的內(nèi)存中分配,我想這種機(jī)制是非常好的,老兄您認(rèn)為呢?一個(gè)普通人都知道...呵呵

下面我們來看看free命令的結(jié)果:

             total       used       free     shared    buffers     cached
Mem:           500        355        145          0         67        249
-/+ buffers/cache:         38        462
Swap:          996          1        994

在這個(gè)結(jié)果中的第一行是從內(nèi)核角度來看系統(tǒng)內(nèi)存使用狀態(tài)的,可以看到free的內(nèi)存只有145M;
第二行是從應(yīng)用層的角度來看系統(tǒng)內(nèi)存的使用狀況,可以看到free的內(nèi)存有462M;

你有沒有看到462這個(gè)值的妙處呢????462 := 145 + 249 + 67

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2006-01-18 13:41 |只看該作者
好啊,雖然本來就知道。
其實(shí)windows下也有disk cache使用了ram,不過沒有這么明顯而且(使用得沒有那么充分),linux下是盡可能地是用空閑地ram來cache。

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2006-02-04 14:12 |只看該作者
好文。。   
     
在我的筆電上 vm.swappiness = 40 時(shí)

系統(tǒng)反應(yīng)速度有明顯上升
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP