-
Notifications
You must be signed in to change notification settings - Fork 4
/
GlobalScan.h
111 lines (92 loc) · 2.48 KB
/
GlobalScan.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* SPDX-License-Identifier: GPL-2.0
*
* Copyright (c) 2018 Intel Corporation
*
* Authors: Fengguang Wu <[email protected]>
* Yao Yuan <[email protected]>
*/
#ifndef AEP_GLOBAL_SCAN_H
#define AEP_GLOBAL_SCAN_H
#include <vector>
#include <atomic>
#include "Queue.h"
#include "Process.h"
#include "EPTMigrate.h"
#include "BandwidthLimit.h"
#include "Sysfs.h"
#include "Numa.h"
enum JobIntent
{
JOB_WALK,
JOB_MIGRATE,
JOB_QUIT,
};
typedef std::shared_ptr<EPTMigrate> EPTMigratePtr;
struct Job
{
EPTMigratePtr migration;
JobIntent intent;
};
class GlobalScan
{
public:
GlobalScan();
void main_loop();
void create_threads();
void stop_threads();
int collect();
void walk_multi();
void migrate();
void count_refs();
void count_migrate_stats();
void update_interval(bool finished);
void request_reload_conf();
void apply_option();
private:
void consumer_loop();
int consumer_job(Job& job);
void walk_once();
bool should_stop_walk();
void update_dram_free_anon_bytes();
void reload_conf();
bool exit_on_stabilized();
bool exit_on_exceeded();
bool check_exit_on_exceeded(pid_t pid);
void update_pid_context();
unsigned long accept_hot_bytes() { return dram_hot_target * 12 / 8; }
unsigned long target_young_bytes() { return dram_hot_target * 10 / 8; }
unsigned long target_hot_bytes() { return dram_hot_target; }
unsigned long get_dram_free_and_anon_bytes()
{ return get_dram_anon_bytes(true) << PAGE_SHIFT; }
unsigned long get_dram_anon_bytes(bool is_include_free);
unsigned long calc_migrated_bytes();
void show_migrate_speed(float delta_time);
bool is_all_migration_done();
private:
static const float MIN_INTERVAL;
static const float MAX_INTERVAL;
unsigned int nround;
int nr_walks;
int nr_acceptable_scans;
float interval;
float real_interval;
struct timeval last_scan_start;
unsigned long young_bytes;
unsigned long top_bytes;
unsigned long all_bytes;
unsigned long dram_free_anon_bytes;
unsigned long dram_hot_target;
ProcessCollection process_collection;
std::vector<std::shared_ptr<EPTMigrate>> idle_ranges;
std::vector<std::thread> worker_threads;
Queue<Job> work_queue;
Queue<Job> done_queue;
std::atomic_int conf_reload_flag;
BandwidthLimit throttler;
NumaNodeCollection numa_collection;
ProcVmstat proc_vmstat;
Sysfs sysfs;
};
#endif
// vim:set ts=2 sw=2 et: