Features Download
From: <zwu.kernel <at> gmail.com>
Subject: [RFC v1 00/11] vfs: hot data tracking
Newsgroups: gmane.linux.kernel
Date: Monday 17th September 2012 07:18:34 UTC (over 4 years ago)
From: Zhi Yong Wu <[email protected]>


  The patchset is currently post out mainly to make sure
it is going in the correct direction and hope to get some
helpful comments from other guys.

TODO List:

 1.) Need to do scalability or performance tests.
 2.) Turn some Micro into tunables
 3.) Rafactor hot_hash_is_aging()
       If you just made the timeout value a timespec and compared
     the _timespecs_, you would be doing a lot fewer conversions.
 4.) Cleanup some unnecessary lock protect
 5.) Add more comments to explain how to calc temperature

Ben Chociej, Matt Lupfer and Conor Scott originally wrote this code to
 be very btrfs-specific.  I've taken their code and attempted to
make it more generic and integrate it at the VFS level.


  Essentially, this means maintaining some key stats
(like number of reads/writes, last read/write time, frequency of
reads/writes), then distilling those numbers down to a single
"temperature" value that reflects what data is "hot," and using that
temperature to move data to SSDs.

  The long-term goal of these patches is to allow some FSs,
e.g. Btrfs to intelligently utilize SSDs in a heterogenous volume.
Incidentally, this project has been motivated by
the Project Ideas page on the Btrfs wiki.

  Of course, users are warned not to run this code outside of development
environments. These patches are EXPERIMENTAL, and as such they might eat
your data and/or memory. That said, the code should be relatively safe
when the hottrack mount option are disabled.


  The overall goal of enabling hot data relocation to SSD has been
motivated by the Project Ideas page on the Btrfs wiki at
It will divide into two steps. VFS provide hot data tracking function
while specific FS will provide hot data relocation function.
So as the first step of this goal, it is hoped that the patchset
for hot data tracking will eventually mature into VFS.

  This is essentially the traditional cache argument: SSD is fast and
expensive; HDD is cheap but slow. ZFS, for example, can already take
advantage of SSD caching. Btrfs should also be able to take advantage of
hybrid storage without many broad, sweeping changes to existing code.


- Hooks in existing vfs functions to track data access frequency

- New rbtrees for tracking access frequency of inodes and sub-file
ranges (hot_rb.c)
    The relationship between super_block and rbtree is as below:
    In include/linux/fs.h, one struct hot_info s_hotinfo is added to
  super_block struct. Each FS instance can find hot tracking info
  s_hotinfo via its super_block. In this hot_info, it store a lot of hot
  tracking info such as hot_inode_tree, inode and range hash list, etc.

- A hash list for indexing data by its temperature (hot_hash.c)

- A debugfs interface for dumping data from the rbtrees (hot_debugfs.c)

- A background kthread for updating inode heat info

- Mount options for enabling temperature tracking(-o hottrack, default mean

- An ioctl to retrieve the frequency information collected for a certain

- Ioctls to enable/disable frequency tracking per inode.

Usage syntax:

[email protected]:~# mount -o hottrack /dev/sdb /mnt
[ 1505.894078] device label test devid 1 transid 29 /dev/sdb
[ 1505.952977] btrfs: disk space caching is enabled
[ 1506.069678] vfs: turning on hot data tracking
[email protected]:~# mount -t debugfs none /sys/kernel/debug
[email protected]:~# ls -l /sys/kernel/debug/vfs_hotdata/
total 0
drwxr-xr-x 2 root root 0 Aug  8 04:40 sdb
[email protected]:~# ls -l /sys/kernel/debug/vfs_hotdata/sdb
total 0
-rw-r--r-- 1 root root 0 Aug  8 04:40 inode_data
-rw-r--r-- 1 root root 0 Aug  8 04:40 range_data
[email protected]:~# vi /mnt/file
[email protected]:~# cat /sys/kernel/debug/hot_track/sdb/inode_data
inode #279, reads 0, writes 1, avg read time 18446744073709551615,
avg write time 5251566408153596, temp 109
[email protected]:~# cat /sys/kernel/debug/hot_track/sdb/range_data
inode #279, range start 0 (range len 1048576) reads 0, writes 1,
avg read time 18446744073709551615, avg write time 1128690176623144209,
temp 64
[email protected]:~# echo "hot data tracking test" >> /mnt/file
[email protected]:~# cat /sys/kernel/debug/hot_track/sdb/inode_data
inode #279, reads 0, writes 2, avg read time 18446744073709551615,
avg write time 4923343766042451, temp 109
[email protected]:~# cat /sys/kernel/debug/hot_track/sdb/range_data
inode #279, range start 0 (range len 1048576) reads 0, writes 2,
avg read time 18446744073709551615, avg write time 1058147040842596150,
temp 64
[email protected]:~#

Changelog from v2:
  1.) Adjust the code based on Ram's comments. [Ram Pai]
  1.) refactor the code based on Dave, Mingming and Ram's sugestions.
                                  [Dave Hansen, Mingming Cao, and Ram Pai]
  1.) refactor the code based on Dave's sugestions. [Dave Hansen]
  2.) fix up some bugs.

Zhi Yong Wu (11):
  vfs: introduce one structure hot_info
  vfs: introduce one rb tree - hot_inode_tree
  vfs: introduce 2 rb tree items - inode and range
  vfs: add support for updating access frequency
  vfs: add one new mount option '-o hottrack'
  vfs: add init and exit support
  vfs: introduce one hash table
  vfs: enable hot data tracking
  vfs: fork one private kthread to update temperature info
  vfs: add 3 new ioctl interfaces
  vfs: add debugfs support

 fs/Makefile               |    3 +-
 fs/compat_ioctl.c         |    8 +
 fs/dcache.c               |    2 +
 fs/direct-io.c            |   10 +
 fs/hot_debugfs.c          |  487 ++++++++++++++++++++++++++++++++++
 fs/hot_debugfs.h          |   60 +++++
 fs/hot_hash.c             |  369 ++++++++++++++++++++++++++
 fs/hot_hash.h             |  108 ++++++++
 fs/hot_rb.c               |  648
 fs/hot_rb.h               |   70 +++++
 fs/hot_track.c            |  113 ++++++++
 fs/hot_track.h            |   23 ++
 fs/ioctl.c                |  132 +++++++++
 fs/namespace.c            |   10 +
 fs/super.c                |   11 +
 include/linux/fs.h        |   15 +
 include/linux/hot_track.h |  169 ++++++++++++
 mm/filemap.c              |    8 +
 mm/page-writeback.c       |   21 ++
 mm/readahead.c            |    9 +
 20 files changed, 2275 insertions(+), 1 deletions(-)
 create mode 100644 fs/hot_debugfs.c
 create mode 100644 fs/hot_debugfs.h
 create mode 100644 fs/hot_hash.c
 create mode 100644 fs/hot_hash.h
 create mode 100644 fs/hot_rb.c
 create mode 100644 fs/hot_rb.h
 create mode 100644 fs/hot_track.c
 create mode 100644 fs/hot_track.h
 create mode 100644 include/linux/hot_track.h

CD: 3ms