Os solaris memory management

35
MEMORY MANAGEMENT 06/06/2022 1

description

 

Transcript of Os solaris memory management

Page 1: Os  solaris memory management

04/08/2023 1

MEMORY MANAGEMENT

Page 2: Os  solaris memory management

04/08/2023 2

Agenda

Introduction to SolarisHistory of solarisSolaris memory architecture. Backing store VM system.Solaris memory management. Swapping Demand paging.

Page 3: Os  solaris memory management

04/08/2023 3

Introduction to solaris

Solaris is a Unix operating system originally developed by Sun Microsystems.

Solaris is known for its scalability especially on SPARC systems and for originating many innovative features such as DTrace, ZFS and Time Slider.

Solaris supports SPARC-based and x-86 based workstation and servers from Sun and other vendors.

Solaris has a reputation for being well-suited to symmetric multiprocessing, supporting a large number of CPUs.

Programmed in C. Its source model is Mixed open source/closed

source.

Page 4: Os  solaris memory management

04/08/2023 4

History of solaris

In earlier days SunOS is implemented in uniprocessor workstation.

In 1980’s distributed and network-based computing became popular, so they went to multiprocessor system to speedup.

In 1987, AT&T bell and Sun joined together for a project and developed a new OS by merging the existing OS.(SunOS,BSD,SVR3,Xenix).

That new OS is named as System V Release 4 (SVR4) and then its name changed as Solaris 2.

Latest version is Solaris 11.

Page 5: Os  solaris memory management

04/08/2023 5

Solaris Memory Architecture

Physical memory is divided into fixed-sized pieces called pages.

The size of the page varies from platform to platform.

The common size is 8 Kbytes.Each page is associated with a file and

offset.The file and offset identify the backing store

for the page.

Page 6: Os  solaris memory management

04/08/2023 6

Backing storeBacking store is the location to which the

physical page contents will be migrated when that page is need to be taken for another process.

The pages are migrated to slower medium like disk and that is called swap space.

The location where the pages are migrated is called page-out.

When again that pages are needed by the process, the location from which the pages are read back again is called page-in.

Page 7: Os  solaris memory management

04/08/2023 7

Virtual memory System

Virtual memory system is the core for a Solaris system.

Why have a Virtual memory System?

It presents simple memory programming model.

It allows process to see linear range of bytes, regardless of fragmentation of the real memory.

It gives programming model with a larger size than available physical storage.

Page 8: Os  solaris memory management

04/08/2023 8

Jobs of VM System

The job of VM system is to keep the most frequently referenced portions of memory in primary storage.

When RAM shortage comes, VM is required to free the RAM by transfering infrequently used memory out to the backing store.

By doing so,the VM system optimizes the performance.

VM system supports multiple users and sharing of pages and thus provide protection.

Page 9: Os  solaris memory management

04/08/2023 9

Process Memory Allocation

A process will have a linear virtual address space.

The linear Virtual address space of a process is divided into segments like

Executable-text : Executable instructions in binary form

Executable-Data : Initialized variables in the executable

Heap space : Memory allocated by malloc()

Process Stack and so on……

Page 10: Os  solaris memory management

04/08/2023 10

Process memory allocation

Page 11: Os  solaris memory management

04/08/2023 11

Solaris virtual to physical memory management

Page 12: Os  solaris memory management

04/08/2023 12

Virtual memory management unit(MMU)

Solaris kernel breaks the process into segments and segments into pages.

The hardware MMU maps those pages into physical memory by using a platform-specific set of translation tables.

Each entry in the table has the physical address of the page of the RAM,so that memory access can be converted on-the-fly in hardware.

Page 13: Os  solaris memory management

04/08/2023 13

Shared Mapped File

Page 14: Os  solaris memory management

04/08/2023 14

Solaris Memory Management

Two basic types of memory management manage the allocation and migration of physical pages of memory to and from swap space :

The VM system uses a global paging model that implements a single global policy to manage the allocation of memory between the processes.

1.Swapping

2.Demand paging

Page 15: Os  solaris memory management

04/08/2023 15

Swapping

The swapping algorithm uses user process as the granularity for managing memory.

If there is a shortage of memory, then all the pages of the least active process will be swapped out to the swap device, freeing memory for other processes.

Then the corresponding flag in the process table is set to indicate that this process has been swapped out.

Page 16: Os  solaris memory management

04/08/2023 16

Memory Scheduler

The memory scheduler is launched at boot time and does nothing.

If the memory is consistently less, it starts looking for processes that it can completely swap out.

If shortage is minimal, then soft swap takes place.

Otherwise hard-swap.

Page 17: Os  solaris memory management

04/08/2023 17

Soft Swapping

If the process have been inactive for atleast maxslp(default 20 seconds) seconds, then memory sceduler swaps out all the pages for that process.

Page 18: Os  solaris memory management

04/08/2023 18

Hard Swapping

Hard swapping takes place when all of the following are true :

