SlideShare a Scribd company logo
1 of 84
Linux Kernel Internals
Outline
• Linux Introduction
• Linux Kernel Architecture
• Linux Kernel Components
Linux Introduction
Linux Introduction
• History
• Features
• Resources
Features
• Free
• Open system
• Open source
• GNU GPL (General Public License)
• POSIX standard
• High portability
• High performance
• Robust
• Large development toolset
• Large number of device drivers
• Large number of application programs
Features (Cont.)
• Multi-tasking
• Multi-user
• Multi-processing
• Virtual memory
• Monolithic kernel
• Loadable kernel modules
• Networking
• Shared libraries
• Support different file systems
• Support different executable file formats
• Support different networking protocols
• Support different architectures
Resources
• Distributions
• Books
• Magazines
• Web sites
• ftp cites
• bbs
Linux Kernel Architecture
Linux Kernel Architecture
• User View of Linux Operating System
• Linux Kernel Architecture
• Kernel Source Code Organization
User View of Linux Operating System
Hardware
Kernel
Shell
Applications
System Structure
Systemcallsinterface
Filesystems
ext2fs xiafs proc
minix nfs msdos
iso9660
Taskmanagement
Scheduler
Signals
Loadablemodules
Memorymanagement
Centralkernel
Machineinterface
ipv4
ethernet
...
NetworkManager
Peripheralmanagers
block character
soundcard cdrom isdn
scsi pci
netwo
rk
BufferCache
Processes
Machine
Linux Kernel Architecture
Analysis of Linux Kernel Architecture
• Stability
• Safety
• Speed
• Brevity
• Compatability
• Portability
• Reusability and modifiability
• Monolithic kernel vs. microkernel
• Linux takes the advantages of monolithic kernel
and microkernel
Kernel Source Code Organization
• Source code web site:
http://www.kernel.org
• Source code version:
– X.Y.Z
– 2.2.17
– 2.4.0
Kernel Source Code Organization (Cont.)
Resources for Tracing Linux
• Source code browser
– cscope
– Global
– LXR (Source code navigator)
• Books
– Understanding the Linux Kernel, D. P. Bovet and M.
Cesati, O'Reilly & Associates, 2000.
– Linux Core Kernel – Commentary, In-Depth Code
Annotation, S. Maxwell, Coriolis Open Press, 1999.
– The Linux Kernel, Version 0.8-3, D. A Rusling, 1998.
– Linux Kernel Internals, 2nd
edition, M. Beck et al., Addison-
Wesley, 1998.
– Linux Kernel, R. Card et al., John Wiley & Sons, 1998.
How to compile Linux Kernel
1. make config (make manuconfig)
2. make depend
3. make boot
generate a compressed bootable linux kernel
arch/i386/boot/zIamge
make zdisk
generate kernel and write to disk
dd if=zImage of=/dev/fd0
make zlilo
generate kernel and copy to /vmlinuz
lilo: Linux Loader
Linux Kernel Components
Linux Kernel Components
• Bootstrap and system initializaiton
• Memory management
• Process management
• Interprocess communication
• File system
• Networking
• Device control and device drivers
Bootstrap and System Initialization
Events From Power-On To Linux
Kernel Running
Bootstrap and System Initialization
• Booting the PC (Events From Power On)
– Perform POST procedure
– Select boot device
– Load bootstrap program (bootsect.S) from floppy or HD
• Bootstrap program
– Hardware Initialization (setup.S)
– loads Linux kernel into memory (head.S)
– Initializes the Linux kernel
– Turn bootstrap sequence to start the first init process
Bootstrap and System Initialization (Cont.)
• Init process
– Create various system daemons
– Initialize kernel data structures
– Free initial memory unused afterwards
– Runs shell
• Shell accepts and executes user commands
Low-level Hardware Resource Handling
Interrupt handling
Trap/Exception handling
System call handling
Memory Management
Memory Management Subsystem
• Provides virtual memory mechanism
– Overcome memory limitation
– Makes the system appear to have more memory than it
actually has by sharing it between competing processes
as they need it.
• It provides:
– Large address spaces
– Protection
– Memory mapping
– Fair physical memory allocation
– Shared virtual memory
Memory Management
• x86 Memory Management
– Segmentation
– Paging
• Linux Memory Management
– Memory Initialization
– Memory Allocation & Deallocation
– Memory Map
– Page Fault Handling
– Demand Paging and Page Replacement
Segment Translation
Selector Offset
15 0 31 0
Segment Descriptor Table
Segment
Descriptor
base address
+
Dir Page Offset
linear address
logical address
Linear Address Translation
Directory Table Offset
31 22 21 12 11 0
linear address
Directory Entry
Page-Table Entry
Physical Address
10 10
12
CR3(PDBR)
32
Page directory
Page table
Physical memory
Segmentation and Paging
Segment
Descriptor
Segment
Selector Offset
Logical Address
Segment
Segment Base Address
Linear Address
Space
Page
Dir Table Offset
Linear Address
Page
Physical Address
Space
Page
Directory
Page Table
Abstract model of Virtual to Physical
address mapping
VPFN7
VPFN6
VPFN3
VPFN2
VPFN1
VPFN0
VPFN4
VPFN5
VPFN7
VPFN6
VPFN3
VPFN2
VPFN1
VPFN0
VPFN4
VPFN5
PFN3
PFN2
PFN1
PFN0
PFN4
Process X Process Y
Process X
Page Table
Process Y
Page Table
Virtual Memory Virtual Memory
Physical Memory
An Abstract Model of VM (Cont.)
• Each page table entry contains:
– Valid flag
– Physical page frame number
– Access control information
• X86 page table entry and page directory entry:
31 12 6 5 2 1 0
Page Address D A
U
/
S
R
/
W
P
Demand Paging
• Loading virtual pages into memory as they
are accessed
• Page fault handling
– faulting virtual address is invalid
– faulting virtual address was valid but the page
is not currently in memory
Swapping
• If a process needs to bring a virtual page
into physical memory and there are no free
physical pages available:
• Linux uses a Least Recently Used page
aging technique to choose pages which
might be removed from the system.
• Kernel Swap Daemon (kswapd)
Caches
• To improve performance, Linux uses a
number of memory management related
caches:
– Buffer Cache
– Page Caches
– Swap Cache
– Hardware Caches (Translation Look-aside
Buffers)
Page Allocation and Deallocation
• Linux uses the Buddy algorithm to effectively
allocate and deallocate blocks of pages.
• Pages are allocated in blocks which are powers of 2
in size.
– If the block of pages found is larger than requested must
be broken down until there is a block of the right size.
• The page deallocation codes recombine pages into
large blocks of free pages whenever it can.
– Whenever a block of pages is freed, the adjacent or buddy
block of the same size is checked to see if it is free.
Splitting of Memory in a Buddy Heap
Vmlist for virtual memory allocation
vmalloc() & vfree()
vmlist
VMALLOC_START VMALLOC_END
: Allocated space : Unallocated space
addr addr+size
•first-fit algorithm
Process Management
What is a Process ?
• A program in execution.
• A process includes program's instructions and
data, program counter and all CPU's registers,
process stacks containing temporary data.
• Each individual process runs in its own virtual
address space and is not capable of interacting
with another process except through secure, kernel
managed mechanisms.
Linux Processes
• Each process is represented by a task_struct data
structure, containing:
– Process State
– Scheduling Information
– Identifiers
– Inter-Process Communication
– Times and Timers
– File system
– Virtual memory
– Processor Specific Context
Process State
ready
stopped
suspended
executing zombie
creation
signal signal
scheduling
input / output
end of
input / output
termination
parent
youngest
child
child
oldest
child
p_osptrp_osptr
p_ysptrp_ysptr
p_pptr
p_opptr
p_pptr
p_opptr
p_pptr
p_opptr
p_cptr
Process RelationshipProcess Relationship
Managing TasksManaging Tasks
pidhashpidhash
struct task_structstruct task_struct
next_task
prev_task
tasktask
tarray_freelisttarray_freelist
Scheduling
• As well as the normal type of process, Linux supports
real time processes. The scheduler treats real time
processes differently from normal user processes
• Pre-emptive scheduling.
• Priority based scheduling algorithm
• Time-slice: 200ms
• Schedule: select the most deserving process to run
– Priority: weight
• Normal : counter
• Real Time : counter + 1000
A Process's Files
current
task_struct
...
files
...
...
...
...
...
...
Tableof
openfiles
Tableof
i-nodes
Virtual Memory
• A process's virtual memory contains executable
code and data from many sources.
• Processes can allocate (virtual) memory to use
during their processing
• Demand paging is used where the virtual
memory of a process is brought into physical
memory only when a process attempts to use it.
Process Address Space
kernel
memory
environment
arguments
stack
data(bss)
data
code
0
0xC0000000
A Process’s Virtual Memory
mm
Process’s
Virtual Memory
count
pgd
mmap
mmap_avl
mmap_sem
mm_struct
task_struct
vm_end
vm_start
vm_flags
vm_inode
vm_ops
vm_next
vm_end
vm_start
vm_flags
vm_inode
vm_ops
vm_next
vm_area_struct
code
data
vm_area_struct
Process Creation and Execution
• UNX process management separates the
creation of processes and the running of a
new program into two distinct operations.
– The fork system call creates a new process.
– A new program is run after a call to execve.
• Programs and commands are normally executed
by a command interpreter.
• A command interpreter is a user process like any
other process and is called a shell
ex.sh, bash and tcsh
• Executable object files:
– Contain executable code and data together with
information to be loaded and executed by OS
• Linux Binary Format
– ELF, a.out, script
Executing Programs
How to execute a program?
Shell clone itself and binary image is replaced with
executable image
Command enter
Search file in
process’s search path(PATH)
ELF
• ELF (Executable and Linkable Format)
object file format
– designed by Unix System Laboratories
– the most commonly used
format in Linux
Format header
Physical header
(Code)
Physical header
(Data)
Code
Data
Interprocess Communication Mechanisms
(IPC)
Signals
Pipes
Message Queues
Semaphores
Shared Memory
Signals
• Signals inform processes of the occurrence of
asynchronous events.
• Processes may send each other signals by kill system
call, or kernel may send signals to a process.
• A set of defined signals in the system:
• 1)SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
• 5) SIGTRAP 6) SIGIOT 7) SIGBUS 8) SIGFPE
• 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
• 13) SIGPIPE 14) SIGALR 15)SIGTERM
• 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
• 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU
• 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
• 29) SIGIO 30) SIGPWR
Signals (Cont.)
• A process can choose to block or handle signals itself
or allow kernel to handle it
• Kernel handles signals using default actions.
– E.g., SIGFPE(floating point exception) : core dump and exit
• Signal related fields in task_struct data structure
– signal (32 bits): pending signals
– blocked: a mask of blocked signal
– sigaction array: address of handling routine or a flag to let
kernel handle the signal
Pipes
• one-way flow of data
• The writer and the reader communicate
using standard read/write library function
TaskA TaskB
Communicationpipe
Restriction of Pipes and Signals
• Pipe:
– Impossible for any arbitrary process to read or write in a
pipe unless it is the child of the process which created it.
– Named Pipes (also known as FIFO)
• also one-way flow of data
• allowing unrelated processes to access a single FIFO.
• Signal
– The only information transported is a simple number,
which renders signals unsuitable for transferring data.
System V IPC Mechanism
• Linux supports 3 types of IPC mechanisms:
– Message queues, semaphores and shared
memory
– First appeared in UNIX System V in 1983
• They allow unrelated processes to
communicate with each other.
Key Management
• Processes may access these IPC resources
only by passing a unique reference
identifier to the kernel via system calls.
• Senders and receivers must agree on a
common key to find the reference identifier
for the System V IPC object.
• Access to these System V IPC objects is
checked using access permissions.
Shared Memory and Semaphores
• Shared memory
– Allow processes to communicate via memory that
appears in all of their virtual address space
– As with all System V IPC objects, access to shared
memory areas is controlled via keys and access rights
checking.
– Must rely on other mechanisms (e.g. semaphores) to
synchronize access to the memory
• Semaphores
– A semaphore is a location in memory whose value can
be tested and set (atomic) by more than one processes
– Can be used to implement critical regions
Create
Segment
Give a valid
IPC identifier
Process to attach
segment
For read and
write
Execute commands
about
Shared memory
Remove or
detach
segment
Sys_shmget() Sys_shmat()
Sys_shmctl()Sys_shmdt()
Semaphores
structsem_queues
structmsqid_ds
IPC_NOID
IPC_UNUSED
structsems
Message Queues
• Allow one or more processes to write messages,
which will be read by one or more reading
processes structmsqid_ds
structmsgs
IPC_NOID
IPC_UNUSED
File System
Linux File System
• Linux supports different file system structures at
the same time
– Ext2, ISO 9660, ufs, FAT-16,VFAT,…
• Hierarchical File System Structure
– Linux adds each new file system into this single file
system tree as it is mounted.
• The real file systems are separated from the OS by
an interface layer: Virtual File System: VFS
• VFS allows Linux to support many different file
systems, each presenting a common software
interface to the VFS.
Hierarchical File System Structure
/
bin dev etc lib sbin usr
bin include lib man sbin
ls cp
cc
Mounting of Filesystems
/
bin dev etc lib sbin usr
bin include lib man sbin
bin include lib man sbin
/
bin dev etc lib sbin usr
/
mountingoperation
/usrfilesystemrootfilesystem
completehierarchyaftermounting/usr
The Layers in the File System
Process
1
Process
2
Process
n
VirtualFileSystem
ext2 msdos minix proc
Buffercache
Devicedrivers
Filesystem
Usermode
Systemmode
Ext2 File System
• Devised (by Rémy Card) as an extensible and
powerful file system for Linux.
• Allocation space to files
– Data in files is kept in fixed-size data blocks
– Indexed allocation (inode)
• directory : special file which contains pointers to
the inodes of its directory entries
• Divides the logical partition that it occupies into
Block Groups.
Physical Layout of File Systems
Block
Group 0
Block
Group 1
…...
Block
Group n
Super
block
Group
descriptors
Block
bitmap
Inode
bitmap
Inode
table
Data
blocks
• Schematic Structure of a UNIX File System
• Physical Layout of EXT2 File System
Inodeblocks
2...
SuperblockBootblock
10
Datablocks
The EXT2 Inode
Mode
Owner Info
Size
Timestamps
Direct Blocks
Indirect blocks
Double Indirect
Triple Indirect
data
data
data
data
data
data
data
Directory Format
name1
name2
name3
name4
3
2
3
0
directory
i-nodetable
0
1
2
3
4
5
The Virtual File System (VFS)
System callinterface
Virtualfilesystem
ext2fsminix proc
Buffercache
Devicedrivers
Tasks
Machine
Inode
cache
Directory
cache
Allocating Blocks to a File
• To avoid fragmentation that file blocks may
spread all over the file system, EXT2 file
system:
– Allocating the new blocks for a file physically
close to its current data blocks or at least in the
same Block Group as its current data blocks as
possible.
– Block preallocation
Speedup Access
• VFS Inode Cache
• Directory Cache
– stores the mapping between the full directory names
and their inode numbers.
• Buffer Cache
– All of the Linux file systems use a common buffer
cache to cache data buffers from the underlying devices
• Replacement policy: LRU
bdflush & update Kernel Daemons
• The bdflush kernel daemon
– provides a dynamic response to the system
having too many dirty buffers (default:60%).
– tries to write a reasonable number of dirty
buffers out to their owning disks (default:500).
• The update daemon
– periodically flush all older dirty buffers out to
disk
The /proc File System
• It does not really exist.
• Presents a user readable windows into the kernel’s
inner workings.
• The /proc file system serves information about the running
system. It not only allows access to process data but also
allows you to request the kernel status by reading files in the
hierarchy.
• System information
– Process-Specific Subdirectories
– Kernel data
– IDE devices in /proc/ide
– Networking info in /proc/net, SCSI info
– Parallel port info in /proc/parport
– TTY info in /proc/tty
Networking
Linux Networking Layers
Network Applications
BSD Sockets
INET Sockets
TCP UDP
IP
PPP SLIP Ethernet
ARP
User
Kernel
Socket Interface
Protocol Layers
Network Devices
Server Client Model
Server
socket( )
bind( )
listen( )
accept( )
socket( )
read( )
connection establishment
connect( )
write( )
write( ) read( )
data(replay)
data(request)
close( )close( )
connection break
Client
Linux BSD Socket Data Structure
files_struct
count
close_on_exec
open_fs
fd[0]
fd[1]
fd[255]
file
f_mode
f_pos
f_flags
f_count
f_owner
f_op
f_inode
f_version
inode
sock
socket
type
protocol
data
type
protocol
socket
SOCK_STREAM
SOCK_STREAM
Address Family
socket operations
BSD Socket
File Operations
lseek
read
write
select
ioctl
close
fasync
Loadable Kernel Module
• A Kernel Module is not an independent
executable, but an object file which will be
linked into the kernel in runtime.
• Modules can be “dynamically integrated”
into the kernel. When no longer used, the
modules may then be unloaded.
• Enable the system to have an “extended”
kernel.
Loading Modules
Kernel
Loading
Compiled
Kernel
Kernelafterloading
modules
Minix
Printer
PPP
NFS
Kernel

