summaryrefstree
path: root/kernel/mm/sec_mm/lowfile_detect.c
blob: 872c0275decb5870b1c09a853f755821d31c0d0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: GPL-2.0
/*
 * sec_mm/
 *
 * Copyright (C) 2020 Samsung Electronics
 *
 */

#include <linux/module.h>
#include <linux/mm.h>
#include <linux/ratelimit.h>
#include "sec_mm.h"

static DEFINE_RATELIMIT_STATE(mm_debug_rs, 10 * HZ, 1);

#define MIN_FILE_SIZE_HIGH	300
#define MIN_FILE_SIZE_LOW	200
#define MIN_FILE_SIZE_THR_GB	3
static unsigned long min_file;

static unsigned long lowfile_count(struct shrinker *s,
				  struct shrink_control *sc)
{
	unsigned long inactive_file, active_file, file;

	inactive_file = global_node_page_state(NR_INACTIVE_FILE);
	active_file = global_node_page_state(NR_ACTIVE_FILE);
	file = inactive_file + active_file;
	if (file < min_file && __ratelimit(&mm_debug_rs)) {
		pr_info("low file detected : %lukB < %luKB\n", K(file),
			K(min_file));
#ifdef CONFIG_SEC_MM
		show_mem(0, NULL);
#else
		mm_debug_show_free_areas();
#endif
		mm_debug_dump_tasks();
	}

	return 0; /* return 0 not to call to scan_objects */
}

static struct shrinker mm_debug_shrinker = {
	.count_objects = lowfile_count,
};

void init_lowfile_detect(void)
{
	if (totalram_pages() > GB_TO_PAGES(MIN_FILE_SIZE_THR_GB))
		min_file = MB_TO_PAGES(MIN_FILE_SIZE_HIGH);
	else
		min_file = MB_TO_PAGES(MIN_FILE_SIZE_LOW);

	register_shrinker(&mm_debug_shrinker);
}

void exit_lowfile_detect(void)
{
	unregister_shrinker(&mm_debug_shrinker);
}

MODULE_LICENSE("GPL");