]> git.ipfire.org Git - people/arne_f/kernel.git/blame - fs/drop_caches.c
MIPS: AR7: Ensure that serial ports are properly set up
[people/arne_f/kernel.git] / fs / drop_caches.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
9d0243bc
AM
2/*
3 * Implement the manual drop-all-pagecache function
4 */
5
6#include <linux/kernel.h>
7#include <linux/mm.h>
8#include <linux/fs.h>
9#include <linux/writeback.h>
10#include <linux/sysctl.h>
11#include <linux/gfp.h>
55fa6091 12#include "internal.h"
9d0243bc
AM
13
14/* A global variable is a bit ugly, but it keeps the code simple */
15int sysctl_drop_caches;
16
01a05b33 17static void drop_pagecache_sb(struct super_block *sb, void *unused)
9d0243bc 18{
eccb95ce 19 struct inode *inode, *toput_inode = NULL;
9d0243bc 20
74278da9 21 spin_lock(&sb->s_inode_list_lock);
9d0243bc 22 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
250df6ed
DC
23 spin_lock(&inode->i_lock);
24 if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) ||
25 (inode->i_mapping->nrpages == 0)) {
26 spin_unlock(&inode->i_lock);
af065b8a 27 continue;
250df6ed 28 }
eccb95ce 29 __iget(inode);
250df6ed 30 spin_unlock(&inode->i_lock);
74278da9
DC
31 spin_unlock(&sb->s_inode_list_lock);
32
28697355 33 invalidate_mapping_pages(inode->i_mapping, 0, -1);
eccb95ce
JK
34 iput(toput_inode);
35 toput_inode = inode;
74278da9
DC
36
37 spin_lock(&sb->s_inode_list_lock);
9d0243bc 38 }
74278da9 39 spin_unlock(&sb->s_inode_list_lock);
eccb95ce 40 iput(toput_inode);
9d0243bc
AM
41}
42
1f7e0616 43int drop_caches_sysctl_handler(struct ctl_table *table, int write,
8d65af78 44 void __user *buffer, size_t *length, loff_t *ppos)
9d0243bc 45{
cb16e95f
PH
46 int ret;
47
48 ret = proc_dointvec_minmax(table, write, buffer, length, ppos);
49 if (ret)
50 return ret;
9d0243bc 51 if (write) {
5509a5d2
DH
52 static int stfu;
53
54 if (sysctl_drop_caches & 1) {
01a05b33 55 iterate_supers(drop_pagecache_sb, NULL);
5509a5d2
DH
56 count_vm_event(DROP_PAGECACHE);
57 }
58 if (sysctl_drop_caches & 2) {
9d0243bc 59 drop_slab();
5509a5d2
DH
60 count_vm_event(DROP_SLAB);
61 }
62 if (!stfu) {
63 pr_info("%s (%d): drop_caches: %d\n",
64 current->comm, task_pid_nr(current),
65 sysctl_drop_caches);
66 }
67 stfu |= sysctl_drop_caches & 4;
9d0243bc
AM
68 }
69 return 0;
70}