CentOS5.2后默认的ramdisk的大小只有16M,通过以下的方法可以修改默认大小:
修改/etc/grub.conf
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-92.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet ramdisk_size=131072
initrd /initrd-2.6.18-92.el5.img
以上设置的大小为124M。ramdisk_size=524288 最大512M。
每次重启后自动生效的方法:
编辑/etc/rc.local
/sbin/mke2fs -q -m 0 /dev/ram0
/bin/mount /dev/ram0 /mnt/rd0
/bin/chown root /mnt/rd0
/bin/chmod 0750 /mnt/rd0
Ramdisk 的读写速度测试如下:
写入速度:
#time dd if=/dev/zero of=test.dbf bs=8k count=100000 conv=fsync
100000+0 records in
100000+0 records out
819200000 bytes (819 MB) copied, 1.35819 seconds, 603 MB/s
real 0m1.369s
user 0m0.030s
sys 0m1.330s
读取速度:
# time dd if=/dev/ram0 of=/dev/null bs=8k
512000+0 records in
512000+0 records out
4194304000 bytes (4.2 GB) copied, 3.00381 seconds, 1.4 GB/s
real 0m3.029s
user 0m0.010s
sys 0m2.995s
另外一个方法是用tmpfs 来实现:
手工命令行实现:
mount -t tmpfs tmpfs /tmp_dir/ -o size=5M
该命令创建5M 的内存空间
如果下次系统启动生效,请在下面的文件中增加:
vi /etc/fstab
tmpdisk /tmp_dir/ tmpfs rw,size=3G 0 0