MTD Based Compressed Swapping for Embedded Linux.

Similar documents
Compressed Swap for Embedded Linux. Alexander Belyakov, Intel Corp.

A Memory Management Scheme for Hybrid Memory Architecture in Mission Critical Computers

The Journalling Flash File System

EMSOFT 09 Yangwook Kang Ethan L. Miller Hongik Univ UC Santa Cruz 2009/11/09 Yongseok Oh

The Journalling Flash File System

Optimizing Translation Information Management in NAND Flash Memory Storage Systems

CHAPTER 3 RESOURCE MANAGEMENT

Data Organization and Processing

Anatomy of Linux flash file systems

Using Transparent Compression to Improve SSD-based I/O Caches

Flash filesystem benchmarks

Flash Drive Emulation

SFS: Random Write Considered Harmful in Solid State Drives

Journal Remap-Based FTL for Journaling File System with Flash Memory

Storage Architecture and Software Support for SLC/MLC Combined Flash Memory

TEFS: A Flash File System for Use on Memory Constrained Devices

CHAPTER 6 Memory. CMPS375 Class Notes (Chap06) Page 1 / 20 Dr. Kuo-pao Yang

CHAPTER 6 Memory. CMPS375 Class Notes Page 1/ 16 by Kuo-pao Yang

Baoping Wang School of software, Nanyang Normal University, Nanyang , Henan, China

Operating Systems Design Exam 2 Review: Fall 2010

Open-Channel SSDs Offer the Flexibility Required by Hyperscale Infrastructure Matias Bjørling CNEX Labs

Operating Systems Design Exam 2 Review: Spring 2011

Flash File Systems Overview

CS 416: Opera-ng Systems Design March 23, 2012

Compression Support for Flash Translation Layer

STAFF: State Transition Applied Fast Flash Translation Layer

Memory Management. Goals of Memory Management. Mechanism. Policies

Chapter 12 Wear Leveling for PCM Using Hot Data Identification

SSD (Solid State Disk)

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

Operating Systems Design Exam 2 Review: Spring 2012

Outlook. Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The Intel Pentium

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

[537] Flash. Tyler Harter

Chapter 3 - Memory Management

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

A Caching-Oriented FTL Design for Multi-Chipped Solid-State Disks. Yuan-Hao Chang, Wei-Lun Lu, Po-Chun Huang, Lue-Jane Lee, and Tei-Wei Kuo

2. PICTURE: Cut and paste from paper

YAFFS A NAND flash filesystem

NAND/MTD support under Linux

A Buffer Replacement Algorithm Exploiting Multi-Chip Parallelism in Solid State Disks

June IBM Power Academy. IBM PowerVM memory virtualization. Luca Comparini STG Lab Services Europe IBM FR. June,13 th Dubai

Shared snapshots. 1 Abstract. 2 Introduction. Mikulas Patocka Red Hat Czech, s.r.o. Purkynova , Brno Czech Republic

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Flash Memory Based Storage System

ECE 598 Advanced Operating Systems Lecture 10

CS510 Operating System Foundations. Jonathan Walpole

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

Basic Memory Management

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Contents. Memory System Overview Cache Memory. Internal Memory. Virtual Memory. Memory Hierarchy. Registers In CPU Internal or Main memory

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

Virtual Memory. Chapter 8

CS399 New Beginnings. Jonathan Walpole

Contents. Acknowledgments... xi. Foreword 1... xiii Pierre FICHEUX. Foreword 2... xv Maryline CHETTO. Part 1. Introduction... 1

Yaffs Tuning. Charles Manning

FILE SYSTEMS, PART 2. CS124 Operating Systems Fall , Lecture 24

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

16 Sharing Main Memory Segmentation and Paging

Memory management units

COSC3330 Computer Architecture Lecture 20. Virtual Memory

Chapter 6 Memory 11/3/2015. Chapter 6 Objectives. 6.2 Types of Memory. 6.1 Introduction

Presented by: Nafiseh Mahmoudi Spring 2017

