日期:2014-05-16  浏览次数:20590 次

Linux内核源代码解析之——我与神童聊Linux内核

本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/11619609


我的朋友里,至少有2.5个神童。

有的书上说,一个人的能力取决于他的朋友圈子的能力。所以,我是幸运的,因为我的很多朋友都比我更优秀。

雅丽是公认的神童。北漂族、帅气、博学、擅长多国语言,同时,公认的Oracle大神。他自认是个文科生,跟计算机毫无关系,不过大量的兄弟伙在他们的Oracle数据库快死的时候会向雅丽求救,同时,获得起死回生的灵药。

童鞋们感兴趣可以去他的院子逛逛:http://www.dbaleet.org/

在我的朋友里,老周是另外一个神童。或许,只有老周能在英语上与雅丽一较高下——老周的爷爷二战时,是美国大兵的翻译官。

他和雅丽有很多共同之处。比如说,语言上的天赋、年龄。

虽然他们都是神童,但并不是说,他们的年龄很小,相反,他们的年龄都比我大。只不过,他们的年纪相比于他们的能力,实在太小了。

今天聊了一个关于mlock的话题。

mlock的代码在Linux内核里只经历过2个作者的维护。

原作者是Linus Torvalds,起源于1995年。

修改者是Christoph Hellwig,修改于2002年。

之后一直没有变动。

自RedHat Linux 6之后,RedHat Linux内核给Lru list加了一个patch——Split Lru

详细介绍如下:

 Starting from the premise that not all data is equal, a Red Hat engineer implemented a set ofpatches that handle different types of pages differently and finds pages that can be evicted withminimal scanning. These patches were, of course, pushed upstream and accepted into the Linuxkernel before being included in Red Hat Enterprise Linux 6. The result is the Split LRU VM (Splitleast recently used virtual memory manager).The Split LRU VM uses several lists of memory pages instead of a single, monolithic memorymanager. These include separate page lists for filesystem backed data (the master data exists ina file in the storage subsystem and can be read again whenever needed), swap backed data (theVM can page out memory to disk and read it back in when needed), and non-reclaimable pages(pages that can not be discarded by the VM).

那mlock是否会被split lru影响呢?

split lru把原本单一的lru list划分成了多个队列表。

其中,包括filesystem backed data zone,swap backed data zone,non-reclaimable pages zone。

关键点就在这里,Linux内核怎么知道一个page应该挂接在哪一个zone里呢?

翻一下mlock.c这个文件吧。

生命是多么美好:)