Operating Systems Level

Operating Systems Level PowerPoint PPT Presentation


  • 147 Views
  • Uploaded on
  • Presentation posted in: General

Duminda Wijesekera. INFS 515 Spring 2000 . 2. Operating Systems. Software that managers system resources.Can be used directly by programmers.Three topics discussed in chapter:Virtual memory.Paging and segmentation.File system. Process management.. Duminda Wijesekera. INFS 515 Spring 2000 . 3.

Download Presentation

Operating Systems Level

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


1. Duminda Wijesekera INFS 515 Spring 2000 1 Operating Systems Level Chapter 6

2. Duminda Wijesekera INFS 515 Spring 2000 2 Operating Systems Software that managers system resources. Can be used directly by programmers. Three topics discussed in chapter: Virtual memory. Paging and segmentation. File system. Process management.

3. Duminda Wijesekera INFS 515 Spring 2000 3 Operating System Level

4. Duminda Wijesekera INFS 515 Spring 2000 4 Virtual Memory Physical memory of a machine too small for most programs. Old Solution = Overlays: Programmer divides code in to several sections, and load each section as needed. Current Solution = Paging: Each program divided into pages, transparent to the coder, by the operating system.

5. Duminda Wijesekera INFS 515 Spring 2000 5 Logical vs. Physical Addresses A machine with 4K words of memory and 16 bit addresses have 65536 addresses. At any instant only 4096 of them can be addressed. Addresses need to be mapped to physical space. Mapping: Program has virtual addresses. Memory has physical addresses. Need to translate Virtual -> Physical. Use page table for mapping.

6. Duminda Wijesekera INFS 515 Spring 2000 6 Address Translating

7. Duminda Wijesekera INFS 515 Spring 2000 7 Implementing Paging Virtual address space: Kept on disk Broken down into equal size pages. Usually 512 to 64k. Brought into memory on an as needed basis. Pages fit in frames in physical memory.

8. Duminda Wijesekera INFS 515 Spring 2000 8 Example Logical to Physical Mapping

9. Duminda Wijesekera INFS 515 Spring 2000 9 Address Translation Virtual to physical mapping is done by the memory management unit Either separate or part of CPU Breaks down a virtual address into a page number+ offset. Replace the page number by the frame number. Physical address = Frame number+offset.

10. Duminda Wijesekera INFS 515 Spring 2000 10 Example: Address Translation

11. Duminda Wijesekera INFS 515 Spring 2000 11 Address Translation Procedure Translate virtual address in to page# + offset. Use page # to index in to page table. Check if page already in memory by checking if present/absent bit is on. When page in memory, copy frame# + offset into output register.

12. Duminda Wijesekera INFS 515 Spring 2000 12 Example Page to Frame Mapping

13. Duminda Wijesekera INFS 515 Spring 2000 13 Demand Paging If wanted page not in memory, a page fault occurs. Then OS brings the required page in to a frame and repeats the instruction. Demand Paging: Bring page on to a frame on demand. Working set: Locality of reference in pages. Peter Denning

14. Duminda Wijesekera INFS 515 Spring 2000 14 Page Replacement Policy Working set moves through pages slowly. When page need to be brought into memory, need to evict existing page: Least Recently Used (LRU). First in First Out (FIFO). Random. If working set larger than available pages, heavy thrashing occurs. 60% rule.

15. Duminda Wijesekera INFS 515 Spring 2000 15 Write Back and Dirty Bit When evicting page, need not write back pages that did not change. Maintain a dirty bit to indicate pages that changed in physical memory. If code fitted into an integral number of pages every bit of physical memory is used. If not there is a page with unused memory – Internal fragmentation.

16. Duminda Wijesekera INFS 515 Spring 2000 16 Fragmentation and Page Size Page size = n, average space wasted in last page = n/2. Small page = less wasted space. Small page size implies: Many pages, Large page table. If maintained in HW many registers More time spent in loading etc. Large number of small memory access result in inefficient memory usage. Many rotations for disk arm. Advantages of small pages: If working set has large number of small regions, less thrashing. Pages fit in small amount of memory.