More Related Content

What's hot

Linux internal
Linux internalLinux internal
Linux internalmcganesh
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel SourceMotaz Saad
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsDivye Kapoor
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel ProgrammingNalin Sharma
 
linux device driver
linux device driverlinux device driver
linux device driverRahul Batra
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programmingVandana Salve
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPTQUONTRASOLUTIONS
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device DriverGary Yeh
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 
Visual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & VirtualisationVisual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & Virtualisationwangyuanyi
 
Introduction to Linux Kernel
Introduction to Linux KernelIntroduction to Linux Kernel
Introduction to Linux KernelStryker King
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device driversAlexandre Moreno
 
Type of Embedded core
Type of Embedded core Type of Embedded core
Type of Embedded core mukul bhardwaj
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modulesEddy Reyes
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)shimosawa
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]mcganesh
 

What's hot (19)

Linux internal
Linux internalLinux internal
Linux internal
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
 
Linux kernel architecture
Linux kernel architectureLinux kernel architecture
Linux kernel architecture
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
Linux Kernel I/O Schedulers
Linux Kernel I/O SchedulersLinux Kernel I/O Schedulers
Linux Kernel I/O Schedulers
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Visual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & VirtualisationVisual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & Virtualisation
 
Introduction to Linux Kernel
Introduction to Linux KernelIntroduction to Linux Kernel
Introduction to Linux Kernel
 
