Monday, October 27, 2014

Running Linux distributions from a flash card or stick -- customization required for good performance!

Linux on flash storage is ubiquitous

There are quite a few Linux-based systems running with the main (root) file system on cheap flash memory (not a full SSD), ranging from development boards to the highest-volume consumer mobile devices sold today.

Full Linux distributions being run on such devices include the popular Raspberry Pi educational development board, and there are communities dedicated to running full Linux distributions on other ARM-based developments boards or consumer devices such as tablets and media boxes.

Many consumer devices can be made to run full Linux, but tinkering often required

In fact, if a consumer device such as a cheap tablet has external interfaces such as a USB port and HDMI and the ability to boot an alternative OS after flashing the bootloader or directly from an SD card, it is probably possible to run a pretty much full-featured Linux desktop on it, including mouse, keyboard and a big PC monitor. Although this used to be relatively slow (especially for a full GUI environment), recent ARM SoCs have become faster and can provide a more pleasant experience.

However, on anything but a development board, this is not usually 'plug-and-play', and technical expertise and experimentation is often required, with the different ARM chip platforms being in different states of development regarding running full Linux on them, and development efforts for a typical platform being fragmented. The often widespread variation between devices using the same chip platform in the use of peripheral chips such as WiFi chips, use of different LCD screens, different RAM configurations and other factors add to the complexity. If a functional kernel with enough working device drivers is available, any typical Linux root filesystem such as something based on Debian compiled for ARM can be run on it.

Or course, billions of mobile devices such as smartphones and tablets running Android already run Linux-like systems (including an actual kernel) on cheap flash-based storage. There is also significant cross-over between Android kernel driver source code and device drivers for full Linux, with many kernels and drivers being directly usable or requiring limited adaptation.

Intel/AMD x86 systems too

Running Linux on a cheap or older x86 system using simple flash storage for the root filesystem is not uncommon either. This includes early netbooks such as the Asus Eee PC series, which can still be pretty usable when properly upgraded, configured and optimized with a lightweight Linux distribution. Additionally the cheapest and smallest x86 mini-PCs often have basic flash storage (although low-cost SSDs offer high performance for a higher price).

Optimization required and does wonders for performance

The fact that standard Linux distributions with their default configurations and settings have a strong legacy in full-featured hard disk drive-based systems, including heavy duty applications like servers, and therefore are not at all suited for running on a small, flash-based single user device in their default configuration, is often overlooked.

Even popular development boards such as the Raspberry Pi for a long time shipped with a Debian-based distribution that was still largely configured for heavier use, with extensive logging and temporary files and caches from applications being continuously stored and modified on the local flash disk (as they would on HDD-based systems), which is an obvious way to make a system very slow and unresponsive given the nature of flash drives (especially writing to a flash drive can be costly in terms of time taken, with excessive write access also being detrimental to the stability and lifetime of the flash memory).

Several major file system and OS configuration optimizations possible

As will be described in subsequent posts, it is not at all difficult to largely eliminate excessive flash disk access (especially writes), resulting in a dramatically better user experience and performance. Measures include largely eliminating system logging, clever use of RAM-disks for every possible kind of temporary storage, and configuring a Linux filesystem such as ext4 with settings such as write-back mode resulting in more effective write caching, eliminating unneccessary bookkeeping such as access time, and other tweaks such as forgoing on features such as journalling and huge file support that cater for larger systems and maximal stability on externally powered systems such as PCs.

In fact, because many of the devices mentioned are battery powered or can easily be modified to be battery powered, there is actually potential to run a fairly stable system even with heavy optimizations such as write-back settings and limited journalling that would normally impact stability on HDD-based desktop systems. Apart from a common filesystem like ext4, many older or new filesystems can in principle be configured to work well on flash memory.

1 comment:

  1. Thanks for sharing this. I am not too good with these things so I have been researching online for a good performance monitoring software to monitor everything for my small business. I have to find what's easiest for me.