How to minimize Linux OS

Source: Internet
Author: User
Article Title: how to minimize the Linux operating system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Reduce Linux system usage, reserve more resources for applications, and reduce hardware costs for devices. "How small can you be ?" This problem is usually asked when embedded Engineers start their projects. Most of the time, the people who ask this question want to reduce RAM and Flash resources and the unit cost or energy demand of devices.

Because Linux was originally designed for a desktop or server system, by default, it has not been optimized for the size. In any case, Linux is increasingly used in embedded devices, it is not easy to make Linux smaller. Here are several ways to reduce the memory usage of the system.

Many Engineers start from reducing the kernel size. Here is an easy way to start. This article will detail how to reduce the kernel size, it mainly removes the code that is not used in a typical embedded system.

In a system, the root file system (RFS) may be the biggest consumer of memory resources. The root file system includes the infrastructure code used by the application and the c library. Selecting a file system for RFS has a huge impact on the final size. The standard is ext3, which is very inefficient from an embedded engineer's perspective, but that is the topic of another article.

In practice, how can we reduce it?

Even the smallest Linux release has at least two parts: the kernel and the root file system. Sometimes these parts are located in the same file, but they are still divided into different parts. Remove almost all code with similar features from the kernel, so that a system can easily be reduced to less than 1 MB. However, many users choose Linux to support networks and different devices, so this is not a practical practice.

Kernel

The Linux kernel is very interesting. Although it depends on GCC at compilation, it does not depend on it at runtime. Those Engineers turned to Linux to initialize the RAM disk (the so-called initrd), which is an attachment to the kernel runtime. Initrd is first loaded by the kernel. When the program runs, it asks the system what modules need to be loaded to support the device so that the real root file system can be loaded. In fact, there are two loading steps: loading initrd and then loading the real root file system. It is rare to find that there is a root file system in the embedded system, because it will increase flexibility in a system, it takes additional space or time to modify the system. embedded systems generally do not require flexibility. However, this article will discuss the root file system later.

Supported load modules

The kernel loading module relocates the code that the kernel connects to itself during runtime. A typical example of a load-able module is to allow the driver to be loaded into the kernel from the user space (after some probe processes are executed ), and do not disable the system upgrade device driver. For most embedded systems, once they are out of this range, modifying the root file system is either unrealistic or impossible. Therefore, the system designer directly connects the module to the kernel and removes the loaded modules, saving a lot of space for the kernel, program Management can load modules (such as insmod \ rmmod \ lsmod) and shell scripts to load them are not required.

Linux-tiny patch

The Linux-tiny patch set has become a temporary project, initially hosted by Matt macall. The consumer electronic Linux Forum (CLEF) is working hard to restore this project. The CLEF developer WiKi has released a patch for the 2.6.22.5 kernel (the latest version when writing this article). At the same time, many changes to the Linux-tiny project have been included in the main kernel. Although many original Linux-tiny patches have been integrated into the kernel, the space-saving patches have not yet been integrated.

For example:

1. Fine-grain printk support [Fine-grained printk support]: users can control what files can use printk. Engineers will not benefit from using the printk file size.

2. Change CRC from calculation to use table lookup [Change CRC algorithm from calculation to use table query]: an Ethernet data packet requires a CRC to verify the accuracy of the data packet. This CRC algorithm replaces the calculation with Table query, saving about 2 K.

3. Network tweaking [Network adjustment]: Several patch packages reduce the supported Network protocols, cache size, and open sockets. Many embedded devices only support a small number of protocols and do not need services with hundreds of thousands of connections.

4. No panic reporting [No emergency report]: If the device has three status lights and a series of connections, users cannot see them, with less impact, the emergency information is displayed on a non-existent terminal. In case of kernel failure, you only need to restart the device.

5. Reduction of inlining: Direct insertion means that the compiler copies the code as a macro to every position of its call, rather than generating a function call. By default, GCC inserts any function directly. By suppressing the direct insertion of functions, the code runs slowly because the compiler needs to generate code for calls and responses, and the reward is that the object file is smaller.

The Linux-tiny patch is released as a tar package, which can be applied together or separately.

[1] [2] [3] [4] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.