High Performance Solid State Storage Under Linux

FFS: The Fast File System -and- The Magical World of SSDs

The What, Why and How of the Pure Storage Enterprise Flash Array. Ethan L. Miller (and a cast of dozens at Pure Storage)

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

Chapter 6. Storage and Other I/O Topics

Storage. Hwansoo Han

CFLRU:A A Replacement Algorithm for Flash Memory

Seagate Enterprise SATA SSD with DuraWrite Technology Competitive Evaluation

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8 Virtual Memory

Chapter 8: Memory-Management Strategies

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

I/O and file systems. Dealing with device heterogeneity

Chapter 8: Virtual Memory. Operating System Concepts

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Topics. File Buffer Cache for Performance. What to Cache? COS 318: Operating Systems. File Performance and Reliability

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Operating Systems. Week 9 Recitation: Exam 2 Preview Review of Exam 2, Spring Paul Krzyzanowski. Rutgers University.

Chapter 3 Memory Management: Virtual Memory

CS 31: Intro to Systems Caching. Kevin Webb Swarthmore College March 24, 2015

1. Creates the illusion of an address space much larger than the physical memory

UNIT III MEMORY MANAGEMENT

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

BPCLC: An Efficient Write Buffer Management Scheme for Flash-Based Solid State Disks

IRON FOR JFFS2. Raja Ram Yadhav Ramakrishnan, Abhinav Kumar. { rramakrishn2, ABSTRACT INTRODUCTION

NAND flash memory is mostly used for data storage of

Virtual Memory #2 Feb. 21, 2018

Command Line Parameters Linux Check Disk Space Windows 7

CS 5523 Operating Systems: Memory Management (SGG-8)

LECTURE 11. Memory Hierarchy

Transcription:

MTD Based Compressed Swapping for Embedded Linux. Alexander Belyakov, alexander.belyakov@intel.com http://mtd-mods.wiki.sourceforge.net/mtd+based+compressed+swapping Introduction and Motivation Memory is a critical resource in many embedded systems. Increasing memory often increases packaging and cooling costs, size, and energy consumption. The total requirements for applications in the mobile phone market are doubling or even tripling each year [1]. As embedded systems support new applications, their working data sets often increase in size, exceeding original estimates of memory requirements. Significant hardware redesign may increase time-to-market and design costs. The flash memory device is a critical component in building embedded systems because of its nonvolatility, shock-resistant, and power economic nature. A typical embedded multimedia system such as high-end cellular phone usually contains D, NOR flash, and NAND flash memory devices, where D is used as a working memory, NOR flash as code storage and NAND for non-volatile data storage. The basic idea of this work is to enable flash memory as swap area to store compressed unused memory pages. The key requirement is solution simplicity without hardware redesign and significant Linux kernel changes. What are the key advantages of having compressed swap on top of flash memory? First more virtual memory becomes available for applications with the same amount of. Second more memory becomes available for file-cache increasing file-backed application performance. Third power consumption becomes lower as we use power economic flash instead of part. Next whole design cost may become lower because flash is usually considered to be cheaper than D and we need less space because of compression. Next point seems to be quite debatable. There is an opinion among kernel developers that swap must be enabled in Linux, because even for systems that don't need the extra memory space, swap can actually provide performance improvements by allowing unused memory to be replaced with often-used memory. It is a magical property of swap space, because extra doesn't allow you to replace unused memory with often used memory. The theory holds true no matter how much you have. [2] The price for all these nice things is performance degradation, because flash is slower than and because compression eats CPU time. Another flash media type related issue is erase cycles required for generic NOR and NAND parts. There is no way to rewrite data without erasing whole eraseblock which is most likely much larger than kernel page size. And the last issue to mention is flash wear out problem. There is very limited number of write-erase cycles allowed for each eraseblock. Normally it is about 10 5 cycles. Media types We used three types of underlying media to evaluate compressed swap solution. NAND Swapping to NAND is quite difficult because all the flash issues mentioned earlier holds true. To handle explicit erase requirements and wear out issue it is necessary to implement caching layer or use special sector manager with garbage collector, bad block manager and wear leveling algorithms. As an 1

option one may use swapfile on top of existing NAND filesystem which supports swapping. But even having all this stuff might not be enough, because swapping subsystem still writes too much and wears out flash too quickly. PCM PCM is phase change memory. It is relatively new flash type which has NOR-like interface. The most important new features of PCM from swapping point of view are high cycling endurance (up to 10 8 rewrite cycles), bit alterable writes, and quite promising performance. Bit alterable writes make swapping very simple eliminating all erase related stuff. The most simple media is itself. Not much to say here we just allocate memory and put compressed swapped pages there. Key benefits are extra virtual memory with minor performance impact and without hardware design changes. Swapping to is well known technique and there are several already working solutions. The one of most recent is compressed caching for Linux solution [8]. It seems compcache idea is quite similar to ours if we are speaking about swapping to. One may consider our solution as a kind superset for compcache solution. Related works The idea of memory compression is not new. Early techniques for reducing the requirements of embedded systems were mostly hardware-based. For example, there was an idea to insert a hardware compressor/decompressor unit between the cache and [3, 4]. These solutions require significant hardware changes and cannot be easily introduced into existing embedded designs. Swap compression itself is also known technique [5-7]. For example, researches from Spain [5] developed and tested mechanism of compressing swap pages and keeping them in a swap cache whenever possible. Depending on workload applications and data compression ratio they got benchmark up between 1.2 and 2.1. Their approach changes Linux virtual memory management subsystem internals and relays on hard-disk enabled systems. Another related work [6] deals with compression of swapped pages and storing them into the device. Their prototype divided the into two portions: one containing compressed data pages and the other containing uncompressed data pages as well as code pages. This solution was tested by the authors on disk-less embedded systems. Experimental results indicated that solution is capable of doubling the amount of available for applications with negligible performance of power consumption overhead. From very high level point of view our solution is quite similar to this one (as well as to most recent compcache solution), except we are able to keep compressed swapped pages not only in, but also on flash. Another related work [7] is trying to keep compressed swapped pages on NAND flash memory. The authors created swap file on YAFFS partition and changed Linux virtual memory management subsystem swapping algorithm. Developed swapping algorithm is based on CFLRU (Clean First LRU) method and employs some additional features such as selective compression and delayed swapping. This algorithm helps enhancing the stability of filesystem by reducing number of writes. Experimental results show that proposed solution can reduce number of writes by 50-70% without affecting the system performance much. Reduced D size helps in lowering the system implementation cost as well as power consumption. 2

MTD compression layer (prototype) The goal of this work was to lower requirements of embedded systems through enabling effective swapping to flash with minor software changes. The basic idea was to create MTD (memory technology device) compression layer and use it as swap area via mtdblock interface. We called this new layer MTDCOMPR just to give an idea of what is this layer for. MTDCOMPR creates new MTD device on top of existing one. MTD flag for the new device is always set to MTD_NO_ERASE, so mtdblock itself doesn t perform caching or flash erase. The only function of mtdblock interface is sector read/write operations translation to mtdcompr read/write calls. swap subsystem (VM) New! MTD FLASH WRITESECT() READSECT() MTDBLOCK IF MTDCOMPR (ZLIB) MTDCOMPR->WRITE() MTDCOMPR->READ() MTD->WRITE() MTD->READ() MTD->ERASE() MEMCPY() We picked kernel zlib library as a main swapped pages compressor. Experimenting with MTDCOMPR on desktop PC running standard GUI enabled applications, it was found that swapped pages have less than 25% compression ratio with best compression method (i.e. pages require four times less memory if compressed). The same results have been achieved by researched worked earlier with compression techniques [6]. 3

MTDCOMPR data flow Writing to swap Assume virtual memory subsystem decided to swap out single page. Write request falls to MTDCOMPR via mtdblock interface. Using MTDCOMPR exclusively for swapping allows us to use kernel page sized buffer. By default mtdblock splits all incoming requests by 512 bytes chunks, so MTDCOMPR waits until whole page is in buffer. Write request (buffer, external offset) Fill input buffer (page size) Invalidate existing on-media data (update free space list) Compress the data Select the largest free on-media chunk from in-memory list Write compressed data (with headers) splitting between free chunks if necessary Update free space list Store external-internal offset correspondence within in-memory tree Return with success Next step is to seek if page with such external offset has been previously swapped out and writted to the media. If such a page does exist we invalidate the old one by marking flash space it holds as free. MTDCOMPR keeps in-memory sorted list with flash free space fragments information. Now we are ready to compress data. Do it. Next step is to pick the largest free space fragment from in-memory list to write compressed data there. Such a rotation creates a kind of so called random wear leveling where pages with the same external offset is stored by different media offsets all the time. Before actual writing we split compressed data into chunks of free space fragment size if needed and apply headers. Then perform writing. 4

There is one important note. Such writing algorithm is fine for and PCM, but not for NAND. Because NAND flash requires explicit erase before rewriting the data. So MTDCOMPR has optional caching layer similar to one of mtdblock. It is quite simple and thus brings significant performance overhead because writing small piece of data may turn into read-erase-write sequence altering whole sector (eraseblock). Actually to make swapping on NAND viable it is necessary to use sector manager or FTL (flash translation layer) with garbage collector, bad block manager and wear leveling stuff. Another option is to use one of existing NAND filesystem like YAFFS. Anyway using NAND as swap requires a lot of things to think about including virtual memory manager changes lowering number of writes [7]. If writing succeeds we update free space list and store external-internal page offset correspondence within in-memory tree. After that we happily return write success status to the mtdblock caller. Reading page back If virtual memory subsystem wants the page back, MTDCOMPR receives read request from mtdblock. Using read-from offset we search in-ram tree for corresponding on-media offset. Then MTDCOMPR reads the data chain from the media and decompress it to the provided buffer. Read request (buffer, external offset) Find corresponding internal offset by external offset Read data chain from the media Decompress the data Return with success until buffer is empty 5

As page read request can span several read requests from mtdblock, we read and decompress whole page after the first subrequest, and then pass the data to the mtdblock caller with several read requests without actual reading from media. Performance expectations (theory) Compressed swap performance and memory increase depends on several factors. They are flash read/write times, flash partition size, erase requirements, CPU, compressor, data compression rate etc. But the generic behavior is quite common. Flash memory Speaking about swapless system we see almost flat memory access time until system uses all available. After that system most likely gets out-of-memory exception. For system with compressed swap things are different. There is also almost flat performance until used memory amount hits size. After that threshold memory access performance gets lower and stays somewhere between pure and swapped pages access, because some pages are still in and some pages are swapped. Out-of-memory event occurs later depending on data compression ratio. memory access access swap access size FLASH size Out of memory memory in use only + compressed SWAP on FLASH Note there is known way to control swapping intensity swappiness parameter which can be set via procfs interface. In particular this parameter changes the threshold where systems start swapping. System with compressed swap in starts to swap earlier because some amount of is already allocated to store compressed pages. As for the rest of behavior it is quite similar to swapping to flash, except is faster. 6

memory access access swap access disk size size memory in use no swap compressed swap in Performance (experiments) Performance measurement technique We used MTDCOMPR module with 2.6.23.8 kernel and ran it on Mainstone II (PXA271) development board limiting its amount to 32 Mbytes. JFFS2 rootfs is placed on M18 volume. MTDCOMPR module itself gathers swap read/write average performance as well as compression and decompression throughput. This information can be accessed via procfs interface. To measure the performance on user-mode level we were using simple benchmarking application. The application allocates memory chunk by chunk filling them with data. After chunk allocation it tries to read some of previously allocated data measuring average performance. There are three cases: first - data to read picked each time randomly ( random reads ); second we randomly pick data chunk and read it several times ( fixed reads ); third we read several times the last allocated chunk of data ( last reads ). Random reads case is quite far from reality, because application doesn t access all the allocated memory randomly. Normally applications work with selected (its own) piece(s) of memory. Fixed read and last read cases describe such a behavior quite well. As a key performance indicator we used memory access chart depending on total amount of allocated by the application memory. NAND A lot of erase related troubles comes if we are speaking about NAND. Some of them have been solved in [7] by using NAND file system and changing swapping algorithm. We were focused on PCM and based solution, but still experimented a bit with NAND. One of purposes was to give an impression about difficulties related to having swap on generic flash like NOR and NAND. 7

Compressed swap on NAND 1000 Performance, % 100 10 1 0 0 16 32 48 64 80 Memory in use, Mbytes fixed reads last reads random reads Fixed reads case average performance is about 52% of pure performance. In case of random reads the performance quickly drops to the less than 0.5% level. Main conclusion from experiment is that NAND is not appropriate media for such a simple solution. To make it viable it is necessary to use quite complex sector manager (FTL) with compression or NAND filesystem which does support swapping. But even using such complex software it still may require to change virtual memory subsystem to lower number of swap read/writes [7]. PCM Phase change memory is great embedded solution s media for swapping, because of its bit alterable writes. It is possible to write data without explicit sector erase. From other side this memory behaves as generic NOR flash. Compressed swap on PCM 1000 Performance, % 100 10 1 0 0 16 32 48 64 80 Mem ory in use, Mbytes fixed reads last reads random reads 8

For the first PCM generation fixed reads benchmark showed performance at the level of 80% from one for pure. In case of random reads the performance slowly drops to the less than 10% level. In our experiments MTDCOMPR increased amount of memory available for applications by 2.5 times. Having 32 Mbytes of and 16 Mbytes of PCM we allocated more than 70 Mbytes of memory for benchmarking application. Storing compressed swapped pages in provides more virtual memory for applications with quite small performance and power consumption change [6]. Compressed swap on 1000 Performance, % 100 10 1 0 0 16 32 48 64 Memory in use, Mbytes fixed reads last reads random reads Fixed reads case average performance is about 89% of pure performance. In case of random reads the performance drops to about 10% level. Note that the amount of memory available for applications was almost doubled in experiments with swap in. Conclusion MTDCOMPR being relatively simple Linux kernel driver allows dramatically increasing virtual memory available for applications with moderate performance impact. Having more virtual memory with the same amount of allows reducing embedded design cost and power consumption. Or, from the other hand, allows running applications with exceptional memory requirements. 32MB 16MB PCM MTDCOMPR ZLIB1 80MB virtual memory perf: 100% perf: 80% PCM or as swap area solution appears to be quite simple because no explicit erase is required. PCM enabled swapping is hardware dependent solution, enabled is not. 9

For NAND significant software changes may be needed including usage of FTL or NAND file system, as well as virtual memory subsystem change. References [1] M. Yokotsuka, Memory motivates cell-phone growth, Wireless Systems Design, Apr. 2004. [2] Nick Piggin, LKML [3] B. Tremaine, et al., IBM memory expansion technology, IBM Journal of Research and Development, vol. 45, no. 2, Mar. 2001. [4] L. Benini, et al., Hardware-assisted data compression for energy minimization in systems with embedded processors, in Proc. Design, Automation & Test in Europe Conf., Mar. 2002. [5] T. Cortes, Y. Becerra, and R. Cervera, Improving Application Performance through Swap Compression, in Proc. USENIX Conf., June 1999. [6] Lei Yang, Robert P. Dick, Haris Lekatsas, Srimat Chakradhar, CES: Compresses for Embedded Systems, in CODES + ISSS 05, Sept. 2005. [7] Sangduck Park, Hyunjin Lim, Hoseok Chang, and Wonyong Sung, Compressed Swapping for NAND Flash Memory Based Embedded Systems [8] Compressed Caching for Linux, http://code.google.com/p/compcache/ 10