brief intro to Linux device drivers
brief intro to Linux device driversbrief intro to Linux device drivers
brief intro to Linux device drivers
 
Type of Embedded core
Type of Embedded core Type of Embedded core
Type of Embedded core
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Linuxdd[1]
Linuxdd[1]Linuxdd[1]
Linuxdd[1]
 

Viewers also liked

Kernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesKernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesAnne Nicolas
 
Hybrid kernel
Hybrid kernelHybrid kernel
Hybrid kernelAbu Azzam
 
Basic linux architecture
Basic linux architectureBasic linux architecture
Basic linux architectureRohit Kumar
 
Part 1 of 'Introduction to Linux for bioinformatics': Introduction
Part 1 of 'Introduction to Linux for bioinformatics': IntroductionPart 1 of 'Introduction to Linux for bioinformatics': Introduction
Part 1 of 'Introduction to Linux for bioinformatics': IntroductionJoachim Jacob
 
A general Overview of linux !!
A general Overview of linux !!A general Overview of linux !!
A general Overview of linux !!jainema23
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
Introduction to GNU/Linux
Introduction to GNU/LinuxIntroduction to GNU/Linux
Introduction to GNU/LinuxRupam Das
 
Fuel, Puppet and OpenStack
Fuel, Puppet and OpenStackFuel, Puppet and OpenStack
Fuel, Puppet and OpenStackaedocw
 
