From: zwu.kernel@gmail.com
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
david@fromorbit.com, dave@jikos.cz, darrick.wong@oracle.com,
andi@firstfloor.org, hch@infradead.org,
linuxram@linux.vnet.ibm.com, zwu.kernel@gmail.com,
wuzhy@linux.vnet.ibm.com
Subject: [PATCH RESEND v1 10/16] vfs: add FS hot type support
Date: Thu, 20 Dec 2012 22:43:29 +0800 [thread overview]
Message-ID: <1356014615-15073-11-git-send-email-zwu.kernel@gmail.com> (raw)
In-Reply-To: <1356014615-15073-1-git-send-email-zwu.kernel@gmail.com>
From: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Introduce one way to enable that specific FS
can inject its own hot tracking type.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
fs/hot_tracking.c | 43 +++++++++++++++++++++++++++++++----------
fs/hot_tracking.h | 1 -
include/linux/fs.h | 1 +
include/linux/hot_tracking.h | 19 ++++++++++++++++++
4 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/fs/hot_tracking.c b/fs/hot_tracking.c
index 383cc54..07a2a81 100644
--- a/fs/hot_tracking.c
+++ b/fs/hot_tracking.c
@@ -64,8 +64,11 @@ void hot_range_tree_init(struct hot_inode_item *he)
static void hot_range_item_init(struct hot_range_item *hr, loff_t start,
struct hot_inode_item *he)
{
+ struct hot_info *root = container_of(he->hot_inode_tree,
+ struct hot_info, hot_inode_tree);
+
hr->start = start;
- hr->len = RANGE_SIZE;
+ hr->len = hot_raw_shift(1, root->hot_type->range_bits, true);
hr->hot_inode = he;
kref_init(&hr->hot_range.refs);
spin_lock_init(&hr->hot_range.lock);
@@ -305,19 +308,21 @@ static void hot_rw_freq_calc(struct timespec old_atime,
*avg = *avg >> FREQ_POWER;
}
-static void hot_freq_data_update(struct hot_freq_data *freq_data, bool write)
+static void hot_freq_data_update(struct hot_info *root,
+ struct hot_freq_data *freq_data, bool write)
{
struct timespec cur_time = current_kernel_time();
if (write) {
freq_data->nr_writes += 1;
- hot_rw_freq_calc(freq_data->last_write_time,
+ root->hot_type->ops.hot_rw_freq_calc_fn(
+ freq_data->last_write_time,
cur_time,
&freq_data->avg_delta_writes);
freq_data->last_write_time = cur_time;
} else {
freq_data->nr_reads += 1;
- hot_rw_freq_calc(freq_data->last_read_time,
+ root->hot_type->ops.hot_rw_freq_calc_fn(
freq_data->last_read_time,
cur_time,
&freq_data->avg_delta_reads);
@@ -421,7 +426,7 @@ static void hot_map_update(struct hot_freq_data *freq_data,
struct hot_comm_item *comm_item;
struct hot_inode_item *he;
struct hot_range_item *hr;
- u32 temp = hot_temp_calc(freq_data);
+ u32 temp = root->hot_type->ops.hot_temp_calc_fn(freq_data);
u8 a_temp = (u8)hot_raw_shift((u64)temp, (32 - HEAT_MAP_BITS), false);
u8 b_temp = (u8)hot_raw_shift((u64)freq_data->last_temp,
(32 - HEAT_MAP_BITS), false);
@@ -494,7 +499,7 @@ static void hot_range_update(struct hot_inode_item *he,
hot_map_update(&hr->hot_range.hot_freq_data, root);
spin_lock(&hr->hot_range.lock);
- obsolete = hot_is_obsolete(
+ obsolete = root->hot_type->ops.hot_is_obsolete_fn(
&hr->hot_range.hot_freq_data);
spin_unlock(&hr->hot_range.lock);
@@ -647,6 +652,7 @@ void hot_update_freqs(struct inode *inode, loff_t start,
struct hot_info *root = inode->i_sb->s_hot_root;
struct hot_inode_item *he;
struct hot_range_item *hr;
+ u64 range_size;
loff_t cur, end;
if (!root || (len == 0))
@@ -659,15 +665,19 @@ void hot_update_freqs(struct inode *inode, loff_t start,
}
spin_lock(&he->hot_inode.lock);
- hot_freq_data_update(&he->hot_inode.hot_freq_data, rw);
+ hot_freq_data_update(root, &he->hot_inode.hot_freq_data, rw);
spin_unlock(&he->hot_inode.lock);
/*
- * Align ranges on RANGE_SIZE boundary
+ * Align ranges on range size boundary
* to prevent proliferation of range structs
*/
- end = (start + len + RANGE_SIZE - 1) >> RANGE_BITS;
- for (cur = (start >> RANGE_BITS); cur < end; cur++) {
+ range_size = hot_raw_shift(1,
+ root->hot_type->range_bits, true);
+ end = hot_raw_shift((start + len + range_size - 1),
+ root->hot_type->range_bits, false);
+ cur = hot_raw_shift(start, root->hot_type->range_bits, false);
+ for (; cur < end; cur++) {
hr = hot_range_item_lookup(he, cur);
if (IS_ERR(hr)) {
WARN(1, "hot_range_item_lookup returns %ld\n",
@@ -677,7 +687,7 @@ void hot_update_freqs(struct inode *inode, loff_t start,
}
spin_lock(&hr->hot_range.lock);
- hot_freq_data_update(&hr->hot_range.hot_freq_data, rw);
+ hot_freq_data_update(root, &hr->hot_range.hot_freq_data, rw);
spin_unlock(&hr->hot_range.lock);
hot_range_item_put(hr);
@@ -705,6 +715,17 @@ int hot_track_init(struct super_block *sb)
hot_inode_tree_init(root);
hot_map_init(root);
+ /* Get hot type for specific FS */
+ root->hot_type = &sb->s_type->hot_type;
+ if (!root->hot_type->ops.hot_rw_freq_calc_fn)
+ root->hot_type->ops.hot_rw_freq_calc_fn = hot_rw_freq_calc;
+ if (!root->hot_type->ops.hot_temp_calc_fn)
+ root->hot_type->ops.hot_temp_calc_fn = hot_temp_calc;
+ if (!root->hot_type->ops.hot_is_obsolete_fn)
+ root->hot_type->ops.hot_is_obsolete_fn = hot_is_obsolete;
+ if (root->hot_type->range_bits == 0)
+ root->hot_type->range_bits = RANGE_BITS;
+
root->update_wq = alloc_workqueue(
"hot_update_wq", WQ_NON_REENTRANT, 0);
if (!root->update_wq) {
diff --git a/fs/hot_tracking.h b/fs/hot_tracking.h
index 96379a6..73d2a3e 100644
--- a/fs/hot_tracking.h
+++ b/fs/hot_tracking.h
@@ -21,7 +21,6 @@
/* size of sub-file ranges */
#define RANGE_BITS 20
-#define RANGE_SIZE (1 << RANGE_BITS)
#define FREQ_POWER 4
/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index c42dc37..a8cb14e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1821,6 +1821,7 @@ struct file_system_type {
struct dentry *(*mount) (struct file_system_type *, int,
const char *, void *);
void (*kill_sb) (struct super_block *);
+ struct hot_type hot_type;
struct module *owner;
struct file_system_type * next;
struct hlist_head fs_supers;
diff --git a/include/linux/hot_tracking.h b/include/linux/hot_tracking.h
index 1feead2..003af47 100644
--- a/include/linux/hot_tracking.h
+++ b/include/linux/hot_tracking.h
@@ -79,6 +79,24 @@ struct hot_range_item {
size_t len; /* length in bytes */
};
+typedef void (hot_rw_freq_calc_fn) (struct timespec old_atime,
+ struct timespec cur_time, u64 *avg);
+typedef u32 (hot_temp_calc_fn) (struct hot_freq_data *freq_data);
+typedef bool (hot_is_obsolete_fn) (struct hot_freq_data *freq_data);
+
+struct hot_func_ops {
+ hot_rw_freq_calc_fn *hot_rw_freq_calc_fn;
+ hot_temp_calc_fn *hot_temp_calc_fn;
+ hot_is_obsolete_fn *hot_is_obsolete_fn;
+};
+
+/* identifies an hot type */
+struct hot_type {
+ u64 range_bits;
+ /* fields provided by specific FS */
+ struct hot_func_ops ops;
+};
+
struct hot_info {
struct hot_rb_tree hot_inode_tree;
spinlock_t lock; /*protect inode tree */
@@ -91,6 +109,7 @@ struct hot_info {
struct workqueue_struct *update_wq;
struct delayed_work update_work;
+ struct hot_type *hot_type;
};
extern void __init hot_cache_init(void);
--
1.7.6.5
next prev parent reply other threads:[~2012-12-20 14:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-20 14:43 [PATCH RESEND v1 00/16] vfs: hot data tracking zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 01/16] vfs: introduce some data structures zwu.kernel
2013-01-10 0:48 ` David Sterba
2013-01-10 6:24 ` Zhi Yong Wu
2012-12-20 14:43 ` [PATCH RESEND v1 02/16] vfs: add init and cleanup functions zwu.kernel
2013-01-10 0:48 ` David Sterba
2013-01-11 7:21 ` Zhi Yong Wu
2012-12-20 14:43 ` [PATCH RESEND v1 03/16] vfs: add I/O frequency update function zwu.kernel
2013-01-10 0:51 ` David Sterba
2013-01-11 7:38 ` Zhi Yong Wu
2013-01-11 14:27 ` David Sterba
2013-01-11 14:54 ` Zhi Yong Wu
2012-12-20 14:43 ` [PATCH RESEND v1 04/16] vfs: add two map arrays zwu.kernel
2013-01-10 0:51 ` David Sterba
2012-12-20 14:43 ` [PATCH RESEND v1 05/16] vfs: add hooks to enable hot tracking zwu.kernel
2013-01-10 0:52 ` David Sterba
2013-01-11 7:47 ` Zhi Yong Wu
2012-12-20 14:43 ` [PATCH RESEND v1 06/16] vfs: add temp calculation function zwu.kernel
2013-01-10 0:53 ` David Sterba
2013-01-11 8:08 ` Zhi Yong Wu
2012-12-20 14:43 ` [PATCH RESEND v1 07/16] vfs: add map info update function zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 08/16] vfs: add aging function zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 09/16] vfs: add one work queue zwu.kernel
2012-12-20 14:43 ` zwu.kernel [this message]
2012-12-20 14:43 ` [PATCH RESEND v1 11/16] vfs: register one shrinker zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 12/16] vfs: add one ioctl interface zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 13/16] vfs: add debugfs support zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 14/16] proc: add two hot_track proc files zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 15/16] btrfs: add hot tracking support zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 16/16] vfs: add documentation zwu.kernel
2012-12-20 14:55 ` [PATCH RESEND v1 00/16] vfs: hot data tracking Zhi Yong Wu
2013-01-07 13:49 ` Zhi Yong Wu
2013-01-08 7:52 ` Zhi Yong Wu
2013-02-22 0:32 ` Zhi Yong Wu
2013-02-25 11:40 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356014615-15073-11-git-send-email-zwu.kernel@gmail.com \
--to=zwu.kernel@gmail.com \
--cc=andi@firstfloor.org \
--cc=darrick.wong@oracle.com \
--cc=dave@jikos.cz \
--cc=david@fromorbit.com \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxram@linux.vnet.ibm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wuzhy@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.