Statistic Module Shuanglong Zhang 04/23/2013 Overview • Device Mapper • procfs • bio control Device Mapper • A mechanism from linux 2.6 • The base of LVM, RAID • dm-linear dm-statistic Can be infinite iteration Don't do this! My implementation dm-statistic procfs • Used to "communicate" with user space • /proc/statistic • /proc/jiffies • A drawback of procfs Drawback • Can not exceed one page size • How to deal with large data • seq_file seq_file interface • Deal with large data, work with procfs • Abstract those data to a mount of items – (array, list, hash) • Simplify the read operation static struct seq_operations seq_ops = { .start = statistic_seq_start, .next = statistic_seq_next, .stop = statistic_seq_stop, .show = statistic_seq_show }; start->show->next->show->...->next->show->stop static struct file_operations seq_fops = { .owner = THIS_MODULE, .open = statistic_open, .read = seq_read, //.write = seq_write, .llseek = seq_lseek, .release = seq_release, }; static int statistic_open(struct inode *inode, struct file *file) { return (seq_open(file, &seq_ops)); } Control on bio • Diffrent ways to do it – These kind of control can happen at any stage from a request begins to it ends. - VFS - FS - DM - BLOCK In device mapper • A bio comes in • Map the bio to the dest – delay it if necessary(read, full) – until there is another room for a bio • Go into block layer Delay • Create another list for write bio • Track back to x bios or 1 second controled by a module parameter • Wait till there is less then x bios in past second User space tool • dmsetup • statistic dmsetup • dmsetup [linear/stripe/statistic] /dev/sda10 • dmsetup remove /dev/mapper/statistic • use sudo! statistic • Get the statistic info from /proc/statistic • Two ways of querying – last x second – from x second to y second • Total, Read, Write Left Problems • module parameter • ioctl function(reset base_time) • more info on bio Demo Q&A