CMPT 300、Operating Systems、c/c++、C++Haskell|Java

Assignment 4 – Create Simple YetFunctional File SystemCMPT 300 – Operating SystemsPlease submit a zip folder with the following naming conventions to canvas:LastName_FirstName_StudentNumber_Assig4This file should include all code, and a text file called answers.txt thatincludes answers to all questions. There may be questions for both part 1 andpart 2, so make sure that you address all questions.Part 1 - I/O and FilesystemsWelcome to LMP1, the first long MP. LMP1 is the first stage of a projectaimed at creating a simple yet functional networked filesystem. In this MP,you will learn about and use POSIX file system calls, while subsequent LMPswill introduce memory management, messaging, and networking functionality.If you implement all parts of this MP correctly, you will be able to reuseyour code for future MPs.This first LMP concentrates on the file I/O portion of the project.Specifically, you will implement a custom filesystem and test its performanceusing a filesystem benchmark. A benchmark is an application used to test theperformance of some aspect of the system. We will be using Bonnie, a realfilesystem benchmark, to test various performance aspects of the filesystemwe implement.LMP1 consists of four steps:1. Read the code; run the Bonnie benchmark and the LMP1 test suite.2. Implement Test Suite 1 functionality, encompassing basic file I/Ooperations.3. Implement Test Suite 2-4 functionality (directory operations, filecreation/deletion, and recursive checksumming).4. Modify Bonnie to use your client-server file I/O methods.Code structure--------------The code for this project is structured according to the client-servermodel. The client code (filesystem benchmark) will interact with theserver (filesystem) only through interface functions defined infileio.h:int file_read(char *path, int offset, void *buffer, size_t bufbytes);int file_info(char *path, void *buffer, size_t bufbytes);int file_write(char *path, int offset, void *buffer, size_t bufbytes);2int file_create(char *path,char *pattern, int repeatcount);int file_remove(char *path);int dir_create(char *path);int dir_list(char *path,void *buffer, size_t bufbytes);int file_checksum(char *path);int dir_checksum(char *path);These functions represent a simple interface to our filesystem. In Steps 2and 3 of this MP, you will write the code for functions implementing thisinterface, replacing the stub code in fileio.c. In Step 4, you will modify aBonnie method to use this interface, rather than calling the normal POSIX I/Ofunctions directly. The purpose of Step 4 is to help test ourimplementation.Step 1: Understanding the code------------------------------1. Compile the project, execute Bonnie and the test framework.Note: you may need to add execute permissions to the .sh files usingthe command chmod +x *.sh.Try the following:make./lmp1(this runs the Bonnie benchmark - it may take a little while)./lmp1 -test suite1(run Test Suite 1 - this has to work for stage1)make test(run all tests - this has to work for stage2)2. Read through the provided .c and .h files and understand how thisproject is organized:bonnie.c - a version of the filesystem benchmarkfileio.c - file I/O functions to be implementedfileio.h - declaration of file I/O functionsrestart.c - restart library (available for use in fileio.c)restart.h - declaration of restart library functionsutil.c - useful utility functionsutil.h - declaration of useful utility functions and macrosIn particular, pay close attention to the comments in fileio.h andbonnieb.c. You should understand what each of the following functionsin bonnie.c does before undertaking the remainder of the MP:fill_file_char()file_read_rewrite()file_read_rewrite_block()fill_file_block()fill_read_getc()file_read_chunk()newfile()Step 2: Basic I/O operations3----------------------------Implement file_read, file_write and file_info operations in fileio.c.If done correctly, your code should pass all suite1 tests:./lmp1 -test suite1Running tests...1.read ::pass2.info ::pass3.write ::passTest Results:3 tests,3 passed,0 failed.IMPORTANT: fileio.c is the only file you should modify for this step.Step 3: More filesystem operations----------------------------------Implement file and directory operations for suite2 (dir_create anddir_list), suite3 (file_create and file_remove), and suite4(file_checksum and dir_checksum).You can test each operation and test suite individually:./lmp1 -test dirlist./lmp1 -test suite2All tests should now pass:make testRunning tests...1.read ::pass2.info ::pass3.write ::pass4.dirlist ::pass5.dircreate ::pass6.remove ::pass7.create ::pass8.filechecksum ::pass9.dirchecksum ::passTest Results:9 tests,9 passed,0 failed.Step 4: Performance testing---------------------------In this step, we will change parts of Bonnie to use our filesysteminterface.Make the function file_read_rewrite_block() in bonnie.c to call yourfileio.c functions instead of POSIX I/O operations. When answering thequestions below, use this modified version of bonnie.c.Before making this change, its a good idea to write pseudocode commentsfor what each part of file_read_rewrite_block() does, so that youunderstand the code and can perform the change correctly. There maynot be an exact one-to-one correspondence between our filesysteminterface and the POSIX commands.4Note: In future LMPs, we will be using the fileio.h interface in asimilar manner, but we will call the functions remotely, via a messagequeue.Questions---------Q1. Briefly explain what the following code from bonnie.c does:if ((words = read(fd, (char *) buf, Chunk)) == -1) ...Q2. Is the above an example of a block read or a character read? Whatis the value of the variable words if the read succeeds? Fails?Q3. Explain the meaning of the flag value (O_CREAT | O_WRONLY |O_APPEND) for the POSIX function open().Q4. Run Bonnie. What is being measured by each test function?Q5. Look at the summary results from the Bonnie run in Q4. Does Bonniemeasure latency, throughput or something else? Justify your answer.Q6. Compare character reads with block reads using Bonnie. Which isfaster? Why do you think this is the case?Q7. Copy and paste the performance measures output when running Bonniebenchmarks in a local directory and again in an NFS-mounted directory.Is one kind of disk access noticeably slower over the network, or areall tests significantly slower?Your home directory may be an NFS mount, whereas /tmp and /scratch are localdisks. To test your code in /tmp, do the following:mkdir /tmp/your_usernamecp lmp1 /tmp/your_usernamecd /tmp/your_username./lmp1(record the output)cdrm -fr /tmp/your_usernameQ8. How does Bonnie handle incomplete reads, e.g., due to interruptionsfrom signals? Justify why Bonnies approach is good or bad for afilesystem benchmark program.Q9. By now you should be very familiar with the self-evaluation testharness we provide for the MPs. Examine the function test_file_read()in lmp1_tests.c, which tests your file_read() function from Step 2.What does this test check for, specifically? You may want to copy andpaste the code for this function in your answer, and annotate eachquit_if or group of related quit_ifs with a comment.Submit all code for this part of the assignment and answers to questionswithin you answers.txt file.Reminder: Do not copy or plagiarize any code from any other student in thecourse and be sure to cite all online references. 5Do not copy or plagiarize from any source online. Any student found doing sowill receive a 0 for the assignment portion of the course. My goal is tomaximize your learning, so please focus on that!Part 2 – Memory ManagementThis machine problem will focus on memory. You will implement your ownversion of malloc() and free(), using a variety of allocation strategies.You will be implementing a memory manager for a block of memory. You willimplement routines for allocating and deallocating memory, and keeping trackof what memory is in use. You will implement four strategies for selectingin which block to place a new requested memory black: 1) First-fit: select the first suitable block with smallest address. 2) Best-fit: select the smallest suitable block. 3) Worst-fit: select the largest suitable block. 4) Next-fit: select the first suitable block after the last block allocated (with wraparound from end to beginning).Here, suitable means free, and large enough to fit the new data.Here are the functions you will need to implement:initmem(): Initialize memory structures.mymalloc(): Like malloc(), this allocates a new block of memory.myfree(): Like free(), this deallocates a block of memory.mem_holes(): How many free blocks are in memory?mem_allocated(): How much memory is currently allocated?mem_free(): How much memory is NOT allocated?mem_largest_free(): How large is the largest free block?mem_small_free(): How many small unallocated blocks are currently in memory?mem_is_alloc(): Is a particular byte allocated or not?We have given you a structure to use to implement these functions. It is adoubly-linked list of blocks in memory (both allocated and free blocks).Every6malloc and free can create new blocks, or combine existing blocks. You maymodify this structure, or even use a different one entirely. However, do notchange function prototypes or files other than mymem.c.IMPORTANT NOTE: Regardless of how you implement memory management, make surethat there are no adjacent free blocks. Any such blocks should be mergedinto one large block.We have also given you a few functions to help you monitor what happens whenyou call your functions. Most important is the try_mymem() function. If yourun your code with mem -try , it will call this function, which youcan use to demonstrate the effects of your memory operations. Thesefunctions have no effect on test code, so use them to your advantage.Running your code:After running make, run1) mem to see the available tests and strategies.2) mem -test to test your code with our tests.3) mem -try to run your code with your own tests (the try_mymem function).You can also use make test and make stage1-test for testing. makestage1-test only runs the tests relevant to stage 1.As in previous MPs, running mem -test -f0 ... will allow tests to run evenafter previous tests have failed. Similarly, using all for a test orstrategy name runs all of the tests or strategies. Note that if all isselected as the strategy, the 4 tests are shown as one.One of the tests, stress, runs an assortment of randomized tests on eachstrategy. The results of the tests are placed in tests.out . You may wantto view this file to see the relative performance of each strategy.Stage 1-------Implement all the above functions, for the first-fit strategy. Use mem -test all first to test your implementation.Stage 2-------A) Implement the other three strategies: worst-fit, best-fit, and next-fit.The strategy is passed to initmem(), and stored in the global variablemyStrategy.Some of your functions will need to check this variable to implement thecorrect strategy.You can test your code with mem -test all worst, etc., or test all 4together with mem -test all all. The latter command does not test thestrategies separately; your code passes the test only if all four strategiespass.7Questions=========1) Why is it so important that adjacent free blocks not be left as such?What would happen if they were permitted?2) Which function(s) need to be concerned about adjacent free blocks?3) Name one advantage of each strategy.4) Run the stress test on all strategies, and look at the results(tests.out). What is the significance of Average largest free block? Whichstrategy generally has the best performance in this metric? Why do you thinkthis is?5) In the stress test results (see Question 4), what is the significance ofAverage number of small blocks? Which strategy generally has the bestperformance in this metric? Why do you think this is?6) Eventually, the many mallocs and frees produces many small blocksscattered across the memory pool. There may be enough space to allocate anew block, but not in one place. It is possible to compact the memory, soall the free blocks are moved to one large free block. How would youimplement this in the system you have built?7) If you did implement memory compaction, what changes would you need tomake in how such a system is invoked (i.e. from a users perspective)?8) How would you use the system you have built to implement realloc? (Briefexplanation; no code)9) Which function(s) need to know which strategy is being used? Brieflyexplain why this/these and not others.10) Give one advantage of implementing memory management using a linked listover a bit array, where every bit tells whether its corresponding byte isallocated.Submit all code for this part of the assignment and answers to questionswithin you answers.txt file.Reminder: Do not copy or plagiarize any code from any other student in thecourse and be sure to cite all online references.Do not copy or plagiarize from any source online. Any student found doing sowill receive a 0 for the assignment portion of the course. My goal is tomaximize your learning, so please focus on that!转自:http://www.3daixie.com/contents/11/3444.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容