Last update at :2024-02-07,Edit by888u
In short, RAMDISK takes out part of the machine's memory and uses it as a hard disk. Due to the inherent advantages of memory, the memory disk has the advantage of high IO, and the read and write speed is simply unmatched by ordinary HDD/SSD. However, RAMDISK cannot save data permanently. Once the machine is restarted or shut down, the data will disappear, so RAMDISK is generally used to store temporary files.
Generally for newer CentOS7 system versions, you can directly create a RAMDISK hard disk with a size of 16GB through the following command:
modprobe brd rd_nr=1 rd_size=16777216 max_part=0
rd_size can be adjusted according to the actual memory of your machine. For example, my machine has a lot of free memory, so I created 16GB.
If the creation is normal, execute the following command:
ls /dev/ram*
It should be possible to display a ram0 device:
Then we can format the device directly (there is no need to partition the device if it is 16GB):
mkfs.ext4 /dev/ram0Create a mounting directory after completion:
mkdir -p /ramdiskMount it:
mount /dev/ram0 /ramdiskCheck whether the mounting is normal:
The creation of such a memory disk is completed. Now we can put the files in the /ramdisk directory to experience the speed difference between memory and hard disk~
If you need to start RAMDISK at boot, you can execute the following commands in sequence to configure:
echo "options brd rd_nr=1 rd_size=16777216 max_part=0" >> /etc/modprobe.d/memdisk.conf echo "mkfs.ext4 /dev/ram0" >> /etc/rc.d/rc.local echo "mount /dev/ram0 /ramdisk" >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local
If you need to unmount the memory disk, you can unmount it first:
umount /dev/ram0
Then execute the following command:
modprobe -r brd
Below I used the unprofessional dd command to briefly test the read and write speed of this memory disk. The results are for reference only. If you need professional testing, please use fio or sysbench.
Test write:
dd if=/dev/zero of=/ramdisk/lala.im bs=8k count=500000 conv=fsync
Result:
Test reading:
dd if=/ramdisk/lala.im of=/dev/null bs=8k
Result:
Original text from: https://lala.im/4559.html
Recommended site searches: domain name check, forum host, IP agent, domain name space agent, website registration number query, independent IP, domain name registration number query, free domain name, registered domain name purchase, Shandong website registration,
发表评论