Linuxer's Blog

世界很大,我太渺小
学习感悟
程序员的乐趣

Linux cached and buffers memory

Linuxer posted @ 2010年10月16日 08:12 in 未分类 , 6027 阅读

我们都知道Linux 的free memory是有两种算法的,一种是系统实际剩余的物理内存,一种是加上系统的cached住的临时缓存后的总剩余内存数,如下面标示的两个free值。

total       used       free     shared    buffers     cached
Mem:       1986376     891920    1094456          0      44352     462224
-/+ buffers/cache:     385344    1601032
Swap:      3695604          0    3695604

内核通过一组内核线程pdflush去管理缓存,有三种方式去释放缓存区。

1. 当脏缓存页保留一段时间后,内核就会显式地开始把脏页写到磁盘。

2. 缓存区达到一定阀值时,pdflush会去主动回收。

3. 使用sync、fsync和fdatasync系统调用将缓存区刷新到磁盘。

所以那些buffers、cached中的缓存空间,在系统需要的时候,它会主动让出空间来做它用。

buffers和cached的区别主要是, buffers是块设备的读写缓存区,是物理级的,如你对裸盘的读写。cached是作为page caches,是针对文件系统的页缓存,文件的读写都是缓存在这里面的。page cache的数据需要刷新时,page cache中的数据交给buffer cache(这种操作在2.6内核后变的简单了,具体怎么简单?)。

手动回收cache的方法:

方法一:

# And free up caches
#
echo Freeing the page cache:
echo 1 > /proc/sys/vm/drop_caches
echo Free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
echo Free the page cache, dentries and the inodes:
echo 3 > /proc/sys/vm/drop_caches

当然这种方法也适用与sysctl。

方法二:

fcntl(fd, F_SETFL, O_DIRECT)

对文件描述符设置O_DRECT,会避免cache该文件的内容,直接读写磁盘。在大量数据传输的时候,会避免占用大量缓存,而且传输效率也不会下降什么。

方法三:

降低如下阀值的数值,有利于回收缓存,但会影响性能,这些设置要根据具体环境来调优。

/proc/sys/vm/dirty_ratio

/proc/sys/vm/dirty_background_ratio

/proc/sys/vm/dirty_expire_centisecs

方法四:

sysctl -w vm.vfs_cache_pressure=n  (n > 100)

这会使Kernel更勤于回收cache。

Avatar_small
cleaning company in 说:
2019年9月14日 15:56

Pertaining to larger jobs like an apartment sophisticated, a full price complex, an workplace, a lodge, or a huge leasing area, a fulltime cleaning service is liable in get. Janitorial services might be much more cost efficient than obtaining an in-house better. Plus, you can find a promise from nearly all cleaning companies and also proof involving insurance.

Avatar_small
riverbankmarketing.c 说:
2019年11月14日 00:41

I . t consultants accomodate business clients to extend the i . t department during an organization. Consultants help out companies with the implementation in new technology with the organization.

Avatar_small
eastern iowa news 说:
2020年3月19日 20:05

Reading through the document online as well as watching 24-hour information sites is becoming a lot more popular. The reason being it is actually cheaper and also you get much more news. You can observe what is going on on the planet, as this happens.

Avatar_small
bio hazard technolog 说:
2020年3月19日 20:06

Technology within the long-run is actually irrelevant. That's what a person of mine explained when We made the presentation in order to him in regards to a new item. I have been talking concerning the product's functions and advantages and detailed "state-of-the-art technology" or even something to that particular effect, as one of these.

Avatar_small
thai citrus technolo 说:
2020年3月19日 20:06

Lots of people mistakenly believe that it is technology that drives development. Yet in the definitions over, that is actually clearly false. It is actually opportunity that defines development and technologies which allows innovation. Think about the traditional "Build a much better mousetrap" instance taught in many business colleges.

Avatar_small
handi sports 说:
2020年3月19日 20:06

