CS 111 Spring 2014

Lecture 10: File System Performance (With More on Deadlocks)

by Kevin Sheu and Zeeshan Pirzada

Table of Contents

  1. More on Deadlock
  2. Quasi-Deadlock
    1. Priority Inversion
    2. Receive Livelock
  3. Event Driven Programming
  4. Hardware Lock Elision (HLE)
  5. File System Performance Ideas
  6. Performace Metrics for File Systems

More on Deadlock

Deadlock has 4 conditions:
  1. Circular Wait - processes are waiting for resources held by other processes, which are waiting for other resources
  2. Mutual Exclustion - holding a resources excludes other processes from getting that resource
  3. No Pre-emption - processes do not have the ability to take resources from others if they have it
  4. Hold & Wait - processes are holding one resource while waiting for another

Solution: In order to avoid deadlock, you would need to design a system without one of these things.

To avoid deadlocking, we would need to look for cycles on each wait operation, such as the one shown above. Then, we would not allow a process to acquire another resource.

The cost for checking for this type of deadlock with a for loop with P processes and R resources would have time completxity of O(PR). However, this is a naive implementation, and we would obviosly prefer a solution with a significantly lower order, ideally O(1). Another solution for this would be lock ordering:

Quasi-Deadlock


Priority Inversion


Recieve Livelock

Below is a graph showing the typical trends for receiving requests:

Here is a scenario to explain the awful curve:

Problem: The CPU is doing two things:
  1. The interrupt service routine grabs data and puts the data into the bounded buffer.
  2. Computations occur during the work routine

However, too many requests are coming in, so the CPU becomes swamped because the interrupt service routine has a higher priority.

Soution:

Event-Driven Programming

Data Races are Evil: Alternative Solution: just use one thread Example:

	0	while (true) {
	1		wait_for_event(e);
	2		e->handler;
	3	}
			
Positive (+) Negative (-)

Hardware Lock Elision

Example Code:

	0	lock:
	1		movl     $1, %eax
	2	try:
	3		xacquire lock xchgl %eax, lockvar
	4		cmp      $0, %eax
	5		jnz      try
	6		ret
	7	unlock:
	8		xrelease movl $0, lockvar
	9		ret
			

File System Performance Ideas

Below are some ideas that can be used to enhance a file system's performance:

Striping


Assign a piece of file on to each disk, so we can read in parallel

Distributed Metadata

Efficient Directory Indexing

Partition Awareness

File System Staying Live During Maintenence

Performance Metrics For File Systems

Performance metrics:
  1. Latency - delay from request to response
  2. Throughput - rate of request completions
  3. Utilizations - function of capacity doing useful work (CPU, bus bandwidth)
Example: Assume a system with these characteristics: Basic busy wait + polling approach for reading:

		for(;;) { 
	0       char buf[40];
	1       read 40 bytes from SSD to buf;
	2       compute(buf+i*40);
	3   }
			
Latency: (microseconds)
Sending command to SSD 5
SSD latency 50
Read latency 40
Computation 5
Total 100

Below are different ideas for speedup:

Batching

Basic Idea: grabbing bigger blocks of data (bigger buffer)

	0   for (;;) {
	1       char buf[840];
	2       read 840 bytes from SSD into buf;
	3       for (i=0; i<21; i++)
	4           compute(buf+i*40);
	5   }
			
Latency:
Sending to SSD 5
SSD latency 50
Read latency 21 * 40 = 840
Computation 21 * 5 = 105
Total 1000

Interrupts


	0   for (;;) {
	1       block_until_interrupt;
	2       do
	3           handle_interrupt;
	4       while (!ready)
	5   }
			
Latency:
Send to SSD 5
Blocking 50
Handling 5
Read latency 40
Computation 5
Total 106

DMA (Direct Memory Access)


	0   while(1) {
	1       write command to disk;
	2       block until interrupt;
	3       check disk if ready;
	4       compute;
	5   }
			
Latency:
Blocking 50
Handling 5
Checking if ready 1
Computation 5
Total 61
However, we can give up on interupts and just use the polling approach.

DMA + Polling


	0   while(1) {
	1       write command to disk;
	2       while (DMA slots are not ready)
	3           schedule;
	4       check disk if ready;
	5       compute;
	6   }
			
Latency:
Blocking (scheduling) 50
Checking if ready 1
Computation 5
Total 56
We can see that the utilization rate is extremely high for DMA with polling. Consquently, this is one of the more popular methods!



Valid HTML 4.01 Transitional