week 5 discussion
DESCRIPTION
mANAGMENT discussionTRANSCRIPT
-
Discussion Week 5TA: Kyle Dewey
-
OverviewHW 3.10 and 6.2 reviewBinary formatsSystem call execution in NACHOSMemory management in NACHOSI/O in NACHOS
-
Homework 3.10Identify the values of pid at lines A, B, C, and D. Assume that the actual pids of the parent and child are 2600 and 2603, respectively.
-
Homework 6.2The Cigarette-Smokers ProblemAgentMatch SmokerPaper SmokerTobacco SmokerTable(holds two of three items)
-
Problem SpecificsAgent places two itemsSmoker with remaining item grabs the two and smokesThe process repeats
-
Java Implementation
-
Binary Formats
-
NOFFNACHOS Object File FormatMagic Number (0xBADFAD)Code (Text)Initialized Data (Data)Uninitialized Data (BSS)
-
Why Bother?CPU sees only a stream of instructionsAll gets loaded into memory anyway
-
AdvantageTells OS roughly how portions will be usedOptimizations possibleShare (reentrant) code and constant dataPrevent execution of non-code regions
-
System Calls Revisited
-
System Call Executionread()User SpaceKernel Spaceread()readFromDisk()read()
-
User -> KernelProblem: kernel space and user space are enforced by hardwareHardware must be informed of jump
-
Solution?Instruction to specify the levelBy necessity, it is privilegedNeed kernel space to tell the system were in kernel space - catch 22
-
Existing MachineryInterrupts are serviced by the kernelGenerated from other devices, often I/OPreempt all else and enter the kernelThe routines that service interrupts are called interrupt service routines - ISRs
-
InterruptsHard DriveISR 1ISR 2ISR 3Int 1MemoryCPU
-
Using InterruptsTrigger a software interruptKernel mode entered synchronouslyParameters can be passed in registers, in a specific memory location, etc.Note that the actual mechanism and lingo is hardware dependent
-
MIPS System CallsMIPS has the syscall instructionProcessor throws a system call exception, triggering the OS system call service routineBy convention, the syscall ID is in $v0, and arguments are passed in $a0 and $a1
-
MIPS System CallsAssume we want the system call with ID 5This call takes no argumentsaddi $v0, $zero, 5syscallCPUSyscall ISRSyscall 5 Handler
-
code/userprog/exception.cccode/userprog/syscall.hcode/test/start.s
-
Memory Management
-
Project #2 MemoryPhysical = virtual (until Project #3)Must using pagingNeed to allocate and free pages as requested
-
NACHOS MemoryDoes not have much128 byte pages32 pages total8 pages for each process stack + data + codeSimple bitmap is sufficient to record what is and is not used
-
Contiguous MemorySince physical = virtual, served memory requests must be contiguousI.e. if a process requests 5 pages, they must be contiguous*Could* do compaction, but this is a terrible idea
-
Fork() ExampleUsed - P1FreeFreeFreeUsed - P2Used - P1FreeFreeUsed - P2Used - P3P1 fork()s P3Memory by pageMemory by page
-
Exit() ExampleUsed - P1FreeFreeUsed - P2Used - P3P2 exit()sMemory by pageMemory by pageUsed - P1FreeFreeUsed - P3Free
-
Getting PagesMemory is available through:machine->mainMemoryMerely array of 1 byte charactersNeed to split into pages on your own
-
Memory and ConcurrencyMultiple processes may request pages at the same timeOnly one may get any given pageSynchronization primitives from Project #1 will have to be usedMake sure they work correctly!
-
I/O Syscalls
-
NACHOS DiskDo not need to worry about this until Project 3I/O syscalls for Project 2 utilize Linuxs existing syscalls for file I/O directly
-
I/O SyscallsActually implement Read() and Write(), NOT readAt() and writeAt()readAt() and writeAt()s provided implementations are sufficient to implement Read() and Write()
-
Files and ConcurrencyProcess A prints Hello world!Process B prints Goodbye cruel world!Hello woGoodbye crld!ruel world!
-
Files and ConcurrencyDetermining what needs to be locked may be difficultMay have separate things that need lockingMay need multiple locks for distinct resourcesConcurrent reads are OK, but not concurrent writes
-
Open File SemanticsSemantics of Fork() are that child processes inherit open filesRead() and Write() can only manipulate open filesIf a process will not close its files upon Exit(), then the OS must do so
-
Open FilesWhich files are opened must be recorded in the PCBThis allows for all aforementioned behaviorsAlso allows for an offset for subsequent Read() and Write() requests
-
ConsoleRead() and Write() may also manipulate the consoleConsole is not opened or closedConstants specifying console usage are in syscall.h
-
CaveatsThe given code is really getting buggyProvided code is also getting really ugly
-
How-To ImplementProject #2 has a step-by-step implementation guide at http://www.cs.ucsb.edu/~cs170/projects/homework_2guide.htmlPlease read carefully
-BSS: Historically Block Started by Symbol, psuedo-op in an antique assembler. Backronymed to Better Save Space - variables that dont currently have a value, but may in the future.-Reentrant code does not modify itself. Most code has this property; the system fights you tooth and nail if you try to break it-OpenBSD will not allow regions of memory to be executed that were not marked as code. This prevents many buffer overflow attacks which write to non-code regions and try to execute those regions.-Note that the Int 1 is just meant to signal that ISR 1 should be used. This is all very hardware-dependent, but the general model of interrupt->CPU->ISR remains the same.-MIPS has the syscall instruction, which causes the CPU to throw a special exception that is reserved for system calls-x86 has the int instruction, which triggers a software interrupt-They do the same thing, but the terminology differs-Why is it a terrible idea?-Expensive-We have virtual memory to avoid this - making people do compaction would teach bad practice-Student pointed out a memory leak in bitmap.cc-I wont go over it myself because it requires a lot of browsing through code