Within the sports industry, peak overall performance in sports happens to be a much desired state through players as well as coaches of levels. If the athletes tend to be school kids soccer gamers or Olympians striving for his or her Gold medals, maximum performance within sports offers always drawn athletes as well as coaches as well.

Avatar_small
pr home school 说:
2020年3月19日 20:07

That is literally true in terms of buying a property. To turn into a first-time residence buyer, you must know where and the way to begin your home buying method. The pursuing questions and also answers are already carefully selected to offer a base of basic familiarity with home acquiring.

Avatar_small
pr home school 说:
2020年3月19日 20:08

That is literally true in terms of buying a property. To turn into a first-time residence buyer, you must know where and the way to begin your home buying method. The pursuing questions and also answers are already carefully selected to offer a base of basic familiarity with home acquiring.

Avatar_small
full time maids in d 说:
2020年4月28日 19:14

For anyone who is recruiting servant maid with the agency, look at its consistency, referrals connected with current buyers, about the maid's insurance coverage, how long there're doing ebay etc. Ask whether or not they guarantee the servants and whether or not they performed any criminal history checks on the maids.

Avatar_small
painting company in 说:
2020年4月28日 19:15

In contrast, if you choosed to go additional route in addition to hire household painters; you're not required to help lift 1 finger. Professionals will work the meet your needs exactly, of course providing you pay these individuals considerably. Painters will be sure that everything is finished according for your requirements and needs.

Avatar_small
seo service UK 说:
2024年5月11日 23:26

Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome Prof Peter Horby, an expert in infectious diseases at University of Oxford, said: "A safe, affordable, and effective oral antiviral would be a huge advance in the fight against Covid.

Avatar_small
카지노쿠폰 说:
2024年5月20日 14:28

Great work! That is the kind of info that should be shared across the internet. Shame on Google for now not positioning this submit upper! Come on over and visit my web site . Thanks =)

Avatar_small
토토하이 说:
2024年5月20日 14:29

I think one of your commercials triggered my web browser to resize, you may well want to put that on your blacklist.

Avatar_small
baccarat friends 说:
2024年5月20日 14:30

This may be the proper weblog for desires to find out about this topic. You know so much its virtually challenging to argue along (not too I really would want…HaHa). You definitely put a new spin for a topic thats been revealed for some time. Excellent stuff, just great!

Avatar_small
먹튀검증 说:
2024年5月20日 15:06

If more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content.

Avatar_small
사설토토사이트 说:
2024年5月20日 15:07

Even nevertheless there are lots of decision methods with the purpose of lookup used for non published numbers, but you would approximating rapid stately results to you possibly will look forward to in, you possibly will necessitate with the purpose of desire particular sort of swap telephone search company.

Avatar_small
토토사이트순위 说:
2024年5月20日 15:08

Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards.

Avatar_small
먹튀검증사이트 说:
2024年5月20日 15:29

Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards.

Avatar_small
메이저사이트목록 说:
2024年5月20日 15:30

Two full thumbs up for this magneficent article of yours. I've truly delighted in perusing this article today and I figure this may be outstanding amongst other article that I've perused yet. If it's not too much trouble keep this work going ahead in a similar quality.

Avatar_small
카지노사이트 说:
2024年5月20日 15:30

Oh my goodness! an amazing article dude. Thank you Nonetheless I’m experiencing concern with ur rss . Don?t know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anyone who is aware of kindly respond. Thnkx

Avatar_small
카지노 说:
2024年5月20日 16:32

Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking

Avatar_small
먹튀폴리스주소 说:
2024年5月20日 16:33

<a href="https://www.fknapredak.com/">먹튀폴리스주소</a>

Avatar_small
토토사이트 说:
2024年5月20日 16:33

Woah I’m just genuinely digging the style/thought of this web site. It’s straightforward, however fantastic. Additional frequently than not it is demanding to acquire the perfect involving exceptional usability along with visual physical appearance. I should say you have carried out a brilliant task. In addition, your web page starts tremendous rapidly personally with Web explorer. Outstanding Internet site

Avatar_small
메이저놀이터추천 说:
2024年5月20日 16:34

