Dr.M.Lordwin Cecil Prabhaker
Contents
•Embedded File System: RAMDisk – RAMFS –
CRAMFS
• Journaling Flash File Systems: JFFS and JFSS2
• NFS and PROC File system
• Optimizing storage Space: Kernel space
optimization - Application Space Optimization
• Applications for Embedded Linux
• Tuning kernel memory.
3.
Dr.M.Lordwin Cecil Prabhaker
EmbeddedFile System
• Types:
– Flash based (Widely Used)
– Memory based
• used at boot-up time to hold a root file system
• for storing volatile data that need not be saved across
reboots.
4.
Dr.M.Lordwin Cecil Prabhaker
RAMDisk
• It is a way by which Linux emulates a hard disk using memory.
• For storing a root file system when there is no traditional
storage device such as a hard disk or a flash.
• .initrd that holds the ramdisk image
– It is used to load the kernel image along with a root file system into
memory.
• Creating the initrd image and packing it with the kernel image.
• It gives a mechanism by which you can switch to a new root
file system at a later point of time during system execution
• Uses :
– system recovery and upgrade procedures
5.
Dr.M.Lordwin Cecil Prabhaker
Process
Thescript creates an initrd image “/tmp/ramdisk.img”
mounted as an “ext2” file system on the target
It uses a loopback device “/dev/loop0” to copy files
from the root file system folder “<rfs-folder> “ to the
target image “/tmp/ramdisk.img”
Dr.M.Lordwin Cecil Prabhaker
•Its Usage is,
mkinitrd <rfs-folder> <ramdisk-size>
where,
• <rfs-folder> is the absolute path of the parent directory
containing the root file system.
• <ramdisk-size> is the size of initrd.
8.
Dr.M.Lordwin Cecil Prabhaker
RAMFS(RAM File System)
• To store files that are not useful across reboots at /tmp directory
– It was observed that initializations such as,
• finding the root device,
• mounting the root file system either locally or over NFS, and so on that were part of
the kernel boot-up sequence can easily be handled in user space.
• Initramfs was introduced in the 2.6 kernel to provide early user space.
The “initramfs” image
Its usage is:
Dr.M.Lordwin Cecil Prabhaker
CRAMFS(Compressed RAM File
System)
• This is a very useful file system for flash storage and was
introduced in the 2.4 kernel.
• It is a high-compression “read-only” file system.
• CRAMFS is a regular file system; that is, it goes via the buffer
cache to talk to a block device holding the actual data.
• Hence you need to enable the MTD block device driver mode
to use CRAMFS.
• CRAMFS uses the zlib routines for compression and it does
compression for every 4-KB (page size) block.
• The CRAMFS image that needs to be burned in flash can be
created using a program called mkcramfs.
11.
Dr.M.Lordwin Cecil Prabhaker
JournalingFlash File Systems — JFFS
and JFFS2
• What is in JFFS?
– The Journaling Flash File System
(or JFFS) is a log-structured file system for
use on NOR flash memory devices on the
Linux operating system.
– No data corruption on sudden power outage
– Directly use the MTD-level APIs instead of
going through the flash translation layers
– Linux 2.0 kernel and 2.2 & 2.3
– A journaling flash file system is
specifically designed to minimize frequent
overwrites.
– Files which are read many times but
written infrequently work well on main
flash.
12.
Dr.M.Lordwin Cecil Prabhaker
•JFFS2
– Added with compression technique
– 2.4 kernel
• Both JFFS and JFFS2 are log-structured file systems; any
change to a file gets recorded as a log, which gets directly stored
on the flash (logs are also called nodes).
• The contents of this log will be:
– Identification of the file to which the log belongs
– Version that is unique per log belonging to a particular file
– Metadata such as timestamp
– Data and data size
– Offset of the data in the file
13.
Dr.M.Lordwin Cecil Prabhaker
Parametersused in JFFS
• Folders and files written to a JFFS2 flash drive are logged in sections called
nodes.
– There are two types of nodes:
• inode – metadata with optional data
• Directory Entry (dirent) node – directory name with inode number.
– When the file is the same but in two different locations, the inode number is the same (hard link).
• When a single file is created, the node is considered valid.
• When a file is modified and created in another location, the node is obsolete.
• Note:
– When a file is renamed,
• a new dirent node is created with the new file name and the inode number. This is similar to a
hard link being created.
• Then, the inode number for the original dirent entry is changed to zero. Changing the number
to a zero unlinked the older entry.
14.
Dr.M.Lordwin Cecil Prabhaker
Themain features of the JFFS2 file
system are as follows.
• Management of erase blocks:
– In JFFS2, the erase blocks are placed in three lists:
• clean, dirty, and free.
– The clean list contains only valid logs (i.e., logs not
invalidated by newer ones).
– The dirty list contains one or many logs that are
obsolete and hence can be purged when garbage
collection is called.
– The free list contains no logs and hence can be used
for storing new logs.
15.
Dr.M.Lordwin Cecil Prabhaker
•Garbage collection:
– JFFS2 garbage collection happens in the context of a separate
thread, which gets started when you mount a JFFS2 file
system.
• For every 99 out of 100 times, this thread will pick up a block from
the dirty list and for the other one out of 100 will pick up a block
from the clean list to ensure wear leveling.
• JFFS2 reserves five blocks for doing garbage collection (this number
seems to have been decided by heuristics).
• Compression:
– The distinguishing factor between JFFS and JFFS2 is that
JFFS2 gives a host of compression including zlib and rubin.
16.
Dr.M.Lordwin Cecil Prabhaker
NFS— Network File System
• The network file system can be used to mount a file system over the
network.
• The Linux kernel provides a mechanism for automatically mounting a file
system using NFS at boot time using following steps,
– The config options CONFIG_NFS_FS, which allows to mount a file
system from a remote server
– CONFIG_ROOT_NFS, which allows to use NFS as root file system
needs to be turned on at build time.
– Because an IP address becomes necessary to connect to a NFS server at
boot time, you might want to turn on the network auto configuration
using BOOTP, RARP, or DHCP.
– Kernel command-line parameters to specify the NFS server have to
be specified
Dr.M.Lordwin Cecil Prabhaker
PROCFile System
• The proc file system is a logical file system used by the kernel to export its
information to the external world.
• The proc file system can be used for,
– system monitoring, debugging, and tuning.
• The proc files are created on the fly when they get opened.
• The files can be read-only or read-write depending on the information
exported by the files.
• The read-only proc files can be used to get some kernel status that cannot
be modified at runtime.
• Examples of read-only proc files are the process status information.
• The read-write proc files contain information that can be changed at
runtime; the kernel uses the changed value on the fly.
• The proc file system gets mounted by the startup scripts at the standard
mount point /proc.
Dr.M.Lordwin Cecil Prabhaker
OptimizingStorage Space
• To effectively use the storage space.
• Techniques
– Kernel Space Optimization
• To remove the unwanted code in kernel space
• Making smaller kernel images (“Linux tiny kernel project”)
– Option to remove printk and all the strings passed to printk
– Avoid too much usage of inline function.
• CONFIG_EMBEDDED option is used to build a sleeker kernel
• SWAP subsystem can be disabled at build time
– Application Space Optimization
• Pruning individual applications with respect to unwanted code
• Using tools such as the library optimizer
• Using smaller and sleeker programs/distributions aimed at embedded systems
• Using a smaller C library such as uClibc
– Using compressed file systems
• file systems such as CRAMFS and JFFS2
21.
Dr.M.Lordwin Cecil Prabhaker
Kernelspace optimization techniques
• Unrolling Loops.
• Pipelining Loops.
• Pipelining Work Items.
• Enabling Concurrent Processing with DATAFLOW.
• Reducing Kernel to Kernel Communication Latency
with OpenCL Pipes.
• Improving Kernel Frequency.
• Exploring Kernel Optimizations Using Vivado HLS.
22.
Dr.M.Lordwin Cecil Prabhaker
Applicationsfor Embedded Linux
• Some popular distributions and applications used for embedded linux systems are,
– Busybox
• Multicall program (single small executable implements some commonly used programs)
• The required programs for the system can be chosen at build time
– Tinylogin
• Similar to Busybox and is used for implementing UNIX log-in and access applications.
• list of functionalities implemented by Tinylogin
– Adding and deleting users
– login and getty applications
– Changing password passwd application
– Ftp Server
• To copy files to and from
• Two Servers : 1. wu-ftpd server and 2. proftpd server,
– Web Server
• Needed for remote management of an embedded device
• For Example: BOA, mini_httpd and GoAhead
23.
Dr.M.Lordwin Cecil Prabhaker
Busyboxcontains the following main programs
known as applets in Busybox terminology:
• Shells such as the
– ash, lash, hush, and so on
• Core utilities such as
– cat, chmod, cp, dd, mv, ls, pwd, rm, and so on
• Process control and monitoring utilities such as
– ps, kill, and so on
• Module-loading utilities such as
– lsmod, rmmod, modprobe, insmod, and depmod
• System tools such
– reboot, init, and so on
• Networking utilities such as
– ifconfig, route, ping, tftp, httpd, telnet, wget, udhcpc (dhcp client), and so on
• Log-in and password management utilities such as
– login, passwd, adduser, deluser, and so on
• Archival utilities such as
– ar, cpio, gzip, tar, and so on
• System logging utilities such as
– Syslogd
24.
Dr.M.Lordwin Cecil Prabhaker
TuningKernel Memory (to reduce memory usage by the kernel)
• Linux kernel does not participate in paging and hence the entire
kernel (code, data, and stack) always resides in main memory.
• How to estimate the memory utilized by the kernel?
– by using the size command
– The /proc/meminfo records the runtime memory on the system.
25.
Dr.M.Lordwin Cecil Prabhaker
TuningKernel Memory - Techniques
• Cutting down on statically allocated data structures
– Statically allocated data structures reside either in the .data or in
the .bss section
• System.map file
– This file contains the symbol addresses of each symbol
• Cutting down unused code within the kernel
• Improper usage of kmalloc ()
– By avoiding waste memory allocation
• Using the .init directive
• Cutting down on holes in physical memory
– To prevent from huge hole “CONFIG_DISCONTIGMEM”
• XIP or “eXecute In Place”
– It is a technology by which a program executes directly from flash
Dr.M.Lordwin Cecil Prabhaker
Conclusion
•File System
– Embedded File system
• RAM Disk – RAMFS – CRAMFS
– Journaling Flash File Systems
• JFFS and JFSS2,
– NFS and PROC File system
• Optimizing storage Space:
– Kernel space optimization
– Application Space Optimization
– Compression
• Applications for Embedded Linux
• Tuning kernel memory
#22 Busybox contains the following main programs known as applets in Busybox terminology:
Shells such as the ash, lash, hush, and so on
Core utilities such as cat, chmod, cp, dd, mv, ls, pwd, rm, and so on
Process control and monitoring utilities such as ps, kill, and so on
Module-loading utilities such as lsmod, rmmod, modprobe, insmod,
and depmod
System tools such reboot, init, and so on
Networking utilities such as ifconfig, route, ping, tftp, httpd,
telnet, wget, udhcpc (dhcp client), and so on
Log-in and password management utilities such as login, passwd,
adduser, deluser, and so on
Archival utilities such as ar, cpio, gzip, tar, and so on
System logging utilities such as syslogd
#24 In computer operating systems, paging is a memory management scheme by which a computer stores and retrieves data from secondary storage for use in main memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages.