FS-Cache and cachefs for network filesystem

Source: Internet
Author: User
Tags delete cache

For NFS-like
And AFS
This network file system, due to the impact of the network, poses certain challenges to the real-time data access and storage, especially in the early 100 Mbit/s network environment (of course, the 10 Mbit/s network environment is a bad news ). To solve the problem of response effectiveness, a type is called cachefs.
The local cache scheme is developed to provide the local cache of the Distributed File System.

A cachefs implementation mechanism as part of kernel 2.6.30
Already added. Currently it supports NFS and AFS, but other file systems can also benefit from this (as mentioned later)

What are FS-Cache and cachefs?

FS-Cache refers to the interface between the file system and the cache. Cachefs refers to the cache backend of FS-cache. Cachefs stores and retrieves data and uses the partition of Block devices.
Cachefs cannot be used on any file system.Required
Can be written to FS-cache. FS-Cache can use any of the caching mechanisms it wants (using the cache interface). The file system itself does not care about which caching mechanism is used. Both AFS and NFS can be modified using fscache. 2.6.30 core already contains a modified version that can use FS-cache.

Figure 1 shows a general data flow chart using FS-Cache and cachefs.


Figure 1: FS-cache, cachefs, and cachefiles

In, NFS/afs/isofs-we generally call netfs-call FS-cache, while FS-Cache calls cachefile or
Cachefs functions, which are two different data cache implementation mechanisms. Both FS-Cache can be called. In this way, the file system on the Left can directly use the cache for FC-Cache reasons.
You do not need to know the specific implementation mechanism. Note: cachefs uses the partition on the block device (here it is/dev/hda5), while cachefiles uses the default/var
/Fscache directory to cache files.

More details are provided.


Figure 2: More details about FS-cache, cachefs, and cachefiles

This figure shows how the netfs File System communicates with FS-Cache and how the FS-Cache communicates with cachefs or cachefiles.
We also noticed that netfs also needs to communicate with VFS. Obviously, after all, cachefs is only used for data caching, rather than implementing a complete file system.
In Linux, all file systems need to deal with VFS to ensure that applications are transparent to different file systems.
The key concept behind FS-cache is that, before accessing a file on netfs through the cache, FS-Cache does not require the file to be fully loaded into the cache. This is because:

  • You must be able to operate without caching.
  •  

  • You must be able to open files larger than the cache size.
  •  

  • The size of all open remote files should not be limited by the cache size
  •  

  • If you only access a remote part at a time, you should not force the user to cache the entire file.

Therefore, FS-cache is based on the concept of pages, rather than files. Otherwise, the entire file needs to be cached even if the content of one byte is read. The implementation of FS-cache provides the following features:

  • Multiple caches can be used. Identify by tag
  •  

  • The cache can be shared among multiple netfs instances. When sharing, the data shared by each netfs is independent of each other. In addition, it does not associate the attempt of the same file. For example, if a file is read by both NFS and CIFS, there will be two copies in the cache.
  • Add or delete cache at any time
  •  

  • Netfs provides an interface to allow any party to roll back the cache from the fileNetfs
    Is provided with an interface that allows either party (Netfs
    Or FS-Cache) to withdraw caching facilities from a file
  •  

  • The netfs interface should return as few errors as possible, rather than the interface toNetfs
    Returns as few errors as possible, preferring to letNetfs
    Remain oblivious
  •  

  • Data Io directly deals with the page of netfs
  •  

  • Asynchronous as much as possible

Use cachefs or cachefiles

 
Use FS-Cache
And cachefs/cachefiles are quite simple. First, ensure that the kernel is supported. You can check the. config file in the kernel source code directory.
. Make sure that both FS-Cache and cachefs are selected. In addition, make sure that the NFS client caching support is selected.

