利用/dev/shm 加速 portage運作

chenpc May 13th, 2009

原理大致上是利用/dev/shm把portage放到記憶體裡面去。
而portage的特性是容量沒有很大,但是小檔案很多。
而小檔案在硬碟上面操作速度很慢,不管是sync或者是search。

我想要做的是寫一個boot up script,可以在開機的時候把portage tar開。
關機的時候把portage打包起來。

所以情況是
start: HD(portage.tar.gz)->RAM(/dev/shm/portage)
stop: RAM(/dev/shm/portage) -> HD(portage.tar.gz)
不管start or stop都不會讓硬碟作大量的小檔案存取。

作法:


mv /usr/portage /usr/portage.bak
mkdir /dev/shm/portage
ln -sf /dev/shm/portage /usr/portage
emerge --sync

這樣你的portage就在ram裡面了。


/etc/init.d/portage start       --->解開你的portage
/etc/init.d/portage stop        --->備份你的portage

在/etc/conf.d/portage裡面,指定你要備份的目錄。


PORTAGE_DIR=/dev/shm/portage     #放portage的目錄。
BACKUP_DIR=/usr                  #放備份檔的目錄,記得不要放在/tmp,重開機可能會被清掉。

記得/usr/portage/distfiles 和packages 要移出來。
這部份可以在/etc/make.conf裡面用:


PKGDIR="somewhere"
DISTIDR="somewhere"

在make.conf指定,或是用link把他link進去。
http://dsppc16.cs.nctu.edu.tw/~chenpc/portage
這裡是一個run script,放到/etc/init.d下面。
執行


/etc/init.d/portage start|stop|restart

即可
程式已經有稍微防呆,只要portage裡面有檔案他就不會tar 開。
裡面要是沒有檔案,他也不會打包。

目前我還沒遇到問題,但是使用前最好還是確定自己有備份。

效能:
df -h顯示shm吃了大約500MB,但是top看到只加了130MB左右,不知道怎麼回事。
RAM很多的話,可以玩看看。
start的速度大概是5秒。stop的速度也差不多5秒。
而emerge search速度非常快。
我的機器是:E8400,4G RAM,WD6400AACS。

Trackback URI | Comments RSS

Leave a Reply