From mboxrd@z Thu Jan 1 00:00:00 1970 From: zwu.kernel@gmail.com Subject: [PATCH v4 05/10] VFS hot tracking: Add an ioctl to get hot tracking information Date: Mon, 5 Aug 2013 22:49:55 +0800 Message-ID: <1375714200-23944-6-git-send-email-zwu.kernel@gmail.com> References: <1375714200-23944-1-git-send-email-zwu.kernel@gmail.com> Cc: linux-fsdevel@vger.kernel.org, sekharan@us.ibm.com, Zhi Yong Wu To: viro@zeniv.linux.org.uk Return-path: Received: from e38.co.us.ibm.com ([32.97.110.159]:43239 "EHLO e38.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752706Ab3HEOu4 (ORCPT ); Mon, 5 Aug 2013 10:50:56 -0400 Received: from /spool/local by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 5 Aug 2013 08:50:55 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 5F3351FF0050 for ; Mon, 5 Aug 2013 08:45:29 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r75Eoh9m079280 for ; Mon, 5 Aug 2013 08:50:46 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r75EnPgs025213 for ; Mon, 5 Aug 2013 08:49:25 -0600 In-Reply-To: <1375714200-23944-1-git-send-email-zwu.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Zhi Yong Wu 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: Chandra Seetharaman Signed-off-by: Zhi Yong Wu --- fs/compat_ioctl.c | 5 ++++ fs/ioctl.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/hot_tracking.h | 21 ++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c index 5d19acf..9026b8a 100644 --- a/fs/compat_ioctl.c +++ b/fs/compat_ioctl.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -1399,6 +1400,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. */ @@ -1578,6 +1582,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(file_inode(f.file)->i_mode)) break; /*FALL THROUGH*/ diff --git a/fs/ioctl.c b/fs/ioctl.c index fd507fb..51a16e1 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -537,6 +538,70 @@ static int ioctl_fsthaw(struct file *filp) } /* + * Retrieve information about access frequency for the given inode. + * + * The temperature that is returned can be "live" -- that is, recalculated when + * the ioctl is called -- or it can be returned from the map list, 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; + + /* The 'live' field need to be read from the user space */ + 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, 0); + if (IS_ERR(he)) { + /* we don't have any info on this file yet */ + ret = -ENODATA; + goto err; + } + + heat_info.avg_delta_reads = + (__u64) he->freq.avg_delta_reads; + heat_info.avg_delta_writes = + (__u64) he->freq.avg_delta_writes; + heat_info.last_read_time = + (__u64) timespec_to_ns(&he->freq.last_read_time); + heat_info.last_write_time = + (__u64) timespec_to_ns(&he->freq.last_write_time); + heat_info.num_reads = (__u32) he->freq.nr_reads; + heat_info.num_writes = (__u32) he->freq.nr_writes; + + if (heat_info.live > 0) { + /* + * got a request for live temperature, + * call hot_calc_temp() to recalculate + */ + heat_info.temp = hot_temp_calc(&he->freq); + } else { + /* not live temperature, get it from the map list */ + heat_info.temp = he->freq.last_temp; + } + + 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 +656,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 adac767..e480f7d 100644 --- a/include/linux/hot_tracking.h +++ b/include/linux/hot_tracking.h @@ -18,6 +18,19 @@ #include #include +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; + __u8 resv[3]; + __u64 future[4]; /* For future expansions */ +}; + #ifdef __KERNEL__ #include @@ -88,6 +101,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.11.7