Step 2: Ensure that nfsutils
Is the latest. We recommend that you download the latest version and compile and install it.
Step 3: Compile and install the latest cachefilesd
. The latest version is 0.9. To install cachefilesd, you need to create the/etc/cachefilesd. conf file to control the behavior of FS-Cache and cachefs (or cachefiles. The format is very simple. For details, please slam this howto
Documentation.

The first step in the configuration file is to define the cache location. You can define the cache location on the system installation partition. Of course, you can use the SD card or USB hard disk as the cache path, however, the performance may be
It will be worse. Of course, if there is free space on the machine, it would be nice to use the new partition for the storage path. If you have enough money, using a solid state disk (SSD) will provide better performance.
The example here is to use a partition as a storage directory. This partition should support extended attributes.
(Xattr
). Most file systems in Linux support this feature, including ext 2/3/4, XFS, reiserfs, and JFS. ext3 is used here.
Use
Mkfs. ext3/dev/sda1
Format
Then use
Tune2fs-O user_xattr/dev/sda1
Enable the xattr feature.

Next, add the following line to/etc/fstab:

/Dev/sda1/var/fscache ext3 defaults, user_xattr 0 0

The preceding steps are applicable to both cachefs and cachefiles. The next step is to start the cachefilesd service.

% Service cachefilesd start

If no error is reported, you can see the following two newly created directories in the/var/fscache directory:

  • Cache
  •  

  • Graveyard

If you view the/var/fscache/cache directory, you will see some strange file names, which means everything has been okay so far. However, before using the files you see, make sure that netfs uses the cache.

For example, NFS can use FS-Cache and cachefs/cachefiles. Only one FSC Mount parameter is required. Like the following command: % Mount-o fsc bigserver:/group-data/mnt/group-Data

Here, "bigserver" is the machine name of the NFS server, And/group-data is the shared directory for export. The client mounts it to the/mnt/group-data directory. The key is the-o fsc parameter.

After netfs is mounted, the cache does not automatically start to work. The cache will only work after a read or write operation occurs, if you see the newly created file in/var/fscache/cache, it indicates that the cache function has been activated.

The cache does not concern which version is used when you mount nfs. V2, V3, and V4 are supported, but there are some differences:
For V2 and V3, direct Io and concurrent write are not supported due to Protocol restrictions.
NFS V4 provides a good lock mechanism to support write caching or direct Io. Therefore, make sure that the version used during mounting is v4.

So how do I continue to work in cachefs? We have some statistical and observation methods. First, make sure that the cache is activated using the above method. In the/proc file system, there are some statistics in it. If you want to view this information, first make sure that the core you run opens the following two parameters:

  • Config_fscache_stats = y
  •  

  • Config_fscache_histogram = y

Then you can see some information from the following two locations:

  • /Proc/fs/fscache/stats
  •  

  • /Proc/fs/fscache/histograms

For more information, see the relevant documentation.

Summary

This document provides a general introduction to FS-Cache and cachefs. The goal of FS-cache is to provide
At the same time, the original newspaper file system is irrelevant to the cache mechanism. While cachefs is actually used to cache the file system, which is used by FS-cache to call the function as a cache.
Cachefs uses block device partitions to store cached data. Of course, FS-Cache can also use cachefiles as a cache function.

Cachefs has entered the 2.6.30 official core, which will be used in the new file system. Both NFS and AFS are ready to use FS-Cache + cachefs/cachefiles.

Another field of use of FS-cache is to cache local file systems. Currently, file systems rely on the kernel to cache data and schedule Io operations. cache is not directly controlled by you.
When FS-Cache uses a very large cache (much larger than the disk cache), The read performance is greatly improved, and for file systems with good write performance, for example, nilfs
, Using FS-Cache and cachefs can also significantly improve read performance.

However, the local system may need to shut down the automatic backup function to ensure that data is written from the cache to the actual file system.

Another use area of FS-cahce and cachefs/cachefiles is the compression of file systems-such as squashfs
-Impact. Squashfs is a compressed file system that adopts read-only mounting. Because FS-Cache does help improve read performance, it is advantageous to combine it with squashfs.
In addition, squashfs can be modified after FS-cache is used.

Finally, if you use NFS on the desktop, laptop, and client, you have enough reason to try FS-Cache and cachefs/cachefiles, which can improve your performance.

Most of the content in this article is translated from http://www.linux-mag.com/id/7378/1/

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.