CIS191

Linux Administration

Welcome

  • Start Zoom
  • Sign In

Resources

Programs access resources

by requesting them from the

operating system.

Programs need memory, CPU time and

file descriptors to perform I/O.

Memory

Programs use memory for instructions and data.

You can see the layout of a program’s memory in:

/proc/<PID>/maps

The ps command will show you values too.

Memory and ps

The ps command has a few useful ways to show a program’s memory.

Resident Set Size (RSS) is the non-swapped memory that the program is using.

Virtual Memory Size (VSZ) is the total memory requested by a program (including shared memory) this will always be >= RSS

Percent Memory (%mem) is the RSS as a percent of the machine’s RAM. It’s useful for finding programs using a lot of memory.

CPU and ps

The ps command shows you the status of a program.

State shows you if the program is runnable or waiting (or a zombie!)

Run time is the total amount of time the program has spent running on a CPU.

%CPU is the run time divided by the total time a program has been running.

File Descriptors

Programs perform input and output (I/O).

Examples of I/O are; reading and writing files,

using a pipe or fifo to communicate

with another program,

using a socket to communicate over the network.

FDs for Apache

The Apache web server has interesting FDs.

$ sudo ls -la /proc/1451/fd

total 0

dr-x------ 2 root root 0 Nov 2 14:26 .

dr-xr-xr-x 9 root root 0 Nov 2 14:26 ..

lr-x------ 1 root root 64 Nov 2 14:26 0 -> /dev/null

l-wx------ 1 root root 64 Nov 2 14:26 1 -> /dev/null

l-wx------ 1 root root 64 Nov 2 14:26 2 -> /var/log/apache2/error.log

lrwx------ 1 root root 64 Nov 2 14:26 3 -> socket:[15992]

lrwx------ 1 root root 64 Nov 2 14:26 4 -> socket:[15993]

lr-x------ 1 root root 64 Nov 2 14:26 5 -> pipe:[859447]

l-wx------ 1 root root 64 Nov 2 14:26 6 -> pipe:[859447]

l-wx------ 1 root root 64 Nov 2 14:26 7 -> /var/log/apache2/other_vhosts_access.log

l-wx------ 1 root root 64 Nov 2 14:26 8 -> /var/log/apache2/access.log

E Pluribus Unum**

So far we’ve studied how to see the resources used by

individual processes

Today we’ll look at how they all

add up into system-wide resource usage.

**Out of many, one.

Resources

And the whole system.

Understanding Memory

Physical memory (RAM) is divided

into pages

for the purposes of management.

Pages are assigned to processes as needed and become

virtual memory.

Processes and Memory

When processes

first start they begin to use pages.

Those pages are allocated into RAM as needed.

A

B

kernel

Main Memory

A

Process A

B

Process B

Processes and Memory

As programs execute

they allocate new

pages

as needed.

The demand is served by free pages in memory.

A

B

kernel

Main Memory

A

Process A

B

Process B

A

A

Processes and Memory

As programs execute

they allocate new

pages

as needed.

The demand is served by free pages in memory.

A

B

kernel

Main Memory

A

Process A

B

Process B

A

A

A

A

Processes and Memory

As programs execute

they allocate new

pages

as needed.

The demand is served by free pages in memory.

A

B

kernel

Main Memory

A

Process A

B

Process B

A

A

A

A

B

B

B

B

Processes and Memory

As programs execute

they allocate new

pages

as needed.

The demand is served by free pages in memory.

A

B

kernel

Main Memory

A

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

B

B

Processes and Memory

When all pages

have been allocated

memory is full.

A program that tries to allocate a page will crash.

A

B

kernel

Main Memory

A

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

B

B

A

A

Swap

Linux allocates space on disk for pages

called swap space.

Swap is used when the system is

running low on memory.

Swap Limitations

Programs cannot use a page that is on disk.

When they try to a

page fault occurs.

Linux handles the page fault by bringing the page back into memory (possibly evicting some other page).

Swap Out

Process B

attempts to allocate new memory.

More space must be made by a

swap out.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

A

Swap Space

A

Swap Out

Process B

attempts to allocate new memory.

More space must be made by a

swap out.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

A

Swap Space

A

Swap Out

Process B

attempts to allocate new memory.

More space must be made by a

swap out.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

A

Swap Space

A

B

B

Swap Out

Process B

attempts to allocate

more

new memory.

No pages are safe,

process B may cause the swap out of its own pages.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

B

A

A

A

Swap Space

A

B

B

Swap Out

Process B

attempts to allocate

more

new memory.

No pages are safe,

process B may cause the swap out of its own pages.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

A

A

A

Swap Space

A

B

B

B

Swap Out

Process B

attempts to allocate

more

new memory.

No pages are safe,

process B may cause the swap out of its own pages.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

A

A

A

Swap Space

A

B

B

B

B

B

Page Faults

When a page fault occurs the

process is put into the wait state

until

a swap in can happen.

Swap In

Process B

attempts to use

memory that is on disk.

A

swap in

must occur.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

B

A

A

Swap Space

A

B

B

B

B

B

Swap In

Process B

attempts to use

memory that is on disk.

A

swap in

must occur.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

A

A

Swap Space

A

B

B

B

B

B

B

Thrashing

Swap works when the demand for memory is

only a little more than the supply

or

when the high demand is temporary.

Otherwise a condition called thrashing happens. And it’s bad...

Thrashing

Process B

needs to swap in.

That evicts pages from

Process A

B

kernel

Main Memory

Process A

B

Process B

A

A

A

A

B

B

B

A

A

A

Swap Space

A

B

B

B

B

A

A

B

Thrashing

Process B

needs to swap in.

That evicts pages from

Process A

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

B

Swap Space

A

B

B

B

B

A

A

B

A

A

A

A

Thrashing

Process B

needs to swap in.

Now there’s room

to

swap in pages.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

B

Swap Space

A

B

B

B

B

A

A

B

A

A

A

A

Thrashing

Process B

needs to swap in.

Now there’s room

to

swap in pages.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

Swap Space

A

B

B

A

A

A

A

A

A

B

B

B

B

Thrashing

But now process A has almost no pages in memory.

When it becomes runnable

it will evict pages from process B

This becomes a

viscous cycle.

B

kernel

Main Memory

Process A

B

Process B

A

A

A

B

B

Swap Space

A

B

B

A

A

A

A

A

A

B

B

B

B

Symptoms of Thrashing

Reading and writing disk is very slow compared to memory. Particularly for spinning disks...

When the system is thrashing

everything slows down and the disk access light is steady on.

CIS 191 - Week 10 - System Monitoring and Logging - Google Slides