the design of a flash-based linux swap system

26
The Design of a Flash-based Linux Swap System Yeonseung Ryu Myongji University October, 2008

Upload: others

Post on 12-Sep-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Design of a Flash-based Linux Swap System

The Design of a Flash-based Linux Swap System

Yeonseung RyuMyongji University

October, 2008

Page 2: The Design of a Flash-based Linux Swap System

Contents

o Overview of linux Swap Systemn How does the swap system operates?n What are the problems of flash based swap system?

o New Swap Systemn Segment-based swap space management and fast start-upn Block-aligned read-ahead swap-in schemen Performance evaluation

2

o Overview of linux Swap Systemn How does the swap system operates?n What are the problems of flash based swap system?

o New Swap Systemn Segment-based swap space management and fast start-upn Block-aligned read-ahead swap-in schemen Performance evaluation

Page 3: The Design of a Flash-based Linux Swap System

Introduction

o All modern general-purpose OS use virtual memory techniques. Most of virtual memory implementations divide the virtual address space of an application program into pages; Page size is usually 4KB in linux.

o When an application executes, its contents (code and data) are loadedon demand into page frames of main memory.

o The stack and heap of the process are created in the main memory ondemand.

o All modern general-purpose OS use virtual memory techniques. Most of virtual memory implementations divide the virtual address space of an application program into pages; Page size is usually 4KB in linux.

o When an application executes, its contents (code and data) are loadedon demand into page frames of main memory.

o The stack and heap of the process are created in the main memory ondemand.

3

Page 4: The Design of a Flash-based Linux Swap System

Introduction

o When the free memory is almost used up, the Linux kernel performs page frame reclaiming. Page frame reclaiming procedure picks up victim page frames and makes them free.

o If a victim page frame is mapped to a portion of a disk file and the page is dirty, the kernel writes the content of the page frame to the corresponding disk file.

o If a victim page frame is not mapped to a disk file like stack and heap (it is called as anonymous pages), the kernel saves the page contents in a dedicated disk partition (or a disk file) called swap area.

o When the free memory is almost used up, the Linux kernel performs page frame reclaiming. Page frame reclaiming procedure picks up victim page frames and makes them free.

o If a victim page frame is mapped to a portion of a disk file and the page is dirty, the kernel writes the content of the page frame to the corresponding disk file.

o If a victim page frame is not mapped to a disk file like stack and heap (it is called as anonymous pages), the kernel saves the page contents in a dedicated disk partition (or a disk file) called swap area.

4

Page 5: The Design of a Flash-based Linux Swap System

Linux Swap System

Swap Area(file or

partition)

taskpage table

pte

RAM

swap out swap in

invalidslot

pgd

5

o A swap area consists of a sequence of swap slots: 4KB blocks used to contain a swapped-out page.

o When an anonymous page is selected for page reclamation, it is swapped out to the swap area.

o Swap-in operation occurs when a process attempts to address a page that has been swapped out.

o When a page is swapped-in from swap area to main memory, we call its slot invalid slot.

Swap Area(file or

partition)invalidslot Swap slot

Page 6: The Design of a Flash-based Linux Swap System

Swap-out

o Linux swap system has been optimized to reduce disk seek time.

o In order to minimize disk seek time, the kernel tries to store swap-out pages in contiguous slots and thus allocates slots from the last allocated slot.

o This simple approach, however, can increase the average seek time during swap-in operations because many occupied swap slots may be scattered far away from one another.

o Linux swap system has been optimized to reduce disk seek time.

o In order to minimize disk seek time, the kernel tries to store swap-out pages in contiguous slots and thus allocates slots from the last allocated slot.

o This simple approach, however, can increase the average seek time during swap-in operations because many occupied swap slots may be scattered far away from one another.

6

Page 7: The Design of a Flash-based Linux Swap System

Swap-out

o In order to address this problem linux kernel restarts allocation from the beginning of the swap area whenever 256 free slots were alloca-ted after the last restart from the beginning of the swap area.

o So, kernel uses slots again that became free due to swap-in requests.

o However, when flash memory is used as swap device, reusing thesefree slots requires erase operations.

o Moreover, since flash memory does not require seek operation, kerneldoes not need to restart allocation from the beginning of the swaparea.

7

o In order to address this problem linux kernel restarts allocation from the beginning of the swap area whenever 256 free slots were alloca-ted after the last restart from the beginning of the swap area.

o So, kernel uses slots again that became free due to swap-in requests.

Page 8: The Design of a Flash-based Linux Swap System

Swap-in

o A swap-in operation tries to read contiguous eight pages including the requested one. Why read-ahead ?n Locality property : neighbor pages tend to be accessed soon.n Seek time: some consecutive pages are read at a time.

o When flash memory is used as swap device, however, swap-in operation with read-ahead can invalidate the swap slots that lie over two erase blocks.

o In order to reuse these eight slots to store swapped-out pages, we need two block erase operations.

o A swap-in operation tries to read contiguous eight pages including the requested one. Why read-ahead ?n Locality property : neighbor pages tend to be accessed soon.n Seek time: some consecutive pages are read at a time.

