linux case study

31
LINUX – CASE STUDY smvdu

Upload: gyanendra-giri

Post on 10-Apr-2015

2.251 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Linux Case Study

LINUX – CASE STUDY

smvdu

Page 2: Linux Case Study

INTRODUCTION

• UNIX based operating system.• Multiuser, multiprocessing, multithreaded OS.• Developed by Linus Torvalds in 1991.• Also used as Server OS.• Open Source software.• Monolithic Kernel Architecture.

Page 3: Linux Case Study

CHARACTERISTICS

• Kernel written in ‘C’ language• Files & folders organized in single rooted

inverted tree structure.• Hardware devices represented logically as

files.• Multiple users can execute commands

concurrently from pseudo terminals.• LINUX security model based around security of files.

Page 4: Linux Case Study

EVOLUTION

• Initially developed by LINUS TORVALDS in 1991.

• As open source became world wide project.• Sep ’91, Linux 0.01 released.• Oct ‘91, Linux 0.02 released.• X window system ported in 1992.• Tux the penguin adopted as mascot in 1996.

Page 5: Linux Case Study

SYSTEM HIERARCHY

User- logged in person Shell- command interpreterInterface b/w user & kernelKernel- resource manager, foundation on which utilitesand applications rely.H/W- physical devicesincluding registers & datapaths

users shell kernel

H/W

Page 6: Linux Case Study

FILE SYSTEM HIERARCHY

• ‘/’- called as root. It is at top of hierarchy.• /boot – contains the kernel and boot related files.• /bin – contains all commands.• /etc – contains sytem configuration files & folders.• /dev – contains device nodes.• /root – home directory of root user.• /home – home directory of normal users.• /sbin – contains system binaries.• /media – automatic mount point for foreign file system.

Page 7: Linux Case Study

FILE SYSTEM HIERARCHY

• /mnt – manual mount point for foreign file system.• /tmp – contains temporary files used by system.• /var – contains variable informations such as sytem logs.

Page 8: Linux Case Study

PROCESS

• An executing program with several components and properties like pid, priority, file descriptors,security credentials etc .

• ‘INIT’ is 1ST boot process with pid 1.• Every process has a parent except ‘init’.• Process tree hierarchy is maintained.• Linux supports multiprocessing.• System processes known as Daemon.

Page 9: Linux Case Study

PROCESS STATES

• Runnable – process already running or waiting for its turn to run.

• Sleeping – waiting for an event to occur or a signal to arise and wake it up.

• Stopped – process has been stopped.• Zombie – halted process for some reason. It

sounds like dead process.

Page 10: Linux Case Study

PROCESS SCHEDULING ALGO

• Linux uses pre-emptive scheduling.• Each process is allowed to run for a small amount of time

and when this time has expired another process is selected to run and the original process is made to wait for a little while until it can run again.

• This small amount of time is known as a time-slice. • Linux uses priority based scheduling algorithm to choose

between the current processes in the system. • While switching it saves the state of the current process,

then restores back when required.• it keeps information in the task_struct for each process

Page 11: Linux Case Study

CONTD.

• POLICY – (i) Round Robin (ii) First In First Out (FIFO)• PRIORITY – ranges from 0 – 139 0 – 99 called static range allocated to real-time tasks. 100

– 139 called dynamic range and is allocated to conventional processes.

static priority higher than dynamic one.• TIME SLICE – chunk of time given to process to run. Higher

a process’s priority bigger time slice it gets. Minm time slice 10 ms, default 200 ms and maxm time slice is 300 ms.

Page 12: Linux Case Study

INTERPROCESS COMMUNICATION

• Processes communicate with each other and with kernel to coordinate their activities.

• Linux supports a number of interprocess communication mechanisms.

• Signals and pipes are two of them.• Linux also supports system V IPC mechanisms.

Page 13: Linux Case Study

SIGNAL

• Oldest IPC mechanism used.• Used to signal asynchronous events.• Could be generated by keyboard interrupt or an error

condition.• No of supported signal limited to word size of processor.• Processes can send signal to processes with same uid or

gid.• E.g. :- SIGSTOP - causes a process to halt its execution. SIGKILL – causes a process to exit.

Page 14: Linux Case Study

PIPES

• Denoted by ‘|’• Unidirectional byte streams.• Connects std. output from one process into the std. input

of another process.• Shell sets up pipes b/w processes.• Implemented using two file data structures pointing at

same VFS inode and containing pointers to file operation routine.

• E.g. :- ls | wc –w counts all files and directories in current

directory.

Page 15: Linux Case Study

System V IPC Mechanism

Message Queue : - • Allow processes to write messages, which will

be read by reading processes. • Linux maintains list of message queue. • Linux restricts number and length of message. • If no room for message then process will be

added to message’s write wait queue.

Page 16: Linux Case Study

CONTD..

Semaphores :-• Location in memory whose value can be tested and

set by any process.• Test and set operation is atomic.• Used to implement critical regions.• Deadlock occurs when a process alters the value of

