一、目的

1.熟悉类 UNIX 系统的 I/O 设备管理
2.熟悉 MINIX 块设备驱动
3.熟悉 MINIX RAM 盘

二、内容与设计思想

测试 RAM 盘和 DISK 盘的文件读写速度,分析其读写速度 差异原因(可用图表形式体 现在实验报告中)。

三、使用环境

Minix,Moba

四、实验过程

1、增加 RAM 盘: 修改/usr/src/minix/drivers/storage/memory/memory.c ,增加默认的用户 RAM 盘数: RAMDISKS=7。重新编译内核,reboot。

2、创建设备 mknod /dev/myram b 1 13,查看设备是否创建成功输入 ls /dev/ | grep ram。 实现 buildmyram 初始化工具(用于分配容量)。

3、参考/usr/src/minix/commands/ramdisk/ramdisk.c,实现 buildmyram.c,但是需要将 KB 单 位修改成 MB。

4、编译 buildmyram.c 文件,然后执行命令: buildmyram /dev/myram。创建一 个 RAM 盘。

5、在 ram 盘上创建内存文件系统,mkfs.mfs /dev/myram。将 ram 盘挂载到用户目录下,mount /dev/myram /root/myram,查看是否 挂在成功:输入 df。

注:重启后用户自定义的ram盘内容会丢失,需要重新设置大小,创建文件系统,并挂载。
6、出现write error错误,应该是因为空间太小了,可以考虑缩小读写次数或者增大磁盘容量,我这里将128MB设置成1GB,这个问题就消失了。

五、总结

刚开始,因为追求块大小的最大值将其设为65536,导致重复的次数减少设为500,最终得出了disk性能优于ram的结论,与假设矛盾。所以之后将块大小调成4096,而增加重复次数为10000,并且删除myram文件夹里的缓存文件,结论恢复正常,但读操作仍然还有改进空间。

