Commit e56e8310 authored by Chen Wandun's avatar Chen Wandun Committed by Zheng Zengkai
Browse files

mm/page_cache_limit: add support for droping caches for target node

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4HOXK



------------------------------------------

Add a proc interface to drop cache in target node.

Signed-off-by: default avatarChen Wandun <chenwandun@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 9fea105d
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -9,12 +9,17 @@
#include <linux/writeback.h>
#include <linux/sysctl.h>
#include <linux/gfp.h>

#ifdef CONFIG_SHRINK_PAGECACHE
#include <linux/page_cache_limit.h>
#endif

#include "internal.h"

/* A global variable is a bit ugly, but it keeps the code simple */
int sysctl_drop_caches;

static void drop_pagecache_sb(struct super_block *sb, void *unused)
static void drop_pagecache_sb(struct super_block *sb, void *nid)
{
	struct inode *inode, *toput_inode = NULL;

@@ -35,7 +40,12 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
		spin_unlock(&inode->i_lock);
		spin_unlock(&sb->s_inode_list_lock);

		if (!nid)
			invalidate_mapping_pages(inode->i_mapping, 0, -1);
		else
			node_invalidate_mapping_pages(inode->i_mapping,
						      *(int *)nid, 0, -1);

		iput(toput_inode);
		toput_inode = inode;

@@ -74,3 +84,25 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
	}
	return 0;
}

#ifdef CONFIG_SHRINK_PAGECACHE
int proc_shrink_node_caches(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp, loff_t *ppos)
{
	int ret;

	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
	if (ret || !write)
		return ret;

	if (node_to_shrink >= MAX_NUMNODES)
		return -EINVAL;

	if (!node_isset(node_to_shrink, node_states[N_MEMORY]))
		return 0;

	iterate_supers(drop_pagecache_sb, &node_to_shrink);

	return 0;
}
#endif
+9 −0
Original line number Diff line number Diff line
@@ -2613,6 +2613,15 @@ extern bool is_bad_inode(struct inode *);
unsigned long invalidate_mapping_pages(struct address_space *mapping,
					pgoff_t start, pgoff_t end);

#ifdef CONFIG_SHRINK_PAGECACHE
unsigned long node_invalidate_mapping_pages(struct address_space *mapping,
					int nid, pgoff_t start, pgoff_t end);
#else
static inline unsigned long
node_invalidate_mapping_pages(struct address_space *mapping, int nid,
		pgoff_t start, pgoff_t end) { return 0; }
#endif

void invalidate_mapping_pagevec(struct address_space *mapping,
				pgoff_t start, pgoff_t end,
				unsigned long *nr_pagevec);
+3 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ enum page_cache_reclaim_flag {
extern int pagecache_reclaim_enable;
extern int pagecache_limit_ratio;
extern int pagecache_reclaim_ratio;
extern int node_to_shrink;

int proc_page_cache_limit(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp, loff_t *ppos);
@@ -20,6 +21,8 @@ unsigned long __shrink_node_page_cache(int nid, gfp_t mask,
void kpagecache_limitd_stop(int nid);
int kpagecache_limitd_run(int nid);
void wakeup_all_kpagecache_limitd(void);
int proc_shrink_node_caches(struct ctl_table *table, int write,
		void __user *buffer, size_t *lenp, loff_t *ppos);
#else
static inline void kpagecache_limitd_stop(int nid) {}
static inline int kpagecache_limitd_run(int nid) { return 0; }
+8 −0
Original line number Diff line number Diff line
@@ -3224,6 +3224,14 @@ static struct ctl_table vm_table[] = {
		.extra1		= SYSCTL_ZERO,
		.extra2		= (void *)&one_hundred,
	},
	{
		.procname	= "node_drop_caches",
		.data		= &node_to_shrink,
		.maxlen		= sizeof(node_to_shrink),
		.mode		= 0600,
		.proc_handler	= proc_shrink_node_caches,
		.extra1		= SYSCTL_ZERO,
	},
#endif
	{ }
};
+2 −0
Original line number Diff line number Diff line
@@ -5,11 +5,13 @@
#include <linux/module.h>
#include <linux/err.h>
#include <linux/swap.h>
#include <linux/fs.h>
#include <linux/page_cache_limit.h>

int pagecache_reclaim_enable;
int pagecache_limit_ratio;
int pagecache_reclaim_ratio;
int node_to_shrink;

static unsigned long pagecache_limit_pages;
static unsigned long node_pagecache_limit_pages[MAX_NUMNODES];
Loading