Skip to content

Added code for custom file prefetching #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fs/nfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ obj-$(CONFIG_NFS_FS) += nfs.o
CFLAGS_nfstrace.o += -I$(src)
nfs-y := client.o dir.o file.o getroot.o inode.o super.o \
direct.o pagelist.o read.o symlink.o unlink.o \
write.o namespace.o mount_clnt.o nfstrace.o
write.o namespace.o mount_clnt.o nfstrace.o prefetch.o
nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
nfs-$(CONFIG_SYSCTL) += sysctl.o
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
Expand Down
1 change: 1 addition & 0 deletions fs/nfs/nfs4_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ extern char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN];
/* nfs4sysctl.c */
#ifdef CONFIG_SYSCTL
int nfs4_register_sysctl(void);
int prefetch_register_sysctl(void);
void nfs4_unregister_sysctl(void);
#else
static inline int nfs4_register_sysctl(void)
Expand Down
4 changes: 4 additions & 0 deletions fs/nfs/nfs4super.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ static int __init init_nfs_v4(void)
if (err)
goto out2;

err = prefetch_register_sysctl();
if (err)
goto out2;

register_nfs_version(&nfs_v4);
return 0;
out2:
Expand Down
53 changes: 53 additions & 0 deletions fs/nfs/prefetch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/nfs_fs.h>
#include <linux/nfs_fs_sb.h>
#include <linux/in6.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/sysctl.h>

#include "internal.h"
#include "iostat.h"
#include "fscache.h"


static int global_var;
static int min_val = 0;
static int max_val = 5;

static struct ctl_table prefetch_child_table[] = {
{
//.ctl_name = CTL_UNNUMBERED,
.procname = "prefetch",
.maxlen = sizeof(int),
.mode = 0644,
.data = &global_var,
.proc_handler = &proc_dointvec_minmax,
.extra1 = &min_val,
.extra2 = &max_val,
},
{}
};

static struct ctl_table prefetch_parent_table[] = {
{
//.ctl_name = CTL_KERN,
.procname = "kernel",
.mode = 0555,
.child = prefetch_child_table,
},
{}
};

int prefetch_register_sysctl(void)
{
/* register the above sysctl */
if (!register_sysctl_table(prefetch_parent_table)) {
printk(KERN_ALERT "Error: Failed to register sample_parent_table\n");
return -EFAULT;
}
return 0;
}
6 changes: 6 additions & 0 deletions mm/filemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,12 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
loff_t *ppos = &iocb->ki_pos;
loff_t pos = *ppos;

if (file->f_path.dentry) {
if (strstr(file->f_path.dentry->d_name.name, ".tar")) {
printk("RDTSC=%llu\n", (unsigned long long)rdtsc());
}
}

if (iocb->ki_flags & IOCB_DIRECT) {
struct address_space *mapping = file->f_mapping;
struct inode *inode = mapping->host;
Expand Down
37 changes: 37 additions & 0 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
#include <asm/div64.h>
#include "internal.h"

unsigned long lt = 0;
unsigned long st = 0;

/* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */
static DEFINE_MUTEX(pcp_batch_high_lock);
#define MIN_PERCPU_PAGELIST_FRACTION (8)
Expand Down Expand Up @@ -2068,17 +2071,51 @@ void free_hot_cold_page(struct page *page, bool cold)
local_irq_restore(flags);
}

void update(unsigned long sum, unsigned long count)
{
unsigned long avg;

if (sum == 0 || count == 0) {
return;
}

avg = sum / count;
st = avg;
}

/*
* Free a list of 0-order pages
*/
void free_hot_cold_page_list(struct list_head *list, bool cold)
{
struct page *page, *next;
struct address_space *mapping;
struct inode *inode1;
struct timespec t1, now;
unsigned long sum = 0, count = 0;

list_for_each_entry_safe(page, next, list, lru) {
printk("Freeing pages\n");
mapping = page->mapping;
if (!mapping) {
printk("No mapping\n");
goto out;
}
inode1 = mapping->host;
if (!inode1) {
printk("No inode associated\n");
goto out;
}
t1 = inode1->i_atime;
getnstimeofday(&now);
sum += now.tv_sec - t1.tv_sec;
count++;

out:
trace_mm_page_free_batched(page, cold);
free_hot_cold_page(page, cold);
}
update(sum, count);
}

/*
Expand Down