o When flash memory is used as swap device, however, swap-in operation with read-ahead can invalidate the swap slots that lie over two erase blocks.

o In order to reuse these eight slots to store swapped-out pages, we need two block erase operations.

8

Linux swap-in

Page 9: The Design of a Flash-based Linux Swap System

New swap system

o Considerations

n Fast start-up

n Minimizing garbage collection cost

n Wear-leveling

o Considerations

n Fast start-up

n Minimizing garbage collection cost

n Wear-leveling

9

Page 10: The Design of a Flash-based Linux Swap System

fast start-up ?

o When the system is booted, kernel needs to clean entire swap space since the previous data in the swap area are obsolete.

o This cleaning operation makes system start-up time longer..

o Worst cleaning time vs. swap area size

block size: 128KBblock erase time: 1.5ms

10

0

5000

10000

15000

20000

25000

30000

512M 1G 1.5G 2G

eras

e time

(ms)

swap area size

block size: 128KBblock erase time: 1.5ms

25 seconds

Page 11: The Design of a Flash-based Linux Swap System

Swap space management

o Patent: Segment based swap space management, October, 2008n Swap space is divided into segments.

,

Swap area (Flash memory)

11

slot

erase block

segment

,

Page 12: The Design of a Flash-based Linux Swap System

Segment-based swap space management

o Each segment consists of a set of erase blocks.o Each segment has a segment header which contains segment status

(used/free) and erasure counter.

o A segment is an unit of erase. That is, all the blocks in a segment are erased together at a time.

o When the segment is erased, segment status becomes free and erasure counter is increased by 1.

o Each segment consists of a set of erase blocks.o Each segment has a segment header which contains segment status

(used/free) and erasure counter.

o A segment is an unit of erase. That is, all the blocks in a segment are erased together at a time.

o When the segment is erased, segment status becomes free and erasure counter is increased by 1.

12

Page 13: The Design of a Flash-based Linux Swap System

Segment-based swap space management

o During the start-up, kernel scans all segment headers and constructs data structure about segments in the RAM .

o After constructing segment data structure, kernel determines the number of segments which must be erased by start-up procedure.n If there is a given limit of start-up time, start-up procedure can

clean only a few segments.n Length of start-up time vs. amount of free swap space

o If the kernel does not clean all invalid segments, remaining invalid segments will be erased by garbage collection process afterwards.

o This space management scheme can limit start-up time.

o During the start-up, kernel scans all segment headers and constructs data structure about segments in the RAM .

o After constructing segment data structure, kernel determines the number of segments which must be erased by start-up procedure.n If there is a given limit of start-up time, start-up procedure can

clean only a few segments.n Length of start-up time vs. amount of free swap space

o If the kernel does not clean all invalid segments, remaining invalid segments will be erased by garbage collection process afterwards.

o This space management scheme can limit start-up time.

13

Page 14: The Design of a Flash-based Linux Swap System

Segment-based swap space management

o We are studying ...n Segment sizen Start-up time limitn How many segments are erased by start-up proceduren Garbage collection algorithmn Wear-levelingn etc

o We are studying ...n Segment sizen Start-up time limitn How many segments are erased by start-up proceduren Garbage collection algorithmn Wear-levelingn etc

14

Page 15: The Design of a Flash-based Linux Swap System

Block-aligned read-ahead swap-in

o Patent: Read-ahead swap-in method considering flash memory erasure block, May. 2008

o Proposed scheme reads ahead pages that lie in the same block.n We need only one erase operation to reuse swapped-in slots.

o By reducing the number of invalid blocks to be erased, we can decrease the garbage collection (GC) cost.

o Patent: Read-ahead swap-in method considering flash memory erasure block, May. 2008

o Proposed scheme reads ahead pages that lie in the same block.n We need only one erase operation to reuse swapped-in slots.

o By reducing the number of invalid blocks to be erased, we can decrease the garbage collection (GC) cost.

15

Block-aligned swap-inLinux swap-in

Page 16: The Design of a Flash-based Linux Swap System

Analysis of Linux swap I/O traces

o In order to evaluate performance, we collected some swap I/O traces from linux kernel.

o Most of all, we want to know the swap-in behaviour. So, we turned off read-ahead option of swap-in before collecting the traces.

o Because we disabled read-ahead option, all swapped-in pages were loaded on demand and we can examine the pure swap-in behaviour.

o We examined if the locality exists in the swap slot accesses due to swap-in operations.

o We found that the temporal/spatial locality exist in the swap-in references

o In order to evaluate performance, we collected some swap I/O traces from linux kernel.

o Most of all, we want to know the swap-in behaviour. So, we turned off read-ahead option of swap-in before collecting the traces.

o Because we disabled read-ahead option, all swapped-in pages were loaded on demand and we can examine the pure swap-in behaviour.

o We examined if the locality exists in the swap slot accesses due to swap-in operations.

o We found that the temporal/spatial locality exist in the swap-in references

16

Page 17: The Design of a Flash-based Linux Swap System