六、测试代码

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <sys/wait.h>/* macro */
#define Concurrency 15      // max concurrent process
//#define repeat 500          // repeat times
#define repeat 10000          // repeat times
//#define Blocksize 65536     // max blocksize
#define Blocksize 4096     // max blocksize
#define maxline (50 * 1024) // array size
#define mod 1000000007      // a big prime number/* global variables */
long long writetext[maxline];                     // testing array
long long readbuff[maxline];                      // buff array
struct timeval starttime, endtime, spendtimeSpec; // used to calculate time
char *filepathdisk[19] ={"/usr/disk1.txt", "/usr/disk2.txt", "/usr/disk3.txt", "/usr/disk4.txt","/usr/disk5.txt", "/usr/disk6.txt", "/usr/disk7.txt", "/usr/disk8.txt","/usr/disk9.txt", "/usr/disk10.txt", "/usr/disk11.txt", "/usr/disk12.txt","/usr/disk13.txt", "/usr/disk14.txt", "/usr/disk15.txt", "/usr/disk16.txt","/usr/disk17.txt", "/usr/disk18.txt", "/usr/disk19.txt"};
char *filepathram[19] ={"/root/myram/ram_test1", "/root/myram/ram_test2", "/root/myram/ram_test3", "/root/myram/ram_test4","/root/myram/ram_test5", "/root/myram/ram_test6", "/root/myram/ram_test7", "/root/myram/ram_test8","/root/myram/ram_test9", "/root/myram/ram_test10", "/root/myram/ram_test11", "/root/myram/ram_test12","/root/myram/ram_test13", "/root/myram/ram_test14", "/root/myram/ram_test15", "/root/myram/ram_test16","/root/myram/ram_test17", "/root/myram/ram_test18", "/root/myram/ram_test19"};/* write files */
void write_file(int blocksize, bool isrand, char *filepath)
{int fp = open(filepath, O_RDWR | O_CREAT | O_SYNC, 0755);if (fp > 0){for (int i = 0; i < repeat; i++){int x = write(fp, writetext, blocksize);if (x < 0){printf("write error!");break;}if (!isrand)lseek(fp, (repeat-1)*(rand() % blocksize), SEEK_SET);}}else{printf("open error!");}lseek(fp, 0, SEEK_SET);
}/* read files */
void read_file(int blocksize, bool isrand, char *filepath)
{int fp = open(filepath, O_RDONLY);int i = 0;if (fp > 0){for (; i < repeat; i++){int x = read(fp, readbuff, blocksize);if (x < 0){printf("read error!\n");break;}if (!isrand)lseek(fp, (repeat-1)*(rand() % blocksize), SEEK_SET);}}else{printf("open error!");}lseek(fp, 0, SEEK_SET);
}/* get time left */
long get_time_left(struct timeval starttime, struct timeval endtime)
{long spendtime = 1000000 * (endtime.tv_sec - starttime.tv_sec) + (endtime.tv_usec - starttime.tv_usec); /* us */return spendtime;
}void test1()
{printf("Ram Sequential Write\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){write_file(block, true, filepathram[i]); //ram sequential writeexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test2()
{printf("Ram Random Write\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){write_file(block, false, filepathram[i]); //ram random writeexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test3()
{printf("Ram Sequential Read\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){read_file(block, true, filepathram[i]);  //ram sequential readexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB*/long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test4()
{printf("Ram Random Read\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){read_file(block, false, filepathram[i]); //ram random readexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB*/long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test5()
{printf("Disk Sequential Write\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){write_file(block, true, filepathdisk[i]);  //disk sequential writeexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test6()
{printf("Disk Random Write\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){write_file(block, false, filepathdisk[i]); //disk random writeexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test7()
{printf("Disk Sequential Read\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){read_file(block, true, filepathdisk[i]);  //disk sequential readexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}
}void test8()
{printf("Disk Random Read\n");printf("block\tprocess\tlatency\n");double BLOCK=0;double LATENCY=0;for (int block = 64; block <= Blocksize; block *= 2){for (int concurrency = 1; concurrency <= Concurrency; concurrency ++){gettimeofday(&starttime, NULL);for (int i = 0; i < concurrency; i++){if (fork() == 0){read_file(block, false, filepathdisk[i]); //disk random readexit(1);}}// wait children to terminatewhile (wait(NULL) != -1);gettimeofday(&endtime, NULL);/* calculate the duration, latency, file_MB */long alltime = get_time_left(starttime, endtime);                        // get the duration (us)double latency = (alltime) / (double)repeat / (double)concurrency;       // single file latency (us)double file_MB = (double)block * repeat * concurrency / 1024.0 / 1024.0; // filesize in totalBLOCK+=block;LATENCY+=latency;printf("%d\t%d\t%.2f\n", block, concurrency, latency);}double throughput=BLOCK/LATENCY;printf("%.3f\n",throughput);BLOCK=LATENCY=0;}}int main()
{srand((unsigned)time(NULL));int i = 0;// initial a test arrayfor (int j = 0; j < maxline; j++)writetext[j] = (j * j * j - 3 * Blocksize * j) % mod;test1();printf("\n");test2();printf("\n");test3();printf("\n");test4();printf("\n");test5();printf("\n");test6();printf("\n");test7();printf("\n");test8();printf("\n");return 0;
}

测试 RAM 盘和 DISK 盘的文件读写速度相关推荐

  1. 显卡显存测试u盘 mats 百度网盘_网盘数据不安全?还不如固态U盘来得踏实,而且传输速度还很快...

    最近全网传遍了一则消息:百度网盘将要对在2018年12月25日至2019年12月31期间从未登录过百度网盘账号的用户进行存储空间调整,调整后的储存空间为100GB,若有超过100GB的文件,网盘将只支 ...

  2. android u盘拷贝文件大小,用手机U盘备份或导出手机文件,还能扩容

    前言 随着各类手机APP的不断升级.各大手机相机功能的不断优化,手机的内存也越来越大. 但即便如此,我们还是会经常收到手机内存满的提示,于是土豪选择买新手机,普通人则选择备份手机里的东西来减少手机的内 ...

  3. 精品分享:基于 SpringBoot + Vue 开发的云盘系统(含大文件断点续传剖析)

    引言 作为开发人员,我们经常需要存储和下载文件,为了使用方便,通常都会将文件存储在云端,市面上使用率最高的云端存储莫过于百度网盘了,但使用别人的东西难免会受到各种各样的限制,必须花钱才会享受到更好的服 ...

  4. 计算机弹出虚拟U盘,我们通过工具所自带的电脑模拟器对我们u盘制作启动盘进行模拟启动测试...

    系统之家WinXP系统u盘制作成启动盘制作教程.现在光驱慢慢退出了我们的电脑必备配置中,而且向win8.1~win10,微软官方都不提供光盘销售了,那么怎么安装系统之家WinXP系统呢.有需要的用户, ...

  5. 使用disk genius合并C盘和D盘

    遇到过很多次C盘可用空间已经为0了,想扩大C盘空间,但由于水平问题,一直不能合并C盘和其它的盘.今天看到有台电脑因为C盘可用空间还有20K,不管打开什么都无法运行,没办法,只能想办法了. 看到她的D盘 ...

  6. 32g的u盘速度测试软件,傻乎乎买U盘被坑篇:USB2.0速度究竟有多低,闪迪酷晶系列快测!...

    HELLO,我是小学弟. 上一个U盘在上版式设计课的时候忘了机房了里了,再去找也没找到,U盘里资料倒是不多,全都网盘备份过,只是可惜我U盘的里的那些小姐姐. 再来个大写的表情: 你们肯定会说,你不是还 ...

  7. U盘作为启动盘使用GRUB2 引导 iso 文件安装各种系统

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/li740207611/article/ ...

  8. linux环境下,模拟百度网盘上传、下载文件

    目录 1.题目 2.运行截图 3.总体设计 4.详细设计 5.源码 5.1服务端 5.2客户端 1.题目 1)模仿百度网盘实现一个文件上传.下载.浏览的终端网盘; 2)能够实现文件和目录的存储; 3) ...

  9. 计算机用户文件夹迁移,Win7系统通过注册表将用户目录转移到D盘或其他盘的方法...

    在win7系统中,默认用户目录是在C盘的,可是许多用户觉得这样会占用C盘空间,就想要将用户目录转移到D盘或其他盘,那么我们可以通过注册表来实现,现在给大家分享一下Win7系统通过注册表将用户目录转移到 ...

最新文章

  1. fftw与matlab中的fft对比,基于FFTW的FFT和IFFT
  2. android mp4流格式,将RTSP流保存到android中的mp4文件
  3. Java提高班(一)Thread详解
  4. T-SQL笔记6:GO
  5. jzoj4274-终章-剑之魂【位运算,贪心】
  6. rstudio查询命令_Rstudio支持可视化的Markdown编辑了?
  7. C++基础与深度解析第三章:数组、vector与字符串
  8. javaweb课程PSP(1)
  9. 编译器和解释器(Compiler and Interpreter)
  10. mysql数据库:mysql增删改、单表、多表及子查询
  11. vue 判断权限过期_vue 路由权限
  12. 心理正常与异常的区分_正常心理与异常心理的区分
  13. 基于node.js的express使用数据库时,解决异步调用的问题
  14. 2022年6月25日PMP考试通关宝典-3
  15. java 多线程课件_Thread_java多线程参考源码_ppt_大学课件预览_高等教育资讯网
  16. 分布式服务架构读书笔记-第六章 Java服务的线上应急和技术攻关
  17. 盗心贼歌曲用计算机多少数字,抖音上常见背景音乐歌词盗心的贼是那首歌?
  18. [山东科技大学OJ]1653 Problem C: 藏头诗
  19. PPSIG携手100+位contributor,共建飞桨开源社区
  20. 世界排名第 3 的滴滴裁员,开春求职必知的独角兽排行榜

热门文章

  1. 酬岑勋见寻就元丹丘对酒相待,以诗见招
  2. Unity2019_音效系统
  3. 使用Postman获取天气接口API(Json格式)
  4. 渠道分销系统开发产品管理功能
  5. 戏说:诸葛亮的真实身份竟是汉献帝
  6. node拉取微信权限,实现自定义分享微信朋友圈等操作
  7. MATLAB和Python求解非线性常微分方程
  8. 怎样制作u盘系统安装盘图文教程
  9. mui-app开发之项目类型概览
  10. 苹果CMS10 影视模板程序源码