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 12/16] vfs: add one ioctl interface
Date: Thu, 20 Dec 2012 22:43:31 +0800 [thread overview]
Message-ID: <1356014615-15073-13-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>
FS_IOC_GET_HEAT_INFO: return a struct containing the various
metrics collected in hot_freq_data structs, and also return a
calculated data temperature based on those metrics. Optionally, retrieve
the temperature from the hot data hash list instead of recalculating it.
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
---
fs/compat_ioctl.c | 5 +++
fs/ioctl.c | 74 ++++++++++++++++++++++++++++++++++++++++++
include/linux/hot_tracking.h | 19 +++++++++++
3 files changed, 98 insertions(+), 0 deletions(-)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index e2f57a0..a55a885 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -57,6 +57,7 @@
#include <linux/i2c-dev.h>
#include <linux/atalk.h>
#include <linux/gfp.h>
+#include <linux/hot_tracking.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci.h>
@@ -1403,6 +1404,9 @@ COMPATIBLE_IOCTL(TIOCSTART)
COMPATIBLE_IOCTL(TIOCSTOP)
#endif
+/*Hot data tracking*/
+COMPATIBLE_IOCTL(FS_IOC_GET_HEAT_INFO)
+
/* fat 'r' ioctls. These are handled by fat with ->compat_ioctl,
but we don't want warnings on other file systems. So declare
them as compatible here. */
@@ -1582,6 +1586,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
case FIBMAP:
case FIGETBSZ:
case FIONREAD:
+ case FS_IOC_GET_HEAT_INFO:
if (S_ISREG(f.file->f_path.dentry->d_inode->i_mode))
break;
/*FALL THROUGH*/
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 3bdad6d..79fe81f 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -15,6 +15,7 @@
#include <linux/writeback.h>
#include <linux/buffer_head.h>
#include <linux/falloc.h>
+#include <linux/hot_tracking.h>
#include <asm/ioctls.h>
@@ -537,6 +538,76 @@ static int ioctl_fsthaw(struct file *filp)
}
/*
+ * Retrieve information about access frequency for the given file. Return it in
+ * a userspace-friendly struct for btrfsctl (or another tool) to parse.
+ *
+ * The temperature that is returned can be "live" -- that is, recalculated when
+ * the ioctl is called -- or it can be returned from the hashtable, reflecting
+ * the (possibly old) value that the system will use when considering files
+ * for migration. This behavior is determined by hot_heat_info->live.
+ */
+static int ioctl_heat_info(struct file *file, void __user *argp)
+{
+ struct inode *inode = file->f_dentry->d_inode;
+ struct hot_heat_info heat_info;
+ struct hot_inode_item *he;
+ int ret = 0;
+
+ if (copy_from_user((void *)&heat_info,
+ argp,
+ sizeof(struct hot_heat_info)) != 0) {
+ ret = -EFAULT;
+ goto err;
+ }
+
+ he = hot_inode_item_lookup(inode->i_sb->s_hot_root, inode->i_ino);
+ if (!he) {
+ /* we don't have any info on this file yet */
+ ret = -ENODATA;
+ goto err;
+ }
+
+ spin_lock(&he->hot_inode.lock);
+ heat_info.avg_delta_reads =
+ (__u64) he->hot_inode.hot_freq_data.avg_delta_reads;
+ heat_info.avg_delta_writes =
+ (__u64) he->hot_inode.hot_freq_data.avg_delta_writes;
+ heat_info.last_read_time =
+ (__u64) timespec_to_ns(&he->hot_inode.hot_freq_data.last_read_time);
+ heat_info.last_write_time =
+ (__u64) timespec_to_ns(&he->hot_inode.hot_freq_data.last_write_time);
+ heat_info.num_reads =
+ (__u32) he->hot_inode.hot_freq_data.nr_reads;
+ heat_info.num_writes =
+ (__u32) he->hot_inode.hot_freq_data.nr_writes;
+
+ if (heat_info.live > 0) {
+ /*
+ * got a request for live temperature,
+ * call hot_hash_calc_temperature to recalculate
+ */
+ heat_info.temp =
+ inode->i_sb->s_hot_root->hot_type->ops.hot_temp_calc_fn(
+ &he->hot_inode.hot_freq_data);
+ } else {
+ /* not live temperature, get it from the hashlist */
+ heat_info.temp = he->hot_inode.hot_freq_data.last_temp;
+ }
+ spin_unlock(&he->hot_inode.lock);
+
+ hot_inode_item_put(he);
+
+ if (copy_to_user(argp, (void *)&heat_info,
+ sizeof(struct hot_heat_info))) {
+ ret = -EFAULT;
+ goto err;
+ }
+
+err:
+ return ret;
+}
+
+/*
* When you add any new common ioctls to the switches above and below
* please update compat_sys_ioctl() too.
*
@@ -591,6 +662,9 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
case FIGETBSZ:
return put_user(inode->i_sb->s_blocksize, argp);
+ case FS_IOC_GET_HEAT_INFO:
+ return ioctl_heat_info(filp, argp);
+
default:
if (S_ISREG(inode->i_mode))
error = file_ioctl(filp, cmd, arg);
diff --git a/include/linux/hot_tracking.h b/include/linux/hot_tracking.h
index 36dac41..bd55a34 100644
--- a/include/linux/hot_tracking.h
+++ b/include/linux/hot_tracking.h
@@ -43,6 +43,17 @@ struct hot_freq_data {
u32 last_temp;
};
+struct hot_heat_info {
+ __u64 avg_delta_reads;
+ __u64 avg_delta_writes;
+ __u64 last_read_time;
+ __u64 last_write_time;
+ __u32 num_reads;
+ __u32 num_writes;
+ __u32 temp;
+ __u8 live;
+};
+
/* List heads in hot map array */
struct hot_map_head {
struct list_head node_list;
@@ -113,6 +124,14 @@ struct hot_info {
struct shrinker hot_shrink;
};
+/*
+ * Hot data tracking ioctls:
+ *
+ * HOT_INFO - retrieve info on frequency of access
+ */
+#define FS_IOC_GET_HEAT_INFO _IOR('f', 17, \
+ struct hot_heat_info)
+
extern void __init hot_cache_init(void);
extern int hot_track_init(struct super_block *sb);
extern void hot_track_exit(struct super_block *sb);
--
1.7.6.5
next prev parent reply other threads:[~2012-12-20 14:43 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 ` [PATCH RESEND v1 10/16] vfs: add FS hot type support zwu.kernel
2012-12-20 14:43 ` [PATCH RESEND v1 11/16] vfs: register one shrinker zwu.kernel
2012-12-20 14:43 ` zwu.kernel [this message]
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-13-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).