Locality of Swap-in pattern

o These figures show the slot numbers accessed by swap-in operations of a particular process.

1000

2000

3000

4000

5000

6000

slot

num

ber

sendmail

17

0

1000

0 20 40 60 80 100 120 140 160 180 200

slot

num

ber

sequence of swap-in

0

1000

2000

3000

4000

5000

6000

0 10 20 30 40 50 60 70

slot

num

ber

sequence of swap-in

Xorg

Page 18: The Design of a Flash-based Linux Swap System

Read ahead ??

o Due to locality, read-ahead is a good approach to reduce the disk seek time.

o Flash memory does not require seek time but read-ahead can result in better performance.n Read-ahead can decrease the number of page faults

o Due to locality, read-ahead is a good approach to reduce the disk seek time.

o Flash memory does not require seek time but read-ahead can result in better performance.n Read-ahead can decrease the number of page faults

18

Page 19: The Design of a Flash-based Linux Swap System

Performance Evaluation

o We have performed trace-driven simulation to investigate the performance of read-ahead swap-in schemes and garbage collection algorithms.

o Swap-out : allocates slots sequentially

o Swap-in: read-aheadn 8 pages by linux swap schemen 8 pages by block-aligned schemen 16 pages by block-aligned schemen 32 pages by block-aligned scheme

o Garbage collection algorithmsn Greedy (GR)n Cost-Benefit (CB)n Cost-Age-Time (CAT) n Cost Benefit with Age (CBA)

o We have performed trace-driven simulation to investigate the performance of read-ahead swap-in schemes and garbage collection algorithms.

o Swap-out : allocates slots sequentially

o Swap-in: read-aheadn 8 pages by linux swap schemen 8 pages by block-aligned schemen 16 pages by block-aligned schemen 32 pages by block-aligned scheme

o Garbage collection algorithmsn Greedy (GR)n Cost-Benefit (CB)n Cost-Age-Time (CAT) n Cost Benefit with Age (CBA)

19

Page 20: The Design of a Flash-based Linux Swap System

Performance Evaluation

o Garbage collection algorithmsn Greedy (GR) : selects a block with the largest amount of invalid

slots

n Cost-Benefit (CB) : selects a block that maximize the formular:

n Cost-Age-Time (CAT) : selects a block that maximize the formular:

n Cost Benefit with Age (CBA) : selects a block like CB and sorts valid slots with ages and moves the oldest pages first

uuage

+-×

1)1(

age : the time since the most recent modificationu : the fraction of space occupied by valid slots

o Garbage collection algorithmsn Greedy (GR) : selects a block with the largest amount of invalid

slots

n Cost-Benefit (CB) : selects a block that maximize the formular:

n Cost-Age-Time (CAT) : selects a block that maximize the formular:

n Cost Benefit with Age (CBA) : selects a block like CB and sorts valid slots with ages and moves the oldest pages first

20

uuage

+-×

1)1(

age : the time since the most recent modificationu : the fraction of space occupied by valid slots

counteraseage

uu

_1

11

××+-

Page 21: The Design of a Flash-based Linux Swap System

Performance Evaluation

o Through the simulation, we measured the following performance metrics to calculate the garbage collection cost.n read countn erase copy count : the number of writes due to GC n erase count

o Garbage collection must copy the valid slots in the victim block to the free space before erasing it.

o Copy operation requires read and write operation.

o Garbage collection cost

§ the write operation is 10 times slower than the read operation and the erase operation is 75 times slower than the read operation.

o Through the simulation, we measured the following performance metrics to calculate the garbage collection cost.n read countn erase copy count : the number of writes due to GC n erase count

o Garbage collection must copy the valid slots in the victim block to the free space before erasing it.

o Copy operation requires read and write operation.

o Garbage collection cost

§ the write operation is 10 times slower than the read operation and the erase operation is 75 times slower than the read operation.

21

Cost = read_count + copy_count*10 + erase_count*75

Page 22: The Design of a Flash-based Linux Swap System

Some Results

22

o GC algorithms have little effect.o The number of read-ahead has

little effect.o Block-aligned read-ahead

outperforms non-block-aligned read-ahead.0

50

100

150

200

250

GR CB CAT CBA

eras

e_co

py_c

ount

8_erase_copy 16_erase_copy32_erase_copy linux_erase_copy

Page 23: The Design of a Flash-based Linux Swap System

Some Results

o GC Cost

o As a result, GC cost of propo-sed block-aligned swap-in scheme is almost three times smaller than linux scheme.

Page 24: The Design of a Flash-based Linux Swap System

Conclusions

o Segment based swap space management can reduce the start-up time.

o Block-aligned read-ahead scheme can reduce the garbage collection cost.

o We are yet studying ..

o Segment based swap space management can reduce the start-up time.

o Block-aligned read-ahead scheme can reduce the garbage collection cost.

o We are yet studying ..

24

Page 25: The Design of a Flash-based Linux Swap System

Thank you..

[email protected]

25

Thank you..

[email protected]

Page 26: The Design of a Flash-based Linux Swap System

26

Swap-in request