2009年6月20日星期六

初识slab分配器

在进程描述符的调度中,涉及到slab的原理,但从其根本上说其是一个内存的分配机制。
先试探其来源、发展的历史,然后从其功能、优点、缺点等作笼统性的概括,最后以一个linux的实例来分析它。
linux的slab机制从sun的sun os5.4继承过来和发展的。
linux通过slab分配器分配task_struct结构,这样能达到对象复用和缓存着色的目的。

分配和释放数据结构是所有内核中最普遍的操作之一。为了便于数据的频繁分配和回收,编程者常常会用到一个空闲链表。该空闲链表包含可供使用的、已经分配好的数据结构块。当代码需要一个新的数据结构实例时,就可以从空闲链表中抓去一个,而不需要分配内存、再把数据放进去。以后,当不再需要这个数据结构的实例时,就把它放回空闲链表、而不是释放掉它。从这个意义上说,空闲链表相当于对象高速缓存以便快速存储频繁使用的对象类型。

在内核中,空闲链表面临的主要问题之一就是不能全局控制。当内存变的紧缺时,内核无法通知每个空闲链表,让其收缩缓存大小以便释放出一些内存来。实际上,内核根本就不知道存在任何空闲链表。为了弥补这一缺陷,也为了使代码更加稳固,linux内核提供了slab层。slab分配器扮演了通用数据结构缓存层的角色。

slab试图在几个基本原则之间寻求一种平衡:

频繁使用的数据结构也会频繁分配和释放,因此应当缓存它们。
频繁分配和回收必然会导致内存碎片。
回收的对象可以立即投入下一次分配。
如果让部分缓存专属于单个处理器,那么,分配和释放就可以在不加SMP锁的情况下进行。
对存放的对象进行着色,以防止多个对象映射到相同的高速缓存行。

1、不同的数据类型用不同的方法分配内存可能提高效率。比如需要初始化的数据结构,释放后可以暂存着,再分配时就不必初始化了
2、内核的函数常常重复地使用同一类型的内存区,缓存最近释放的对象可以加速分配和释放对内存的请求可以按照请求频率来分类,频繁使用的类型使用专门的缓存,很少使用的可以使用类似2.0中的取整到2的幂次的通用缓存
3、使用2的幂次大小的内存区域时高速缓存冲突的概率较大,有可能通过仔细安排内存区域的起始地址来减少高速缓存冲突缓存一定数量的对象可以减少对buddy系统的调用,从而节省时间并减少由此引起的高速缓存污染

Slab分配器把存储器区看作对象(object)
Slab分配器把对象按照类型分组成不同
每个Slab由一个或多个连续的页框组成,这些页框中包含已分配的对象,也包含空闲的对象
Slab分配器通过伙伴系统分配页框

2009年6月16日星期二

Intel 8xx series graphics card not well support KMS

1.What is kernel modesetting(KMS)?
Currently, most graphics modes are initialized during the X server startup. Kernel Modesetting (referred to as KMS hereafter) moves this process from the X server's DDX drivers to the kernel, and it enables several new features including:

* Improved Graphical Boot
* Faster fast user switching
* Seamless X server switching
* Graphical panic messages

Memory Management, while a separate feature in its own right, is included here because it is a requirement for Kernel Modesetting.

2.Fedora 11 enable this by default

3.However, Intel 8xx graphics card or earlier edition did not well support this. So KMS may produce several troubles.



4.how to find the informaiton of your video card?

>lspci | grep VGA



5.How to figure it out?

disable KMS.

To fix, disable kernel mode setting (KMS) by adding the following to the kernel parameters in /etc/grub.conf after "rhgb quiet" "nomodeset". But if you still want the graphical boot screen then add this also "vga=0x318".

Why IBM 360 Model 65 and 75, staggered in two separate main memory units

IN IBM 360 model 65 and 75 address are staggered in two seperate main memory units( all even number words in one unit and all odd number words in another unit)What might be the purpose of this technique?

Answers:

多体交叉存储器,使用地址交叉法,有多套读写电路并行访问,提高速度。

The memory is divided into two blocks, even and odd blocks called low order and high order blocks with odd addresses is termed as low order and the blocks with even addresses is referred as high order blocks. In odd it stores arithmetic and will come in single word and in even it stores floating point numbers and will come in two words. Also to maintain the old architecture because the old one used 8-bit register and this new one use 16-bit of 8,8 bit each.Suppose you want to read a word from location 125. Okay, the L.O. byte of the word comes from location 125 and the H.O. word comes from location 126.
The advantage of using even and odd registers is that we can access up to two words. This increase the speed and efficiency of the whole system.
Think of memory as a linear array of bytes. The address of the first byte is zero and the address of the last byte is (2**n)-1.
To execute the equivalent of the Pascal statement "Memory [125]:= 0;" the CPU places the value zero on the data bus, the address 125 on the address bus, and asserts the write line (since the CPU is writing data to memory:

The above discussion applies only when accessing a single byte in memory. So what happens when the processor accesses a word or a double word? Since memory consists of an array of bytes, how can we possibly deal with values larger than eight bits?



The 80x86 family deals with this problem by storing the L.O. byte of a word at the address specified and the H.O. byte at the next location.
The IBM Models 65 & 75 used two separate registers namely odd register & even register for odd-numbered words & even-numbered words respectively. The actual idea behind the application of this technique was that the integers at that time required only one word & hence rightly labeled as odd-numbered word, while floating points required two words & hence named as even-numbered words. Thus the two types of values were stored in two different registers as mentioned above.
The following were the major advantages: -
• Memory was greatly saved by allotting almost exactly the required space. At that time, memory was very limited & costly.
• Accessing the address was much faster mentioning the address was not required. Because on finding the integer value it will automatically go to odd register & on encountering floating point value, it will automatically go to even register.
• Parallel accessing the two registers was possible by a single clock. So processing speed was increased.