Blame view
fs/drop_caches.c
1.58 KB
9d0243bca
|
1 2 3 4 5 6 7 8 9 10 |
/* * Implement the manual drop-all-pagecache function */ #include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h> #include <linux/writeback.h> #include <linux/sysctl.h> #include <linux/gfp.h> |
55fa6091d
|
11 |
#include "internal.h" |
9d0243bca
|
12 13 14 |
/* A global variable is a bit ugly, but it keeps the code simple */ int sysctl_drop_caches; |
01a05b337
|
15 |
static void drop_pagecache_sb(struct super_block *sb, void *unused) |
9d0243bca
|
16 |
{ |
eccb95cee
|
17 |
struct inode *inode, *toput_inode = NULL; |
9d0243bca
|
18 |
|
74278da9f
|
19 |
spin_lock(&sb->s_inode_list_lock); |
9d0243bca
|
20 |
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { |
250df6ed2
|
21 22 23 24 |
spin_lock(&inode->i_lock); if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) || (inode->i_mapping->nrpages == 0)) { spin_unlock(&inode->i_lock); |
af065b8a1
|
25 |
continue; |
250df6ed2
|
26 |
} |
eccb95cee
|
27 |
__iget(inode); |
250df6ed2
|
28 |
spin_unlock(&inode->i_lock); |
74278da9f
|
29 |
spin_unlock(&sb->s_inode_list_lock); |
286973552
|
30 |
invalidate_mapping_pages(inode->i_mapping, 0, -1); |
eccb95cee
|
31 32 |
iput(toput_inode); toput_inode = inode; |
74278da9f
|
33 34 |
spin_lock(&sb->s_inode_list_lock); |
9d0243bca
|
35 |
} |
74278da9f
|
36 |
spin_unlock(&sb->s_inode_list_lock); |
eccb95cee
|
37 |
iput(toput_inode); |
9d0243bca
|
38 |
} |
1f7e0616c
|
39 |
int drop_caches_sysctl_handler(struct ctl_table *table, int write, |
8d65af789
|
40 |
void __user *buffer, size_t *length, loff_t *ppos) |
9d0243bca
|
41 |
{ |
cb16e95fa
|
42 43 44 45 46 |
int ret; ret = proc_dointvec_minmax(table, write, buffer, length, ppos); if (ret) return ret; |
9d0243bca
|
47 |
if (write) { |
5509a5d27
|
48 49 50 |
static int stfu; if (sysctl_drop_caches & 1) { |
01a05b337
|
51 |
iterate_supers(drop_pagecache_sb, NULL); |
5509a5d27
|
52 53 54 |
count_vm_event(DROP_PAGECACHE); } if (sysctl_drop_caches & 2) { |
9d0243bca
|
55 |
drop_slab(); |
5509a5d27
|
56 57 58 59 60 61 62 63 64 |
count_vm_event(DROP_SLAB); } if (!stfu) { pr_info("%s (%d): drop_caches: %d ", current->comm, task_pid_nr(current), sysctl_drop_caches); } stfu |= sysctl_drop_caches & 4; |
9d0243bca
|
65 66 67 |
} return 0; } |