Cloud Foundry Introduction and Overview
Cloud Foundry Introduction and OverviewCloud Foundry Introduction and Overview
Cloud Foundry Introduction and OverviewAndy Piper
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux IntroductionRamasubbu .P
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniquesSatpal Parmar
 
Automating OpenStack Deployment with Fuel
Automating OpenStack Deployment with FuelAutomating OpenStack Deployment with Fuel
Automating OpenStack Deployment with FuelTomasz Zen Napierala
 
Case study operating systems
Case study operating systemsCase study operating systems
Case study operating systemsAkhil Bevara
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversSatpal Parmar
 

Viewers also liked (20)

Intro to linux
Intro to linuxIntro to linux
Intro to linux
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Kernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologiesKernel Recipes 2015: Kernel packet capture technologies
Kernel Recipes 2015: Kernel packet capture technologies
 
Hybrid kernel
Hybrid kernelHybrid kernel
Hybrid kernel
 
Basic linux architecture
Basic linux architectureBasic linux architecture
Basic linux architecture
 
Part 1 of 'Introduction to Linux for bioinformatics': Introduction
Part 1 of 'Introduction to Linux for bioinformatics': IntroductionPart 1 of 'Introduction to Linux for bioinformatics': Introduction
Part 1 of 'Introduction to Linux for bioinformatics': Introduction
 
