 There we go. It is unmuted now. Sorry about that. All right so Even though every file is only 96 bytes as you have discovered in lab 6 it will still consume an entire block. So even though It's small still consumes a block So each file will consume one block and then a file is represented by an inode So each file will need a hundred and twenty-eight bytes for the inode plus 4096 bytes for the block. So that is how many bytes I need per file, which is 4224 and then since I have a thousand files, it's just that number times a thousand So in total I need well That many bytes to store all of the files, even though they consume a lot less So you need something for the bitmaps if you really want to if you want to go into like deep-deep thought I guess but But then you don't know if all the inodes are contiguous and so on and so forth So you could do that as long as it seems like you know what you're doing And you have these two numbers included then probably fine All right, so as for the previous question. Oh, how many bytes are lost due to internal fragmentation? You may say zero bytes if that is the case. So how much space are we wasting to internal fragmentation? Yeah, so for each file Well each file gets a whole block which is 4096 But it only uses 96 bytes of that So if I subtract 96 that means I have lost 4,000 bytes due to internal fragmentation per file, and if I have a thousand files Well, I multiply that by a thousand which means I lose four Million bytes due to internal fragmentation. Yeah No, so each of them they will not share a block Because well, they'll be mapped to a page in memory at some point eventually whatever it wants to read it in and Then you might get in the case where well if they're sharing a block Well, you can only read one block in the memory So you can actually read the contents of another file even if you don't have access to it because you're just reading a block So they all need to be on separate blocks all right so question four came up and This is how I came up with this question. It's because I started copying files And you know like in Windows Explorer It'll show you how fast the progress is going and then I hit a bunch of small files And then I just saw the progress just I was like oh Students in the course could explain this now especially if I set it up like this So question says why might copying a directory containing a single large file be faster than copying a directory with many small files Even if the total size of the small files is less than the size of the large file Yeah, so if I have a single large file, what do I actually have to copy? Well, I have to copy one i node which is pretty small and then I have to copy. I don't know say it Fills almost like a thousand blocks. Well, then I copy one i node and then a thousand blocks and Since it's one large file Well, the last block might have a bit of internal fragmentation, but overall it'll probably be negligible So I essentially have zero fragmentation because it's all one big file Well, if I just have I don't know say Let's say I have even more. Let's say I have five thousand small files. Well That's five thousand i nodes plus Five thousand blocks even if each file only uses like one or two bytes of the block But it's still going to need to copy over the entire block And it won't count towards the progress of copying a file because like windows will only tell you how fast it is It actually copying the contents of the file not anything else associated with it So in this case the size of the i node could be bigger than the actual Contents of the file you actually care about so it might it might actually spend most of its time copying the i nodes and Taking more time doing that and just having more blocks Even though that this might only use like, you know 5,000 bytes in total across all the files because each file needs an i node and each One of them also need a block. It's going to be really really slow. So questions about that Yeah, so So disk usage well depending on however you report it Sometimes operating systems will lie to you and say files consume a block whenever you look at like disk usage Even though it's not technically true, but they're consuming blocks So it depends on the file systems and whatever your operating system wants to tell you so likely it'll just tell you it's full and Kind of hide details for you, but yes, you'll run out of space much faster if you have a bunch of small files So you run out of space before you expect Alright, so any other questions about that part? Alright, so next one Assume an i node has 12 direct blocks and one I guess this should be clarified One single indirect block whoops that word should be moved up One single indirect block What is the maximum file size in kilobytes that can be supported? You may skip the file calculation if you don't have a calculator or you forgot it or whatever so Go back up. So I will copy the relevant information So my page size or block size, I guess I should say in this context Is equal to 2 to the 12 and then my pointer size? Was equal to 4 bytes or 2 to the 2? So what is the maximum size of the file? I can support if I have 12 direct blocks and then one single indirect block Yeah, so well through the 12 direct blocks Well, I could point to 12 blocks and they're 4 kilobytes each so through just the direct point Direct pointers I could store up to was at 48 kilobytes But through the indirect block that's probably where most of my pointers are so Assuming that I have no other metadata I need to figure out how many pointers I can fit on a block So that's just block size divided by pointer size. Whoops. That was the wrong tool So it's just block size divided by pointer size Which means I can fit Two to the ten pointers on a block. So using that single indirect block I can point up to two to the ten more things so in total I can point to 12 blocks through the direct pointers plus another two to the ten which is 1024 and then each of them Points to a four kilobyte block so I could just multiply that by four So in that case, it's what 136 times four which is 4144 kilobytes is the maximum size of the file with this kind of scuffed I node. Yeah to the ten different thing so So the pointer size there are only four byte pointers four byte pointers. Yeah, not Yeah, not for for bit Yeah, no four byte pointers. Yeah for for bit. We would be in trouble questions about that Yep Yeah, indirect blocks. It's like one page table same concept Sorry. Yeah, it's just by definition. So if you look at the spec Especially in your lab six use an I node. So the first 12 pointers are all direct and then according to the spec Index 12 is the single indirect and then the next one is double and then the next one is triple So you just have to read the spec to know what to do That's real computing it in that shell and then you read the spec and that's wrong and then you work around it and Then you're pod racing All right, so next question is how many directories wait All right, this is already too late How many directories need to be accessed when attempting to read a file located in this path? home user uterano ec 353 labs grade dot txt assume that grade is a regular file. So how many directories do I need to go through I? Have one five Should be five. So what's the first directory always? Slash, what's the special name for slash? the root the root directory so Here it would be five. So I have to start The root directory Which would be slash and the only reason we know how to start there as it just gets a special I know number it's I know to and that is how we know where to start with a file system So we start at the root directory inside there. There would be the home directory So we would access home then site home would be user then side User would be uterano then side uterano would be ec 353 and then this is just a regular file. So in total we would access five directories because Well starts at the root directory All right next question is even more fun. So you think you should create a copy on right file system But someone who hasn't taken this class Says you don't need to because you can already do the same thing with hard links Explain to your friend why they are wrong What are the differences between file one and file two being hard links to the same I node and the concept of copy on right? Can I achieve copy on right using hard links? So hard link is no to I node Yeah, so if So if they are hard links then file one and file two Are actually pointing to the same I node and Then that tells us where to go to get all the contents. So if I try to modify file One and I save some changes and I try to access file two I'm gonna get those changes in file two. They're not going to be completely independent, which is what I want from copy on right I want them to be Independent, but I also want them to share share blocks if they can but as soon as they Differ and one tries to write then I have to make an independent copy and make sure that well through both of the files They are both independent So answer to this is no if they are hard links if I change one I change the other with copy on right I want the two files to look like they are independent even though they are actually maybe sharing information and I cannot achieve copy on right using hard links Because well, they just refer to the same I node same contents. There's no way to actually share it So some file systems are copy on right file systems, but it's not achieved through using hard links It would essentially need to do what you do in like lab 3 So you need to keep track of what pages are being shared and if you modify them then you create a new copy update Whatever one changed it so on and so forth same concept Yeah, if I'm reading well essentially while they're the same I know that's the same contents So it's not like they're even really sharing pages. Anyways, you're just referring to the same thing But they're hard links then if you modify one the other one gets modified What do you mean? So they're both pointing to the same I node Yeah, you could point one way, but says you can you achieve it just using hard links only Yeah, you need files because if you make them independent that they both point to a different I node Now they're independent, but now they're not sharing data They're not sharing a But here they won't be sharing anything at all. This would point to like block 12 this would point to block 13 or something like that That's if we implemented a copyright So this is like I want to implement a copy on right file system without Changing any of the details of the file system just using regular old hard links. Can I implement it? But you're pointing it to a different I node, but you're not sharing blocks or anything Yeah, you're basically saying I Make them point to different I nodes and I implement copy on right therefore I can implement copy on right Yeah, you could do it, but not just through I nodes So we got that Yeah Yeah, if you could if you just explain copy on right and you do it and like explain how you do it That's fine because yeah, it it can be interpreted in some different ways So this one was loosely marked if you actually told me how to implement copy on right using that as long as you said Same things. That's fine You'll be fine All right, so Should we do this threading question or carry on to something else Yeah, do we want to skip through some questions quick? So we got a threading question Then we have a lock question So carry on all right Then we have a locking question which has center for us Well, let's skip and then we have a memory allocation question And then we have a disk question That talks about raid and we have a file system question again And then we have virtual machine question, which is not going to be relevant to you So which one do we want to This in file system So yeah, we well, let's slip over to discs. All right. Well So inspired by the course and your data hoarding you decide to build yourself array you buy yourself eight hard drives They're four terabytes each What raid configuration would you use if you really really so there's two really's here So that's a clue really care about your data justify your answer Two separate copies, but raid so raid one is really really care So raid one is you make an exact copy of every disc So in this case if I have eight hard drives, I can tolerate Seven of them failing before I lose any data Sorry, so so raid one is just Every disc is exactly the same as one another No, it's a mirror of every single disc So raid one is a mirror of every single disc For some reason in the o-step book they call raid one raid ten But raid ten is actually a combination of raid zero and raid one Why they do that I don't know All right next one is what raid configuration would you use if you care about your data? But want more than four terabytes of total capacity So raid four is one we should always avoid because it is silly Anyone remember why raid four is silly? so Yeah, raid four and raid five are both the X or one So essentially one disc is used for parody, but in raid five or raid four We have a dedicated parody disc so it comes a bottleneck and raid five is the same idea except that parody is Distributed over the rest of the disc so we don't have a bottleneck So raid five is just a strictly better version of raid four So in this case we want raid five So if we have raid five How much total capacity can I use? 28 terabytes Yeah Yeah, essentially we use the capacity of one drive for parody information So we waste one drive so our total usable capacity is seven times four so if My math is correct that equals 28 terabytes So I can use 28 terabytes of usable space and I can tolerate one disc from failing So one disc fails no problem. I can chuck in another one and rebuild it So yet that is good justified So what rate configuration would you use if you only care about performance? Justify your answer state how much faster you read and write performance would be compared to a single disc Raid zero what's raid zero you to stripe that data across all the drives and How many Times more than a single disc am I going to improve my read and write performance with raid zero Eight times. Yeah, so I'll get eight times better performance, but if a single drive dies, I am now screwed so You get to benefit from all 32 terabytes of storage, but you know eight times read and write performance But if one fails you are now screwed so live fast die hard. All right cool Yep, that's it. So next one do we want to do this file system question All right one more quick that only took five minutes So you'll be using your knowledge of file systems to explain the differences between Ln and cp in terms of inodes and blocks Assume you have a file called my file that contains 2090 bytes The block size of the file system is 4096 so it fits on a single block as a hint I ran the Ln and cp commands and you'll find the output of LS after this so here I created Ln with just no extra arguments. This creates a hard link remember So my file and Ln should be pointing to the same inode which I can see that they do It's inode one oh one for both of these and then I see if I cp it well They don't point to the same inode. They get a different inode. It gets inode one oh two So first question says explain what happens on the file system when you run the Ln command Start your explanation with the new directory entry for Ln Dash file dot txt Yeah, so I knowed one oh one does not point to anything hard links is name pointing to an inode so we have a new directory entry for Something called Ln file dot txt Then we probably have to well if you want to go into excruciating detail We have to look at the entry for my file See what I knowed it refers to and then in this new entry we make Ln file also refer to inode 101 so Ln file dot txt that points to inode 101 and so does my file dot txt it points to inode 101 So they are both hard links So current directory we make a new entry for Ln dot txt It'd be a same assigned the same inode as my file on the inode itself Oh, it would also increment that link count by one which I didn't explicitly ask for in this question So if you said that I was happy there was no bonus marks for it Unfortunately, but would increase the number of links to that inode as well if you really want it to be super explicit about it Yes Name points to inode Yep, all right. So next one explain what happens in the file system if you run the cp command Start your explanation with the new directory entry for CP file dot txt. Yes Sorry Yeah, so first thing I would do I know points to the contents of file has all the metadata about it who owns it when it was modified all that fun stuff Yeah All right, so first one I create a new directory entry for cp file dot txt and then Well, next thing I need to do is I need to grab a new inode because I'm creating a new File that's just it's essentially kind of like fork It's supposed to be the exact copy of whatever that I am trying to copy from so I grab some new inode this case it was obviously 102 and then using that inode well, I would copy the data from Inode 101 and make 102 an exact copy of that and then Well, it points to a block. So I would have to in step two Grab a new block then I would need to on step three actually bite for bite copy the contents of of my files block zero copy my file Block zero to CP file block zero Make see make inode 102 point to that content and then I'm done now They are two separate copies that look are independent, but look exactly the same in terms of content The inode gets a deep copy sure Sure Yeah, too many words. So this was really wordy But yeah, if you say it gets a copy of everything such that it's independent or a deep copy and implies that that's fine All right, so that was six minutes. All right, which other question do we want to do? Lock this lock one. What's the center for us? This one. Yeah, there's locks and locking. So locks is mutex is locking with center for us Yeah, so yours is Your exam's appropriately named So yeah, this is just locking because I don't know So you're given four threads that get properly created and run. There's a bunch of garbage here No, this was similar to the one we saw So in this case, so we have I think by default. I just gave you Initialize gave you some functions and then gave you all the comments for them Yep, that was the solution. So Yeah, so we all forget them now, so we haven't initialized I said you can initialize your center for us to whatever value you want Huh? Oh, we're good Okay. All right, so we have four threads here thread one Calls f1 and then f2 thread 2 calls f3 and the comment says that this should run Only after f1 completes in thread 3 we have f4 that runs only after f1 completes In thread 4 we have f5 that should only run after f2 completes and then f6 that only runs after f3 and f4 complete so Using center for us. How would we make all of the comments true? So when we have a center for question, we should first think to ourselves Well, what do we want to prevent from executing? So in this? Should I prevent thread one from executing at all? No, no, it's good. It can just go full bore Should I prevent thread two from executing at all? Yes. Yes, so I should probably have a weight So I'll just uncommon it. So I'll need to wait on some center for so I'll just make one called SEM one So if I make one called SEM one All next I should probably argue about its initial value. So what should its initial value be? Zero because I want it to not continue. So thread or sorry Center for one All this right shorthand gets an initial value of zero possibly but Your library would probably quickly get more complicated than actually just doing center for us So next one thread three. Do I want to prevent thread three from executing? Yes. Yes Oh, well, I guess what I want it to wait on F one So it should be waiting on the same thing that F Or sorry that thread two is waiting on so this should also probably wait on SEM one and Current value is zero. So I prevent it from running All right thread for I need to prevent from running So should this be the same as SEM one or should it be a new center for? New center for I want to prevent it from running So I will have a SEM weight of SEM to and what should the initial value of SEM to probably be? Zero because I don't want to do anything All right. So now we're at this point. So SEM to equals zero so now Let's tackle fixing thread two from executing so Thread two should only execute after F one complete. So how do I make sure that thread two can actually call F three? Yeah Post after I'm done F one right so post All right. So if I just have one post there, is that good enough? So if I only have one post that would change the value from oops, sorry from zero to one and then well either thread Three or thread two will execute next say this one goes and Decrements it from one to zero and then it runs at four and now. Oh, guess what? Thread two can't run Yeah, so after F three what? So you you want You want to move this here You want to move this here. I'm not saying thread one has to run before thread three Yeah, well, that's what I just said. I said what if I move this line here essentially No thread three could unblock to your thread to yeah You could have a then both post if you want it'd be weird All right, so But that doesn't matter really right All right, so now we got this check and this checks right? We're good for those All right, let's tackle something else So We have a wait for some to So that wants to run only after f2 completes so Can we fix that one? post them to after f2 So post them to here we all We all agree with that Alright, that looks good. So then we have this check All right, so the last condition we have is f6. We want to run it only after f3 completes and F4 completes. So how do we do that? wait twice So yeah, I should probably have a wait I probably need a new center for so some three and what should the initial value of some 3b? Probably zero So now in this case, I want to make sure that it runs only after f3 and f4 complete So that probably means I need to post some three here and also post Some three here which creates a bit of a problem because right now Well f6 could execute after f3 or f For complete because I only have one way so in order to make sure both of them Complete. I yeah, I just wait twice so now I can go ahead and Give it the old check and then make sure that I'm not criminally insane See that was wait through some three post them three post them three All right. We're good. Yay Yeah, yeah, yeah for which one Send three oh Initial values cannot be negative as how are they defined the value is an unsigned int Unsigned ints cannot be negative. Well, then it would be yeah Well max it would fit technically Max it would be Some weight definition is that it will decrement but if it cannot If it the current value zero and it would go negative It will block until that's something what one another thread increments it and it can actually decrement it and continue No, it cannot go negative So if the current value zero it blocks until someone else increments it so I can decrement it back down to zero or Some positive number Yeah, yeah, it cannot be negative one alright, so The next question was for each function state which functions could run in parallel not including itself Write none. So which functions can run in parallel with let's say F1 None of them can write in parallel with it, right? So they all wait for something else. So nothing else can run in parallel with F1 What about F2 what could run in parallel with F2? F functions So F3 could run at the same time as F2 so could F4 could F5 run at the same time as F2 No, because it's waiting on it, right? so Well about F3 so that should be able to run at the same time as F2 F4 and can it run at the same time as F5? Yeah, can't run at the same time as F6 No, because it's being waited for All right, so what about F4 so F2 can run at the same time as it and F3 Can F5 run at the same time? Yep Can F6 run at the same time? Nope. All right, what about F5? So can that yeah commutative so it should be run as the same time as F3 Run as the same time as F4. Can it run as the same time as F6? Yeah Yeah, no it's running in a thread. So a thread has to run sequentially. It's a thread Yeah, so what can run in parallel with F6? Nada All right, so let's see. Is that good? Hey, it looks good all right, so What question do we want to try and speed run in five minutes? Memory allocations. All right, probably good You decide to use a buddy allocator to handle a bunch of fixed size allocations It was too early and you slept through slab allocators. Yikes So your allocator needs to be able to handle eight allocation of 10 byte each How big of a memory block does your buddy allocator need at minimum to be able to handle every allocation? Justify your answer. So So yeah for each allocation Well, if it wants 10 bytes, it needs to be a power of 2 So each of them is going to be 16 bytes and if I have eight allocations. Well, I have 16 essentially times 8 So that is 128 total You have different allocations each allocation has to be a power of 2 So if it had a slab allocator, you could move them all right next to each other That would be more efficient, but we have a buddy allocator All right, so next question is how many bytes are lost due to fragmentation and what type of fragmentation is this? Justify your answer Internal fragmentation. So for each of them, I'm losing six bytes because I get 16 and I only use 10 of that So I am wasting six bytes per and I have eight allocations So that equals whatever that equals was that equal 48? So I have 48 bytes lost due to internal fragmentation. Yeah External fragmentation is wasted space between or yeah between blocks themselves So in this case I Might be able to consider with buddy allocators typically you've way less internal fragmentation But say I had like eight 16 byte ones Something like that and then I well so right now we don't have any blank space between the blocks 16 Something like that and then say I went through and I freed a bunch some of the allocations So let's say I freed this allocation. So now this one is free and now this one is free So in total I have 32 bytes free, but now if I have a 32 byte allocation Oh, I can't fit it anywhere because these free blocks are not contiguous So that would be considered external fragmentation because I have wasted blocks essentially All right, so anything else real quick Slab allocator works do lab six Lab lab six is a slab allocator needs a bitmap you do a bitmap in lab six and All the blocks are essentially a giant array of inodes. That's a slab allocator. I don't know Yes, all right with that just remember going for you. We're all in this together