semaphore as it enters the critical region but fails to leave region.

• Linux maintains lists of adjustments to semaphore array to protect against deadlock.

Page 17: Linux Case Study

CONTD..

Shared Memory :-• Allows one or more processes to communicate via memory that appear in their virtual address

space.• Pages of virtual memory is referenced by page table

entries.• Access to shared memory areas is controlled via keys

and access rights checking. Once the memory is being shared, there are no checks on how the processes are using it.

Page 18: Linux Case Study

PHYSICAL DEVICES

CHARACTER DEVICES :-• Read one character at a time.• Read or write without buffering. E.g.-system’s

serial ports /dev/cua0 and /dev/cua1.• Accessed as files.• System calls are used to open, read, write and

close those files.• Entry of device driver in chrdevs vector of

device_struct data structure.

Page 19: Linux Case Study

CONTD..

Block devices :-• Read or written in multiple of block size typically 512

or 1024 bytes.• Entry of devices in blkdevs vector of device_struct data

structure.• Device drivers provide class specific interfaces to the

class. E.g. a SCSI device driver has to provide interfaces to the SCSI subsystem which the SCSI subsystem uses to provide file operations for this device to the kernel.

• E.g. – SCSI and IDE devices.

Page 20: Linux Case Study

CONTD..

Network devices :-• Physical device that sends and receives packet of data such as

Ethernet card. • Represented by device data structure.• Device data structure contains information about the device

and the addresses of functions that allow the various supported network protocols to use the device's services.

• common network devices are: /dev/ethN Ethernet devices /dev/slN SLIP devices /dev/pppN PPP devices

Page 21: Linux Case Study

I/O USING DMA

• Allows transfer of data to or from memory without intervention of processor.

• DMA controller has 8 DMA channels.• Each channel has 16 bit address and count register.• DMA channels are not shareable.• Linux tracks the usage of the DMA channels using a vector

of dma_chan data structures (one per DMA channel). The dma_chan data structure contains just two fields, a pointer to a string describing the owner of the DMA channel and a flag indicating if the DMA channel is allocated or not.

• Some devices have a fixed DMA channel.

Page 22: Linux Case Study

Data transfer using DMA

Page 23: Linux Case Study

I/O USING POLLING AND INTERRUPTS

• Polling the device usually means reading its status register every so often until the device's status changes to indicate that it has completed the request.

• An interrupt driven device driver is one where the hardware device being controlled will raise a hardware interrupt whenever it needs to be serviced.

• Device driver registers the address of an interrupt handling routine and the interrupt number that it wishes to own.

• Interrupts entries in /proc/interrupts file.

Page 24: Linux Case Study

MEMORY MANAGEMENT

• LINUX supports virtual memory.• Virtual and physical memory are divided into handy sized

chunks called pages.• Linux on Alpha AXP systems uses 8 Kbyte pages and on Intel

x86 systems it uses 4 Kbyte pages. Each of these pages is given a unique number; the page frame number (PFN).

• A virtual address is composed of two parts; an offset and a virtual page frame number. If the page size is 4 Kbytes, bits 11:0 of the virtual address contain the offset and bits 12 and above are the virtual page frame number.

• To translate the virtual page frame number into a physical one the processor uses page tables.

Page 25: Linux Case Study

Virtual to physical address mapping

Page 26: Linux Case Study

PAGE TABLE

Page table contains the following information:• Valid flag. This indicates if this page table entry is

valid • The physical page frame number that this entry is

describing • Access control information. This describes how the

page may be used. Can it be written to? Does it contain executable code?

Note - The page table is accessed using the virtual page frame number as an offset.

Page 27: Linux Case Study

SOME CONCEPTS…

DEMAND PAGING :- • Technique of only loading virtual pages into

memory as they are accessed is known as demand paging.

• Linux uses demand paging to load executable images into a processes virtual memory.

• Linux uses the processes memory map in order to determine which parts of the image to bring into memory for execution.

Page 28: Linux Case Study

CONTD…

SWAPPING :- • To bring a virtual page into physical memory when no free

physical pages available, the operating system discards another page from physical memory.

• Linux uses a Least Recently Used (LRU) page aging technique to fairly choose pages which might be removed from the system. This scheme involves every page in the system having an age which changes as the page is accessed. The more that a page is accessed, the younger it is; the less that it is accessed the older and more stale it becomes. Old pages are good candidates for swapping.

Page 29: Linux Case Study

CONTD…

LINUX PAGE TABLES :- • Linux assumes that there are three levels of page tables. Each Page Table accessed contains the page

frame number of the next level of Page Table.• To translate a virtual address into a physical one, the

processor must take the contents of each level field, convert it into an offset into the physical page containing the Page Table and read the page frame number of the next level of Page Table. This is repeated three times until the page frame number of the physical page containing the virtual address is found.

Page 30: Linux Case Study

Three Level page tables

Page 31: Linux Case Study

अनू�पसं�जी�व

संधन्यव द