A general Overview of linux !!
A general Overview of linux !!A general Overview of linux !!
A general Overview of linux !!
 
Systemtap
SystemtapSystemtap
Systemtap
 
Introduction to GNU/Linux
Introduction to GNU/LinuxIntroduction to GNU/Linux
Introduction to GNU/Linux
 
Fuel, Puppet and OpenStack
Fuel, Puppet and OpenStackFuel, Puppet and OpenStack
Fuel, Puppet and OpenStack
 
Cloud Foundry Introduction and Overview
Cloud Foundry Introduction and OverviewCloud Foundry Introduction and Overview
Cloud Foundry Introduction and Overview
 
Case study linux
Case study linuxCase study linux
Case study linux
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 
Automating OpenStack Deployment with Fuel
Automating OpenStack Deployment with FuelAutomating OpenStack Deployment with Fuel
Automating OpenStack Deployment with Fuel
 
Case study operating systems
Case study operating systemsCase study operating systems
Case study operating systems
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Window architecture
Window architecture Window architecture
Window architecture
 

Similar to Linux introduction

Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsnullowaspmumbai
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh Naik
 
Workshop - Linux Memory Analysis with Volatility
Workshop - Linux Memory Analysis with VolatilityWorkshop - Linux Memory Analysis with Volatility
Workshop - Linux Memory Analysis with VolatilityAndrew Case
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Mac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityMac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityAndrew Case
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-reviewabinaya m
 
Chap1_Part2.pptx
Chap1_Part2.pptxChap1_Part2.pptx
Chap1_Part2.pptxNMohd3
 
Linux操作系统01 简介
Linux操作系统01 简介Linux操作系统01 简介
Linux操作系统01 简介lclsg123
 
Ospresentation 120112074429-phpapp02 (1)
Ospresentation 120112074429-phpapp02 (1)Ospresentation 120112074429-phpapp02 (1)
Ospresentation 120112074429-phpapp02 (1)Vivian Vhaves
 
Regarding About Operating System Structure
Regarding About Operating System StructureRegarding About Operating System Structure
Regarding About Operating System Structuresankarkvdc
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsQUONTRASOLUTIONS
 

Similar to Linux introduction (20)

Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Ganesh naik linux_kernel_internals
Ganesh naik linux_kernel_internalsGanesh naik linux_kernel_internals
Ganesh naik linux_kernel_internals
 
Workshop - Linux Memory Analysis with Volatility
Workshop - Linux Memory Analysis with VolatilityWorkshop - Linux Memory Analysis with Volatility
Workshop - Linux Memory Analysis with Volatility
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Windows XP operating system
Windows XP operating systemWindows XP operating system
Windows XP operating system
 
Os
OsOs
Os
 
Mac Memory Analysis with Volatility
Mac Memory Analysis with VolatilityMac Memory Analysis with Volatility
Mac Memory Analysis with Volatility
 
Unit 4
Unit  4Unit  4
Unit 4
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Chap1_Part2.pptx
Chap1_Part2.pptxChap1_Part2.pptx
Chap1_Part2.pptx
 
Os
OsOs
Os
 
Linux操作系统01 简介
Linux操作系统01 简介Linux操作系统01 简介
Linux操作系统01 简介
 
Ospresentation 120112074429-phpapp02 (1)
Ospresentation 120112074429-phpapp02 (1)Ospresentation 120112074429-phpapp02 (1)
Ospresentation 120112074429-phpapp02 (1)
 
kerch04.ppt
kerch04.pptkerch04.ppt
kerch04.ppt
 
Regarding About Operating System Structure
Regarding About Operating System StructureRegarding About Operating System Structure
Regarding About Operating System Structure
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
The Linux System
The Linux SystemThe Linux System
The Linux System
 
distcom-short-20140112-1600
distcom-short-20140112-1600distcom-short-20140112-1600
distcom-short-20140112-1600
 

More from Abhishek Khune (16)

07 java collection
07 java collection07 java collection
07 java collection
 
Clanguage
ClanguageClanguage
Clanguage
 
Java Notes
Java NotesJava Notes
Java Notes
 
Threads
ThreadsThreads
Threads
 
Sorting
SortingSorting
Sorting
 
Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01Slide8appletv2 091028110313-phpapp01
Slide8appletv2 091028110313-phpapp01
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Week0 introduction
Week0 introductionWeek0 introduction
Week0 introduction
 
Binary trees
Binary treesBinary trees
Binary trees
 
Applets
AppletsApplets
Applets
 
Clanguage
ClanguageClanguage
Clanguage
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
Java unit3
Java unit3Java unit3
Java unit3
 
Java unit2
Java unit2Java unit2
Java unit2
 
Shared memory
Shared memoryShared memory
Shared memory
 
Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)
 

Recently uploaded

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Recently uploaded (20)

What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

Linux introduction

  • 2. Outline • Linux Introduction • Linux Kernel Architecture • Linux Kernel Components
  • 4. Linux Introduction • History • Features • Resources
  • 5. Features • Free • Open system • Open source • GNU GPL (General Public License) • POSIX standard • High portability • High performance • Robust • Large development toolset • Large number of device drivers • Large number of application programs
  • 6. Features (Cont.) • Multi-tasking • Multi-user • Multi-processing • Virtual memory • Monolithic kernel • Loadable kernel modules • Networking • Shared libraries • Support different file systems • Support different executable file formats • Support different networking protocols • Support different architectures
  • 7. Resources • Distributions • Books • Magazines • Web sites • ftp cites • bbs
  • 9. Linux Kernel Architecture • User View of Linux Operating System • Linux Kernel Architecture • Kernel Source Code Organization
  • 10. User View of Linux Operating System Hardware Kernel Shell Applications
  • 11. System Structure Systemcallsinterface Filesystems ext2fs xiafs proc minix nfs msdos iso9660 Taskmanagement Scheduler Signals Loadablemodules Memorymanagement Centralkernel Machineinterface ipv4 ethernet ... NetworkManager Peripheralmanagers block character soundcard cdrom isdn scsi pci netwo rk BufferCache Processes Machine
  • 13. Analysis of Linux Kernel Architecture • Stability • Safety • Speed • Brevity • Compatability • Portability • Reusability and modifiability • Monolithic kernel vs. microkernel • Linux takes the advantages of monolithic kernel and microkernel
  • 14. Kernel Source Code Organization • Source code web site: http://www.kernel.org • Source code version: – X.Y.Z – 2.2.17 – 2.4.0
  • 15. Kernel Source Code Organization (Cont.)
  • 16. Resources for Tracing Linux • Source code browser – cscope – Global – LXR (Source code navigator) • Books – Understanding the Linux Kernel, D. P. Bovet and M. Cesati, O'Reilly & Associates, 2000. – Linux Core Kernel – Commentary, In-Depth Code Annotation, S. Maxwell, Coriolis Open Press, 1999. – The Linux Kernel, Version 0.8-3, D. A Rusling, 1998. – Linux Kernel Internals, 2nd edition, M. Beck et al., Addison- Wesley, 1998. – Linux Kernel, R. Card et al., John Wiley & Sons, 1998.
  • 17. How to compile Linux Kernel 1. make config (make manuconfig) 2. make depend 3. make boot generate a compressed bootable linux kernel arch/i386/boot/zIamge make zdisk generate kernel and write to disk dd if=zImage of=/dev/fd0 make zlilo generate kernel and copy to /vmlinuz lilo: Linux Loader
  • 19. Linux Kernel Components • Bootstrap and system initializaiton • Memory management • Process management • Interprocess communication • File system • Networking • Device control and device drivers
  • 20. Bootstrap and System Initialization Events From Power-On To Linux Kernel Running
  • 21. Bootstrap and System Initialization • Booting the PC (Events From Power On) – Perform POST procedure – Select boot device – Load bootstrap program (bootsect.S) from floppy or HD • Bootstrap program – Hardware Initialization (setup.S) – loads Linux kernel into memory (head.S) – Initializes the Linux kernel – Turn bootstrap sequence to start the first init process
  • 22. Bootstrap and System Initialization (Cont.) • Init process – Create various system daemons – Initialize kernel data structures – Free initial memory unused afterwards – Runs shell • Shell accepts and executes user commands
  • 23. Low-level Hardware Resource Handling Interrupt handling Trap/Exception handling System call handling
  • 25. Memory Management Subsystem • Provides virtual memory mechanism – Overcome memory limitation – Makes the system appear to have more memory than it actually has by sharing it between competing processes as they need it. • It provides: – Large address spaces – Protection – Memory mapping – Fair physical memory allocation – Shared virtual memory
  • 26. Memory Management • x86 Memory Management – Segmentation – Paging • Linux Memory Management – Memory Initialization – Memory Allocation & Deallocation – Memory Map – Page Fault Handling – Demand Paging and Page Replacement
  • 27. Segment Translation Selector Offset 15 0 31 0 Segment Descriptor Table Segment Descriptor base address + Dir Page Offset linear address logical address
  • 28. Linear Address Translation Directory Table Offset 31 22 21 12 11 0 linear address Directory Entry Page-Table Entry Physical Address 10 10 12 CR3(PDBR) 32 Page directory Page table Physical memory
  • 29. Segmentation and Paging Segment Descriptor Segment Selector Offset Logical Address Segment Segment Base Address Linear Address Space Page Dir Table Offset Linear Address Page Physical Address Space Page Directory Page Table
  • 30. Abstract model of Virtual to Physical address mapping VPFN7 VPFN6 VPFN3 VPFN2 VPFN1 VPFN0 VPFN4 VPFN5 VPFN7 VPFN6 VPFN3 VPFN2 VPFN1 VPFN0 VPFN4 VPFN5 PFN3 PFN2 PFN1 PFN0 PFN4 Process X Process Y Process X Page Table Process Y Page Table Virtual Memory Virtual Memory Physical Memory
  • 31. An Abstract Model of VM (Cont.) • Each page table entry contains: – Valid flag – Physical page frame number – Access control information • X86 page table entry and page directory entry: 31 12 6 5 2 1 0 Page Address D A U / S R / W P
  • 32. Demand Paging • Loading virtual pages into memory as they are accessed • Page fault handling – faulting virtual address is invalid – faulting virtual address was valid but the page is not currently in memory
  • 33. Swapping • If a process needs to bring a virtual page into physical memory and there are no free physical pages available: • Linux uses a Least Recently Used page aging technique to choose pages which might be removed from the system. • Kernel Swap Daemon (kswapd)
  • 34. Caches • To improve performance, Linux uses a number of memory management related caches: – Buffer Cache – Page Caches – Swap Cache – Hardware Caches (Translation Look-aside Buffers)
  • 35. Page Allocation and Deallocation • Linux uses the Buddy algorithm to effectively allocate and deallocate blocks of pages. • Pages are allocated in blocks which are powers of 2 in size. – If the block of pages found is larger than requested must be broken down until there is a block of the right size. • The page deallocation codes recombine pages into large blocks of free pages whenever it can. – Whenever a block of pages is freed, the adjacent or buddy block of the same size is checked to see if it is free.
  • 36. Splitting of Memory in a Buddy Heap
  • 37. Vmlist for virtual memory allocation vmalloc() & vfree() vmlist VMALLOC_START VMALLOC_END : Allocated space : Unallocated space addr addr+size •first-fit algorithm
  • 39. What is a Process ? • A program in execution. • A process includes program's instructions and data, program counter and all CPU's registers, process stacks containing temporary data. • Each individual process runs in its own virtual address space and is not capable of interacting with another process except through secure, kernel managed mechanisms.
  • 40. Linux Processes • Each process is represented by a task_struct data structure, containing: – Process State – Scheduling Information – Identifiers – Inter-Process Communication – Times and Timers – File system – Virtual memory – Processor Specific Context
  • 41. Process State ready stopped suspended executing zombie creation signal signal scheduling input / output end of input / output termination
  • 43. Managing TasksManaging Tasks pidhashpidhash struct task_structstruct task_struct next_task prev_task tasktask tarray_freelisttarray_freelist
  • 44. Scheduling • As well as the normal type of process, Linux supports real time processes. The scheduler treats real time processes differently from normal user processes • Pre-emptive scheduling. • Priority based scheduling algorithm • Time-slice: 200ms • Schedule: select the most deserving process to run – Priority: weight • Normal : counter • Real Time : counter + 1000
  • 46. Virtual Memory • A process's virtual memory contains executable code and data from many sources. • Processes can allocate (virtual) memory to use during their processing • Demand paging is used where the virtual memory of a process is brought into physical memory only when a process attempts to use it.
  • 48. A Process’s Virtual Memory mm Process’s Virtual Memory count pgd mmap mmap_avl mmap_sem mm_struct task_struct vm_end vm_start vm_flags vm_inode vm_ops vm_next vm_end vm_start vm_flags vm_inode vm_ops vm_next vm_area_struct code data vm_area_struct
  • 49. Process Creation and Execution • UNX process management separates the creation of processes and the running of a new program into two distinct operations. – The fork system call creates a new process. – A new program is run after a call to execve.
  • 50. • Programs and commands are normally executed by a command interpreter. • A command interpreter is a user process like any other process and is called a shell ex.sh, bash and tcsh • Executable object files: – Contain executable code and data together with information to be loaded and executed by OS • Linux Binary Format – ELF, a.out, script Executing Programs
  • 51. How to execute a program? Shell clone itself and binary image is replaced with executable image Command enter Search file in process’s search path(PATH)
  • 52. ELF • ELF (Executable and Linkable Format) object file format – designed by Unix System Laboratories – the most commonly used format in Linux Format header Physical header (Code) Physical header (Data) Code Data
  • 54. Signals • Signals inform processes of the occurrence of asynchronous events. • Processes may send each other signals by kill system call, or kernel may send signals to a process. • A set of defined signals in the system: • 1)SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL • 5) SIGTRAP 6) SIGIOT 7) SIGBUS 8) SIGFPE • 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 • 13) SIGPIPE 14) SIGALR 15)SIGTERM • 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP • 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU • 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH • 29) SIGIO 30) SIGPWR
  • 55. Signals (Cont.) • A process can choose to block or handle signals itself or allow kernel to handle it • Kernel handles signals using default actions. – E.g., SIGFPE(floating point exception) : core dump and exit • Signal related fields in task_struct data structure – signal (32 bits): pending signals – blocked: a mask of blocked signal – sigaction array: address of handling routine or a flag to let kernel handle the signal
  • 56. Pipes • one-way flow of data • The writer and the reader communicate using standard read/write library function TaskA TaskB Communicationpipe
  • 57. Restriction of Pipes and Signals • Pipe: – Impossible for any arbitrary process to read or write in a pipe unless it is the child of the process which created it. – Named Pipes (also known as FIFO) • also one-way flow of data • allowing unrelated processes to access a single FIFO. • Signal – The only information transported is a simple number, which renders signals unsuitable for transferring data.
  • 58. System V IPC Mechanism • Linux supports 3 types of IPC mechanisms: – Message queues, semaphores and shared memory – First appeared in UNIX System V in 1983 • They allow unrelated processes to communicate with each other.
  • 59. Key Management • Processes may access these IPC resources only by passing a unique reference identifier to the kernel via system calls. • Senders and receivers must agree on a common key to find the reference identifier for the System V IPC object. • Access to these System V IPC objects is checked using access permissions.
  • 60. Shared Memory and Semaphores • Shared memory – Allow processes to communicate via memory that appears in all of their virtual address space – As with all System V IPC objects, access to shared memory areas is controlled via keys and access rights checking. – Must rely on other mechanisms (e.g. semaphores) to synchronize access to the memory • Semaphores – A semaphore is a location in memory whose value can be tested and set (atomic) by more than one processes – Can be used to implement critical regions
  • 61. Create Segment Give a valid IPC identifier Process to attach segment For read and write Execute commands about Shared memory Remove or detach segment Sys_shmget() Sys_shmat() Sys_shmctl()Sys_shmdt()
  • 63. Message Queues • Allow one or more processes to write messages, which will be read by one or more reading processes structmsqid_ds structmsgs IPC_NOID IPC_UNUSED
  • 65. Linux File System • Linux supports different file system structures at the same time – Ext2, ISO 9660, ufs, FAT-16,VFAT,… • Hierarchical File System Structure – Linux adds each new file system into this single file system tree as it is mounted. • The real file systems are separated from the OS by an interface layer: Virtual File System: VFS • VFS allows Linux to support many different file systems, each presenting a common software interface to the VFS.
  • 66. Hierarchical File System Structure / bin dev etc lib sbin usr bin include lib man sbin ls cp cc
  • 67. Mounting of Filesystems / bin dev etc lib sbin usr bin include lib man sbin bin include lib man sbin / bin dev etc lib sbin usr / mountingoperation /usrfilesystemrootfilesystem completehierarchyaftermounting/usr
  • 68. The Layers in the File System Process 1 Process 2 Process n VirtualFileSystem ext2 msdos minix proc Buffercache Devicedrivers Filesystem Usermode Systemmode
  • 69. Ext2 File System • Devised (by Rémy Card) as an extensible and powerful file system for Linux. • Allocation space to files – Data in files is kept in fixed-size data blocks – Indexed allocation (inode) • directory : special file which contains pointers to the inodes of its directory entries • Divides the logical partition that it occupies into Block Groups.
  • 70. Physical Layout of File Systems Block Group 0 Block Group 1 …... Block Group n Super block Group descriptors Block bitmap Inode bitmap Inode table Data blocks • Schematic Structure of a UNIX File System • Physical Layout of EXT2 File System Inodeblocks 2... SuperblockBootblock 10 Datablocks
  • 71. The EXT2 Inode Mode Owner Info Size Timestamps Direct Blocks Indirect blocks Double Indirect Triple Indirect data data data data data data data
  • 73. The Virtual File System (VFS) System callinterface Virtualfilesystem ext2fsminix proc Buffercache Devicedrivers Tasks Machine Inode cache Directory cache
  • 74. Allocating Blocks to a File • To avoid fragmentation that file blocks may spread all over the file system, EXT2 file system: – Allocating the new blocks for a file physically close to its current data blocks or at least in the same Block Group as its current data blocks as possible. – Block preallocation
  • 75. Speedup Access • VFS Inode Cache • Directory Cache – stores the mapping between the full directory names and their inode numbers. • Buffer Cache – All of the Linux file systems use a common buffer cache to cache data buffers from the underlying devices • Replacement policy: LRU
  • 76. bdflush & update Kernel Daemons • The bdflush kernel daemon – provides a dynamic response to the system having too many dirty buffers (default:60%). – tries to write a reasonable number of dirty buffers out to their owning disks (default:500). • The update daemon – periodically flush all older dirty buffers out to disk
  • 77. The /proc File System • It does not really exist. • Presents a user readable windows into the kernel’s inner workings. • The /proc file system serves information about the running system. It not only allows access to process data but also allows you to request the kernel status by reading files in the hierarchy. • System information – Process-Specific Subdirectories – Kernel data – IDE devices in /proc/ide – Networking info in /proc/net, SCSI info – Parallel port info in /proc/parport – TTY info in /proc/tty
  • 78.
  • 80. Linux Networking Layers Network Applications BSD Sockets INET Sockets TCP UDP IP PPP SLIP Ethernet ARP User Kernel Socket Interface Protocol Layers Network Devices
  • 81. Server Client Model Server socket( ) bind( ) listen( ) accept( ) socket( ) read( ) connection establishment connect( ) write( ) write( ) read( ) data(replay) data(request) close( )close( ) connection break Client
  • 82. Linux BSD Socket Data Structure files_struct count close_on_exec open_fs fd[0] fd[1] fd[255] file f_mode f_pos f_flags f_count f_owner f_op f_inode f_version inode sock socket type protocol data type protocol socket SOCK_STREAM SOCK_STREAM Address Family socket operations BSD Socket File Operations lseek read write select ioctl close fasync
  • 83. Loadable Kernel Module • A Kernel Module is not an independent executable, but an object file which will be linked into the kernel in runtime. • Modules can be “dynamically integrated” into the kernel. When no longer used, the modules may then be unloaded. • Enable the system to have an “extended” kernel.