Atleast two processes are on the run queue, waiting for CPU.

The average free memory over 30 seconds is consistently less than minimum.

Excessive paging (page-out + page-in is high).

Page 19: Os  solaris memory management

04/08/2023 19

Pros and Cons of Swapping

Pros: 1.This is the inexpensive way to conserve

memory. 2. Easy implementation.

Cons: 1. It dramatically affects a process’s

performance.

So the swapping is used only as a last resort when the system is desperate for memory.

Page 20: Os  solaris memory management

04/08/2023 20

Demand paging

The Demand paging model uses a page as the granularity for memory management.

Pages of memory are allocated on demand.

When memory is first referenced, a page fault occurs and memory is allocated one page at a time.

The page scanner and the virtual memory page fault mechanism are the core of the demand paged memory management.

Page 21: Os  solaris memory management

04/08/2023 21

Page ScannerThe page scanner is a kernel thread, which is

awakened when the amount of memory on the free-page list falls below a system threshhold, typically 1/64 th of total physical memory.

Scanner (pageout_scanner) tracks pages by reading the state of the hardware bits in MMU

– MMU bits maintain state of referenced and written

(dirty). – Uses a twohanded clock algorithm to

determine eviction.

Page 22: Os  solaris memory management

04/08/2023 22

Two Handed Clock Algorithm

Both hands rotate clock-wise.The front hand clears the referenced and

modified bit of each page.The trailing back hand then inspects the

referenced and modified bits some time later.

Page 23: Os  solaris memory management

04/08/2023 23

Scan RateThe scan rate changes during the course of

the page scanners operation Scanners scans at slowscan when

memory is below lotsfree and then increases to fastscan when memory has fallen below minfree threshold

Slowscan is set to 100 pages by default.

Fastscan is set to physicalmemory/2 capped at 8192 pages

Page 24: Os  solaris memory management

04/08/2023 24

Page Faults

When do Page Faults occur? MMU-generated exceptions (trap) tell the

operating system when a memory access cannot continue without the kernel’s intervention.

Three major types of memory-related hardware exceptions can occur:

Major page faults Minor page faults Protection faults

Page 25: Os  solaris memory management

04/08/2023 25

Advantages of Demand paging

Loading pages of memory on demand dramatically lowers the memory footprintMemory footprint refers to the amount of main

memory that a program uses or references while running.

And startup time of the process.

Page 26: Os  solaris memory management

04/08/2023 26

Memory sharing

Multiple users’ processes can share memory

Multiple processes can sharing program binaries and application data.

The Solaris kernel introduced dynamically linked libraries.

Page 27: Os  solaris memory management

04/08/2023 27

Memory protection

A user’s process must not be able access the memory of another process.

A program fault in one program could cause another program (or the entire operating system) to fail.

The protection is implemented by using protection modes read, write, execute and boundary checking.

Page 28: Os  solaris memory management

04/08/2023 28

Kernel Virtual Memory Layout

The kernel uses virtual memory and MMU like the process.

The kernel uses top 256 Mbytes or 512 Mbytes in common virtual address space.

Most of the kernel memory are not pageable.This characteristics avoids the deadlocks.The kernel cannot rely on the global paging.

Page 29: Os  solaris memory management

04/08/2023 29

Kernel Memory AllocationKernel memory is allocated at different

levels.

Page allocator It allocates unmapped pages from the

free list to the kernel address space. Solaris uses Resource map allocator to

allocate the free memory to the kernel. Resource map allocator uses first-fit

algorithm.

Page 30: Os  solaris memory management

04/08/2023 30

Kernel Memory Slab Allocator

Solaris provides a general-purpose memory allocator that provides arbitrarily sized memory allocations.

We use the slab allocator for memory requests that are:

Smaller than a page size Not an even multiple of a page size Frequently going to be allocated and freed,

so would otherwise fragment the kernel map

Page 31: Os  solaris memory management

04/08/2023 31

Why Slab Allocator?The reasons for introducing the slab allocator

were as follows:

The SVR4 allocator was slow to satisfy allocation requests.

Significant fragmentation problems arose with use of the SVR4 allocator.

The allocator footprint was large, wasting a lot of memory.

With no clean interfaces for memory allocation, code was duplicated in many places.

Page 32: Os  solaris memory management

04/08/2023 32

Page 33: Os  solaris memory management

04/08/2023 33

The slab allocator uses the term object to describe a single memory allocation unit.

Cache to refer to a pool of like objects.Slab to refer to a group of objects that

reside within the cache. Slab allocator solves many of the

fragmentation issues by grouping different sized memory objects.

Many cache will be activate at once in the solaris kernel.

Page 34: Os  solaris memory management

04/08/2023 34

References

Book: SOLARIS Internals,Core Kernel

Architecture,Sun Microsystems.Website:

www.sun.com

Page 35: Os  solaris memory management

04/08/2023 35

THANK YOU….