This is really likewise an incredibly beneficial placing most of us severely encountered shopping as a result of. It truly is faraway from each and every day we have now possibility to think about something. 

Avatar_small
토토사이트 说:
2024年5月20日 16:38

I think one of your commercials triggered my web browser to resize, you may well want to put that on your blacklist.

Avatar_small
토토사이트 说:
2024年5月20日 16:39

Oh my goodness! an amazing article dude. Thank you Nevertheless I am experiencing situation with ur rss . Don?t know why Unable to subscribe to it. Is there anyone getting identical rss downside? Anybody who is aware of kindly respond. Thnkx

Avatar_small
사설토토사이트 说:
2024年5月20日 16:39

Oh my goodness! an amazing article dude. Thank you Nevertheless I am experiencing situation with ur rss . Don?t know why Unable to subscribe to it. Is there anyone getting identical rss downside? Anybody who is aware of kindly respond. Thnkx

Avatar_small
토토사이트 说:
2024年5月20日 16:42

Hi, i feel that i noticed you visited my website so i got here to ?go back the prefer?.I’m trying to to find things to enhance my website!I guess its ok to use some of your ideas!!

Avatar_small
안전놀이터 说:
2024年5月20日 16:43

This is really likewise an incredibly beneficial placing most of us severely encountered shopping as a result of. It truly is faraway from each and every day we have now possibility to think about something. 

Avatar_small
토토사이트추천 说:
2024年5月20日 16:44

Operational Challenges:New Rabbit's continuous address changes may pose inconveniences for users seeking a stable and reliable webtoon experience.

Avatar_small
토토사이트 说:
2024年5月20日 16:45

Hello, you used to write excellent, but the last few posts have been kinda boring? I miss your tremendous writings. Past several posts are just a little out of track! come on!

Avatar_small
먹튀사이트 说:
2024年5月20日 16:46

My partner and I absolutely love your blog and find many of your post’s to be what precisely I’m looking for. Would you offer guest writers to write content to suit your needs? I wouldn’t mind composing a post or elaborating on a number of the subjects you write in relation to here. Again, awesome site!

Avatar_small
토토안전나라 说:
2024年5月20日 16:46

It is really a nice and helpful piece of info. I?m glad that you shared this useful information with us. Please keep us informed like this. Thanks for sharing.

Avatar_small
먹튀타운 说:
2024年5月20日 16:47

Oh my goodness! an amazing article dude. Thank you Nonetheless I’m experiencing concern with ur rss . Don?t know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anyone who is aware of kindly respond. Thnkx

Avatar_small
메이저놀이터순위 说:
2024年5月20日 16:52

Thanks, I have all the files, is there any way that the geometry and mesh can be connected again? Now, I can import to a new .wbpj each file independently, so if I need to remesh my model, I need to change the geometry and start meshing from scratch.

Avatar_small
먹튀사이트조회 说:
2024年5月20日 16:54

This may be the proper weblog for desires to find out about this topic. You know so much its virtually challenging to argue along (not too I really would want…HaHa). You definitely put a new spin for a topic thats been revealed for some time. Excellent stuff, just great!

Avatar_small
안전놀이터가입 说:
2024年5月20日 16:55

Even nevertheless there are lots of decision methods with the purpose of lookup used for non published numbers, but you would approximating rapid stately results to you possibly will look forward to in, you possibly will necessitate with the purpose of desire particular sort of swap telephone search company.

Avatar_small
먹튀사이트 说:
2024年5月20日 17:39

Prevention is key, which is why we offer maintenance plans. We help you stay ahead of potential hazards and costly repairs with regular cleaning and inspections.

Avatar_small
파워사다리 说:
2024年5月20日 17:40

Operational Challenges:New Rabbit's continuous address changes may pose inconveniences for users seeking a stable and reliable webtoon experience.

Avatar_small
메이저놀이터 说:
2024年5月20日 17:41

World of warcraft! What precisely tabs opener the place has long been in my situation. Considerably preferred, bookmarked as their favorite, That i can’t look forward to even more!


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter