Suvendu Kumar Dash
Suvendu.15292@gmail.com
M.Tech ECE
VtP1492

 Memory Structure of Linux OS.
 How Program is loaded into the memory.
 Address Translation.
 Feature for Multithreading and Multiprocessing.
Overview
10/10/2014 suvendu.15292@gmail.com 2

 Linux is one of popular version of UNIX operating
System.
 It is open source as its source code is freely available.
 It is free to use. Linux was designed considering
UNIX compatibility.
 It's functionality list is quite similar to that of UNIX.
Linux OS
10/10/2014 suvendu.15292@gmail.com 3

Linux Operating System has primarily three components
 Kernel - Kernel is the core part of Linux. It is responsible for all
major activities of this operating system. It is consists of various
modules and it interacts directly with the underlying hardware.
Kernel provides the required abstraction to hide low level
hardware details to system or application programs.
 System Library - System libraries are special functions or
programs using which application programs or system utilities
accesses Kernel's features. These libraries implements most of
the functionalities of the operating system and do not requires
kernel module's code access rights.
 System Utility - System Utility programs are responsible to do
specialized, individual level tasks.
Components of Linux System
10/10/2014 suvendu.15292@gmail.com 4

Components of Linux System
10/10/2014 suvendu.15292@gmail.com 5

 User Space
 Kernel Space
 Data Flow Between User Space and Kernel Space
 Architecture
Kernel Architecture Overview
10/10/2014 suvendu.15292@gmail.com 6

 The User Space is the space in memory, where user
processes run.
 This memory is above the Kernel.
 It includes the rest of available memory.
 This Space is protected.
 The system prevents one process from interfering with
another process.
 Only Kernel processes can access a user process
Kernel Architecture Overview..
User Space
10/10/2014 suvendu.15292@gmail.com 7

 The Kernel Space is the space in memory where all
kernel services are provided via kernel processes.
 The user has access to it only through the system
call.
 A user process becomes a kernel process when it
executes a system call.
Kernel Architecture Overview..
Kernel Space
10/10/2014 suvendu.15292@gmail.com 8

 User Space and Kernel Space are in different spaces.
 When a System Call is executed, the arguments to
the call are passed from User Space to Kernel Space.
Kernel Architecture Overview..
System Call
10/10/2014 suvendu.15292@gmail.com 9

Kernel Architecture Overview..
User Space and Kernel Space
Relationship
10/10/2014 suvendu.15292@gmail.com 10

Kernel Architecture Overview..
Architecture
10/10/2014 suvendu.15292@gmail.com 11
10/10/2014 suvendu.15292@gmail.com 12
Address Translation

 Address translations are kept in a special cache
called Translation Look-Aside Buffer or TLB
 TLB must be on chip; its access time is comparable to
cache.
10/10/2014 suvendu.15292@gmail.com 13
Address Translation

10/10/2014 suvendu.15292@gmail.com 14
Address Translation
Typical TLB Format
 Tag: Portion of virtual address
 Data: Physical Page number
 Dirty: since use write back, need to know whether or
not to write page to disk when replaced
 Ref: Used to help calculate LRU on replacement
 Valid: Entry is valid
 Access rights: R (read permission), W (write perm.)

 TLBs usually small, typically 128-256 entries.
 Like any other cache, the TLB can be fully
associative, set associative, or direct mapped.
10/10/2014 suvendu.15292@gmail.com 15
Address Translation
Translation Look_Aside
Buffers

 Assume 32 entries, fully associative TLB
(Alpha AXP 21064)
1: Processor sends the virtual address to all tags
2: If there is a hit (there is an entry in TLB with that
Virtual Page number and valid bit is 1) and there is no
access violation, then
3: Matching tag sends the corresponding Physical Page
number
4: Combine Physical Page number and Page Offset to
get full physical address
10/10/2014 suvendu.15292@gmail.com 16
Address Translation
Translation Look_Aside
Buffers
10/10/2014 suvendu.15292@gmail.com 17
Feature for Multithreading and
Multiprocessing
What is Thread?
 A thread is a flow of execution through the process code, with its
own program counter, system registers and stack.
 A thread is also called a light weight process.
 Threads provide a way to improve application performance
through parallelism. Threads represent a software approach to
improving performance of operating system by reducing the
overhead thread is equivalent to a classical process.
 Each thread belongs to exactly one process and no thread can exist
outside a process.
 Each thread represents a separate flow of control.
 Threads have been successfully used in implementing network
servers and web server.
 They also provide a suitable foundation for parallel execution of
applications on shared memory multiprocessors.
10/10/2014 suvendu.15292@gmail.com 18
Multithreading

10/10/2014 suvendu.15292@gmail.com 19
Multithreading..

10/10/2014 suvendu.15292@gmail.com 20
Multithreading..
Advantages of Thread
 Thread minimize context switching time.
 Use of threads provides concurrency within a
process.
 Efficient communication.
 Economy- It is more economical to create and
context switch threads.
 Utilization of multiprocessor architectures to a
greater scale and efficiency.

10/10/2014 suvendu.15292@gmail.com 21
Multithreading..
Types of Thread
Threads are implemented in following two ways
 User Level Threads -- User managed threads
 Kernel Level Threads -- Operating System managed
threads acting on kernel, an operating system core.

10/10/2014 suvendu.15292@gmail.com 22
Multithreading..
User Level Threads
 In this case, application
manages thread
management kernel is not
aware of the existence of
threads.
 The thread library contains
code for creating and
destroying threads, for
passing message and data
between threads, for
scheduling thread execution
and for saving and restoring
thread contexts.
 The application begins with
a single thread and begins
running in that thread.

10/10/2014 suvendu.15292@gmail.com 23
Multithreading..
ADVANTAGES OF USER LEVEL THREADS:
 Thread switching does not require Kernel mode
privileges.
 User level thread can run on any operating system.
 Scheduling can be application specific in the user level
thread.
 User level threads are fast to create and manage.
DISADVANTAGES OF USER LEVEL THREADS:
 In a typical operating system, most system calls are
blocking.
 Multithreaded application cannot take advantage of
multiprocessing.

10/10/2014 suvendu.15292@gmail.com 24
Multithreading..
Kernel Level Threads
 In this case, thread management done by the Kernel.
 There is no thread management code in the application area.
Kernel threads are supported directly by the operating system.
 Any application can be programmed to be multithreaded. All of
the threads within an application are supported within a single
process.
 The Kernel maintains context information for the process as a
whole and for individuals threads within the process. Scheduling
by the Kernel is done on a thread basis.
 The Kernel performs thread creation, scheduling and
management in Kernel space.
 Kernel threads are generally slower to create and manage than
the user threads.

10/10/2014 suvendu.15292@gmail.com 25
Multithreading..
ADVANTAGES OF KERNEL LEVEL THREADS:
 Kernel can simultaneously schedule multiple threads
from the same process on multiple processes.
 If one thread in a process is blocked, the Kernel can
schedule another thread of the same process.
 Kernel routines themselves can multithreaded.
DISADVANTAGES OF KERNEL LEVEL THREADS:
 Kernel threads are generally slower to create and
manage than the user threads.
 Transfer of control from one thread to another within
same process requires a mode switch to the Kernel.

10/10/2014 suvendu.15292@gmail.com 26
Multithreading..
Multithreading Models:
Multithreading models are three types
 Many to many relationship.
 Many to one relationship.
 One to one relationship.

10/10/2014 suvendu.15292@gmail.com 27
Multithreading..
Many to Many Model
 In this model, many user
level threads multiplexes to
the Kernel thread of smaller
or equal numbers. The
number of Kernel threads
may be specific to either a
particular application or a
particular machine.
 Following diagram shows the
many to many model. In this
model, developers can create
as many user threads as
necessary and the
corresponding Kernel threads
can run in parallels on a
multiprocessor.

10/10/2014 suvendu.15292@gmail.com 28
Multithreading..
Many to One Model
 Many to one model maps many
user level threads to one Kernel
level thread. Thread management
is done in user space. When
thread makes a blocking system
call, the entire process will be
blocks. Only one thread can
access the Kernel at a time , so
multiple threads are unable to
run in parallel on
multiprocessors.
 If the user level thread libraries
are implemented in the operating
system in such a way that system
does not support them then
Kernel threads use the many to
one relationship modes.

10/10/2014 suvendu.15292@gmail.com 29
Multithreading..
One to One Model
 There is one to one relationship of
user level thread to the kernel
level thread. This model provides
more concurrency than the many
to one model. It also another
thread to run when a thread
makes a blocking system call. It
support multiple thread to
execute in parallel on
microprocessors.
 Disadvantage of this model is
that creating user thread requires
the corresponding Kernel thread.
OS/2, windows NT and
windows 2000 use one to one
relationship model.

10/10/2014 suvendu.15292@gmail.com 30
Multiprocessing
 Multiprocessing is the use of two or more central
processing units (CPUs) within a single computer
system. The term also refers to the ability of a
system to support more than one processor
and/or the ability to allocate tasks between them.
 According to some on-line dictionaries,
a multiprocessor is a computer system having
two or more processing units (multiple
processors) each sharing main memory and
peripherals, in order to simultaneously process
programs

 http://www.tutorialspoint.com/operating_system/
os_linux.htm
 http://www.makelinux.net/ldd3/chp-8-sect-2
 http://www.linux-
tutorial.info/modules.php?name=MContent&pageid
=327
Reference
10/10/2014 suvendu.15292@gmail.com 31
10/10/2014 suvendu.15292@gmail.com 32

Linux Memory Management

  • 1.
  • 2.
      Memory Structureof Linux OS.  How Program is loaded into the memory.  Address Translation.  Feature for Multithreading and Multiprocessing. Overview 10/10/2014 suvendu.15292@gmail.com 2
  • 3.
      Linux isone of popular version of UNIX operating System.  It is open source as its source code is freely available.  It is free to use. Linux was designed considering UNIX compatibility.  It's functionality list is quite similar to that of UNIX. Linux OS 10/10/2014 suvendu.15292@gmail.com 3
  • 4.
     Linux Operating Systemhas primarily three components  Kernel - Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It is consists of various modules and it interacts directly with the underlying hardware. Kernel provides the required abstraction to hide low level hardware details to system or application programs.  System Library - System libraries are special functions or programs using which application programs or system utilities accesses Kernel's features. These libraries implements most of the functionalities of the operating system and do not requires kernel module's code access rights.  System Utility - System Utility programs are responsible to do specialized, individual level tasks. Components of Linux System 10/10/2014 suvendu.15292@gmail.com 4
  • 5.
     Components of LinuxSystem 10/10/2014 suvendu.15292@gmail.com 5
  • 6.
      User Space Kernel Space  Data Flow Between User Space and Kernel Space  Architecture Kernel Architecture Overview 10/10/2014 suvendu.15292@gmail.com 6
  • 7.
      The UserSpace is the space in memory, where user processes run.  This memory is above the Kernel.  It includes the rest of available memory.  This Space is protected.  The system prevents one process from interfering with another process.  Only Kernel processes can access a user process Kernel Architecture Overview.. User Space 10/10/2014 suvendu.15292@gmail.com 7
  • 8.
      The KernelSpace is the space in memory where all kernel services are provided via kernel processes.  The user has access to it only through the system call.  A user process becomes a kernel process when it executes a system call. Kernel Architecture Overview.. Kernel Space 10/10/2014 suvendu.15292@gmail.com 8
  • 9.
      User Spaceand Kernel Space are in different spaces.  When a System Call is executed, the arguments to the call are passed from User Space to Kernel Space. Kernel Architecture Overview.. System Call 10/10/2014 suvendu.15292@gmail.com 9
  • 10.
     Kernel Architecture Overview.. UserSpace and Kernel Space Relationship 10/10/2014 suvendu.15292@gmail.com 10
  • 11.
  • 12.
  • 13.
      Address translationsare kept in a special cache called Translation Look-Aside Buffer or TLB  TLB must be on chip; its access time is comparable to cache. 10/10/2014 suvendu.15292@gmail.com 13 Address Translation
  • 14.
     10/10/2014 suvendu.15292@gmail.com 14 AddressTranslation Typical TLB Format  Tag: Portion of virtual address  Data: Physical Page number  Dirty: since use write back, need to know whether or not to write page to disk when replaced  Ref: Used to help calculate LRU on replacement  Valid: Entry is valid  Access rights: R (read permission), W (write perm.)
  • 15.
      TLBs usuallysmall, typically 128-256 entries.  Like any other cache, the TLB can be fully associative, set associative, or direct mapped. 10/10/2014 suvendu.15292@gmail.com 15 Address Translation Translation Look_Aside Buffers
  • 16.
      Assume 32entries, fully associative TLB (Alpha AXP 21064) 1: Processor sends the virtual address to all tags 2: If there is a hit (there is an entry in TLB with that Virtual Page number and valid bit is 1) and there is no access violation, then 3: Matching tag sends the corresponding Physical Page number 4: Combine Physical Page number and Page Offset to get full physical address 10/10/2014 suvendu.15292@gmail.com 16 Address Translation Translation Look_Aside Buffers
  • 17.
    10/10/2014 suvendu.15292@gmail.com 17 Featurefor Multithreading and Multiprocessing
  • 18.
    What is Thread? A thread is a flow of execution through the process code, with its own program counter, system registers and stack.  A thread is also called a light weight process.  Threads provide a way to improve application performance through parallelism. Threads represent a software approach to improving performance of operating system by reducing the overhead thread is equivalent to a classical process.  Each thread belongs to exactly one process and no thread can exist outside a process.  Each thread represents a separate flow of control.  Threads have been successfully used in implementing network servers and web server.  They also provide a suitable foundation for parallel execution of applications on shared memory multiprocessors. 10/10/2014 suvendu.15292@gmail.com 18 Multithreading
  • 19.
  • 20.
     10/10/2014 suvendu.15292@gmail.com 20 Multithreading.. Advantagesof Thread  Thread minimize context switching time.  Use of threads provides concurrency within a process.  Efficient communication.  Economy- It is more economical to create and context switch threads.  Utilization of multiprocessor architectures to a greater scale and efficiency.
  • 21.
     10/10/2014 suvendu.15292@gmail.com 21 Multithreading.. Typesof Thread Threads are implemented in following two ways  User Level Threads -- User managed threads  Kernel Level Threads -- Operating System managed threads acting on kernel, an operating system core.
  • 22.
     10/10/2014 suvendu.15292@gmail.com 22 Multithreading.. UserLevel Threads  In this case, application manages thread management kernel is not aware of the existence of threads.  The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread contexts.  The application begins with a single thread and begins running in that thread.
  • 23.
     10/10/2014 suvendu.15292@gmail.com 23 Multithreading.. ADVANTAGESOF USER LEVEL THREADS:  Thread switching does not require Kernel mode privileges.  User level thread can run on any operating system.  Scheduling can be application specific in the user level thread.  User level threads are fast to create and manage. DISADVANTAGES OF USER LEVEL THREADS:  In a typical operating system, most system calls are blocking.  Multithreaded application cannot take advantage of multiprocessing.
  • 24.
     10/10/2014 suvendu.15292@gmail.com 24 Multithreading.. KernelLevel Threads  In this case, thread management done by the Kernel.  There is no thread management code in the application area. Kernel threads are supported directly by the operating system.  Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process.  The Kernel maintains context information for the process as a whole and for individuals threads within the process. Scheduling by the Kernel is done on a thread basis.  The Kernel performs thread creation, scheduling and management in Kernel space.  Kernel threads are generally slower to create and manage than the user threads.
  • 25.
     10/10/2014 suvendu.15292@gmail.com 25 Multithreading.. ADVANTAGESOF KERNEL LEVEL THREADS:  Kernel can simultaneously schedule multiple threads from the same process on multiple processes.  If one thread in a process is blocked, the Kernel can schedule another thread of the same process.  Kernel routines themselves can multithreaded. DISADVANTAGES OF KERNEL LEVEL THREADS:  Kernel threads are generally slower to create and manage than the user threads.  Transfer of control from one thread to another within same process requires a mode switch to the Kernel.
  • 26.
     10/10/2014 suvendu.15292@gmail.com 26 Multithreading.. MultithreadingModels: Multithreading models are three types  Many to many relationship.  Many to one relationship.  One to one relationship.
  • 27.
     10/10/2014 suvendu.15292@gmail.com 27 Multithreading.. Manyto Many Model  In this model, many user level threads multiplexes to the Kernel thread of smaller or equal numbers. The number of Kernel threads may be specific to either a particular application or a particular machine.  Following diagram shows the many to many model. In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallels on a multiprocessor.
  • 28.
     10/10/2014 suvendu.15292@gmail.com 28 Multithreading.. Manyto One Model  Many to one model maps many user level threads to one Kernel level thread. Thread management is done in user space. When thread makes a blocking system call, the entire process will be blocks. Only one thread can access the Kernel at a time , so multiple threads are unable to run in parallel on multiprocessors.  If the user level thread libraries are implemented in the operating system in such a way that system does not support them then Kernel threads use the many to one relationship modes.
  • 29.
     10/10/2014 suvendu.15292@gmail.com 29 Multithreading.. Oneto One Model  There is one to one relationship of user level thread to the kernel level thread. This model provides more concurrency than the many to one model. It also another thread to run when a thread makes a blocking system call. It support multiple thread to execute in parallel on microprocessors.  Disadvantage of this model is that creating user thread requires the corresponding Kernel thread. OS/2, windows NT and windows 2000 use one to one relationship model.
  • 30.
     10/10/2014 suvendu.15292@gmail.com 30 Multiprocessing Multiprocessing is the use of two or more central processing units (CPUs) within a single computer system. The term also refers to the ability of a system to support more than one processor and/or the ability to allocate tasks between them.  According to some on-line dictionaries, a multiprocessor is a computer system having two or more processing units (multiple processors) each sharing main memory and peripherals, in order to simultaneously process programs
  • 31.
      http://www.tutorialspoint.com/operating_system/ os_linux.htm  http://www.makelinux.net/ldd3/chp-8-sect-2 http://www.linux- tutorial.info/modules.php?name=MContent&pageid =327 Reference 10/10/2014 suvendu.15292@gmail.com 31
  • 32.