Fcache: Accelerate linux Startup

Source: Internet
Author: User
Article Title: fcache: Accelerate linux Startup. 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.

  I. Introduction:

Fcache is written by Jens Axboe, which regards this patch as a weekend project.

The purpose of this patch is not to modify the file system, but to make the startup process completely linear (it should refer to the disk read process), so as to accelerate the linux Startup, in short, fcache is a type of re ing between the file system and Block devices.

Fcache has two operating modes: prime mode and normal mode. When running in prime mode, it caches all read operations on the target partition and writes the data to the cache partition. In this way, data is stored linearly on the cache device, which is a function of time. When running in normal mode, fcache searches for the cache on the cache device. If hit, fcache can directly read the linear data of the cache device at startup. Because the startup process is mostly repetitive, fcache provides a perfect way to obtain startup data.

Generally, the first time you start the system to use the prime mode, prepare the cache data, and then use the normal mode to greatly accelerate the startup speed (as long as your startup process remains unchanged)

Here is a document on fcache principles written by hzmagnel. If you are interested, you can flip it over and we will be touched!

  Ii. How to Use fcache

Step 1: Install fcache for the kernel. The recommended kernel version is 2.6.17.

Cd/usr/src/linux

Download patch wget http://www.kernel.org/pub/linux/kernel/people/ck/patches/2.6/2.6.17/2.6.17-ck1/patches/fs-fcache-v2.1.patch

Go to the kernel source code directory patch-p1 Block devices-> Boot fronted cache driver

Then re-compile the kernel and use it.

Step 2: Create a fcache Partition

The partition size is about MB, and the file system is ext3. If it is only a test, you can temporarily use the swap partition as the fcache partition.

Step 3: Modify the startup and shutdown scripts

When linux is started, the root file system is readonly when it is loaded for the first time. When the root file system is checked, then the rw method is used to remount the root file system. We need to add the fcache parameter during remount. Remount varies with different releases. For example, in gentoo, remount is stored in/etc/init. d/checkroot, and in suse, remount is in/etc/init. d/rootfsck. We can use grep

"Remount" to find the script.

Find the script and find mount-n-o remount, rw/2>/dev/null

Change to mount-n-o remount, fcache_dev = #/*, fcache_prime = 0/2>/dev/null

For ubuntu 7.04, write a specific method (Note: Other versions need to be adjusted accordingly)

Edit the/etc/init. d/checkroot. sh script and find

If! Mount-n-o remount, $ rootopts, $ rootmode $ fstabroot/2>/dev/null

Then

Mount-n-o remount, $ rootopts, $ rootmode/

Fi

Change

If! Mount-n-o

Remount, $ rootopts, $ rootmode, fcache_dev = #/*, fcache_prime = 1 $ fsabroot/

2>/dev/null

Then

Mount-n-o remount, $ rootopts, $ rootmode, fcache_dev = #/*, fcache_prime = 1/

Fi

Note that fcache_dev = #/* indicates the device corresponding to the partition we created in step 2.

# Represents the primary device number, and * represents the secondary device number. For example, the IDE hard disk used by the author is hda10, so fcache_dev = 3/10

Edit the/etc/init. d/umountroot script and find

Mount $ MOUNT_FORCE_OPT-n-o remount, ro-t dummytype dummydev/

2>/dev/null \

| Mount $ MOUNT_FORCE_OPT-n-o remount, ro dummydev/

2>/dev/null \

| Mount $ MOUNT_FORCE_OPT-n-o remount, ro

Change

Mount $ MOUNT_FORCE_OPT-n-o remount, ro, fcache_dev = #/*-t

Dummytype dummydev/2>/dev/null \

| Mount $ MOUNT_FORCE_OPT-n-o remount, ro, fcache_dev = #/*

Dummydev/2>/dev/null \

| Mount $ MOUNT_FORCE_OPT-n-o remount, ro, fcache_dev = #/*

/

OK. Now you can restart it. fcache enters prime mode. This start-up will be a little slower than normal start-up. After the desktop is started, run mount

/-O remount, fcache_dev = #/*, fcache_prime = 0

We can check whether fcahce is working.

Ken @ ubuntu :~ $ Dmesg | grep "fcache"

[17179592.200000] fcache: new header: first block 2872, max 294040

[2, 17179592.200000] fcache: hda10 opened successfully (priming)

[17180105.728000] fcache: ios r/w 6286/4904, hits 0, misses 0, overwrites 766

[17180105.744000] fcache: wrote 6286 extents, holding 354656 sectors of data

[17180105.756000] fcache: wrote header (extents = 6286, serial = 27)

[17180105.808000] fcache: header looks valid (extents = 6286 extents, serial = 27)

[17180105.824000] fcache: loaded 6286 extents

[2, 17180105.824000] fcache: hda10 opened successfully (not priming)

We can see that fcahce is indeed in prime mode and the data at startup is cached.

Finally, modify/etc/init. d/checkroot. sh again, change the first modification

If! Mount-n-o

Remount, $ rootopts, $ rootmode, fcache_dev = #/*, fcache_prime = 0 $ fsabroot/

2>/dev/null

Then

Mount-n-o

Remount, $ rootopts, $ rootmode, fcache_dev = #/*, fcache_prime = 0/

Fi

That is to say, let the fcahce be in the normal state, and start again, you will be able to enjoy the fcache brings you the feeling of starting like flying.

If your startup process changes in the future, for example, if you increase or decrease some startup scripts, You need to reactivate the prime mode once, that is, repeat the above process.

I personally think that from the logon window with the name of the target machine to the login, the system enters the desktop environment and loads the startup Item. During this period, the speed improvement brought by fcache is quite obvious.

Below is the test report

Time1 time2 total

Bytes --------------------------------------------------------------------------------------

Fcache and prime = 1 50 s 52 s 102 s

Fcache and prime = 0 46 s 29 s 75 s

Without fcache 48 s 38 s 86 s

Note: time1 indicates that the logon window appears from loading the kernel

Time2 indicates that logon from start to full start is complete.

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.