17. Duminda Wijesekera INFS 515 Spring 2000 17 Segmentation Semantically Diverse parts of code need logically separated chunks of memory. Leads to non linear arrangement of logical address space: Called segments.

18. Duminda Wijesekera INFS 515 Spring 2000 18 Segmentation Programmer aware of segmentation. Each segment can grow and shrink separately. Logical addresses given as (segment#, offset).

19. Duminda Wijesekera INFS 515 Spring 2000 19 Virtues of Segmentation Each segment can be separately recompiled. Saving make time. Changing one procedures size does not effect addresses in another. Facilitates sharing. Library sharing by keeping separate runtime for the same piece of code. Protection can be at a segment level. Facilitates catching more runtime errors.

20. Duminda Wijesekera INFS 515 Spring 2000 20 Comparing Paging and Segmentation

21. Duminda Wijesekera INFS 515 Spring 2000 21 Implementing Segmentation Swapping: If a segment is addressed, it is bought into memory. Problem: External fragmentation due to variable size of pages. Solution: Compaction – moving segments in memory to create bigger holes. Filling memory holes: (1) First fit, (2) best fit, (3) worst fit. 1,2 decrease average hole size. 1 increases performance.

22. Duminda Wijesekera INFS 515 Spring 2000 22 External Fragmentation

23. Duminda Wijesekera INFS 515 Spring 2000 23 Paged Segmentation Segments are paged. I.e. broken down into a collection of pages. Results in internal segmentation, but not external segmentation.

24. Duminda Wijesekera INFS 515 Spring 2000 24 File System File = an abstraction for a container of virtual I/O. Operations with files: Create, Open Close, Read, Write, Execute – in the form of a system call. Operations within a file: Next position. Can navigate between beginning to end. Each system call has some parameters. Read has Buffer with data, next position pointer, file descriptor and file pointer. To the operating system a file is a contiguous sequence of memory.

25. Duminda Wijesekera INFS 515 Spring 2000 25 Implementing Files Space allocation on disks as a sequence of disk blocks. Disk structure: Spindle, platter, track, sector, head. Files spread out on disks in some geometry, kept in File index Liked list Consecutive or not??

26. Duminda Wijesekera INFS 515 Spring 2000 26 A Disk Map

27. Duminda Wijesekera INFS 515 Spring 2000 27 Consecutive vs. Non Consecutive Consecutive: Easy management Cannot grow beyond estimated size. May leave unused space. External fragmentation Non-consecutive More complicated disk map Maintained as a bit vector or table. Can grow or shrink. No fragmentation.

28. Duminda Wijesekera INFS 515 Spring 2000 28 Other Issues Size of Allocation Units Large Units: Can save on access time. Wasted space large due to internal fragmentation. Small Units: Expensive to get large files. Space due to internal fragmentation negligible. Free Lists: Maintained for block assignment.

29. Duminda Wijesekera INFS 515 Spring 2000 29 Directory Management Due to large number of files created, need to arrange them in directories. Allows users to create, delete, move directories. Create, delete, link files. Directory structures: Trees Link: Soft and hard links.

30. Duminda Wijesekera INFS 515 Spring 2000 30 Example Directory Structure

31. Duminda Wijesekera INFS 515 Spring 2000 31 Process Management Process = Code in execution Has: State Include PC, PSW, stack pointer, general registers Address space Including data segment, code segment Processes created dynamically Every process except process 0 is a child of some other process When parent dies, grand parents inherit children.

32. Duminda Wijesekera INFS 515 Spring 2000 32 Process Synchronization Process synchronization needed for proper handshakes. Producer consumer with circular buffers. Producer makes a data item, writes it to buffer. Consumer read it out of the buffer. Conditions: Producer goes to sleep if it finds buffer full (if out = in+1 MOD (buffer Length)). Consumer waits if buffer is empty (in =out).

33. Duminda Wijesekera INFS 515 Spring 2000 33 Producer-Consumer Example

34. Duminda Wijesekera INFS 515 Spring 2000 34 Synchronization by Semaphores Critical sections of code = code that should execute in isolation. Semaphore: Obtain lock for critical section Lock data, use it unlock it. Semaphore is a variable the can be set (UP) or unset (DOWN) atomically. The operating system provides them through a system call Depends on having atomic instructions such as test-and-set.

35. Duminda Wijesekera INFS 515 Spring 2000 35 Semaphores

36. Duminda Wijesekera INFS 515 Spring 2000 36 Some Example Unix Calls

37. Duminda Wijesekera INFS 515 Spring 2000 37 Unix Structure

38. Duminda Wijesekera INFS 515 Spring 2000 38 A Unix Process

39. Duminda Wijesekera INFS 515 Spring 2000 39 Unix File System Calls

40. Duminda Wijesekera INFS 515 Spring 2000 40 Unix File System Related Devices are also files. Reading or writing to those files are the same as reading or writing directly to devices. MODE = Open for R, W or RW File descriptor = An integer id for the file. FD 0,1,2 are stdin, stdout, stderr. Lseek jumps next pointer in file.

41. Duminda Wijesekera INFS 515 Spring 2000 41 Unix Directories Tree structured. Notion of working directory. Path gives where directory is. Link: Makes a pointer to existing directory or file. Soft link vs. Hard link. Access privileges RWX given to owner, group rest of the world. Super User: system administrator can override protection

42. Duminda Wijesekera INFS 515 Spring 2000 42 Example Directory

43. Duminda Wijesekera INFS 515 Spring 2000 43 Directory Related Calls

44. Duminda Wijesekera INFS 515 Spring 2000 44 Implementation of Unix Files Each file has I-node = 64-byte block of information giving Owner, permissions, group, length. Time (created, last changed etc) 13 disk addresses, physical arrangement etc. I-nodes of files on each disk at beginning. When Unix searches for a file it looks up the I-node and reads it in. Does so many times for a directory with many levels.

45. Duminda Wijesekera INFS 515 Spring 2000 45 Structure of I-nodes First 10 point to data blocks (Direct) . If block size = 1024, have 10240 bytes. Address 11 points to first indirect block with 256 disk addresses Max size 10240+ 356*1024 = 67,381,248. Address 12 points to a block with addresses of 256 indirect blocks (double indirect). Max size = Address 13 points to 256 double indirect blocks (triple indirect).

46. Duminda Wijesekera INFS 515 Spring 2000 46 I/O Transfers To speed up transfer, I –node is copied in main memory when file is opened. O/S tries to copy next block(s) expecting sequential access.

47. Duminda Wijesekera INFS 515 Spring 2000 47 Unix Process Management Child process created by fork system call. Right after both processes are same except child returns 1, parent returns 0. Child executes exec(executable) system call and replaces mother’s process with complied process. If parent wants to wait execute wait for child to die (execute exit).

48. Duminda Wijesekera INFS 515 Spring 2000 48 Example Process Structure

49. Duminda Wijesekera INFS 515 Spring 2000 49 Unix IPC Pipe: A buffer to which one process writes and another process reads. Message Queues: Create or open an exiting queue. Can read/write to it. Shared Memory: Two processes share a common address region. Unix maps same pages in both processes into this region.

50. Duminda Wijesekera INFS 515 Spring 2000 50 Threads Two threads within the same process has every thing same except registers, PC and stack. Advantage: If one thread blocks due to some reason, the other can execute. Context switch time is saved due to not having to copy large regions of memory.

51. Duminda Wijesekera INFS 515 Spring 2000 51 POSIX Threads Calls

  • Login