@cryptotaxi247 / netdata-1 / commits / f2e47302b

eliminated the need to periodically load mount information for disk performance metrics

Costa Tsaousis (ktsaou) committed Jan 14, 2017 at 17:26 UTC f2e47302b3818de72968b2e0670a750c7ed1aca0
1 file changed +10 -33
src/proc_diskstats.c
+10 -33
@@ -6,8 +6,6 @@
6 #define DISK_TYPE_PARTITION 2
7 #define DISK_TYPE_CONTAINER 3
8
9 -static int check_for_new_mountpoints_every = 15;
10 -
9 static struct disk {
10 char *disk; // the name of the disk (sda, sdb, etc)
11 unsigned long major;
@@ -30,27 +28,12 @@ static struct disk {
28 struct disk *next;
29 } *disk_root = NULL;
30
33 -static struct mountinfo *disk_mountinfo_root = NULL;
34 -
35 -static inline void mountinfo_reload(int force) {
36 - static time_t last_loaded = 0;
37 - time_t now = now_realtime_sec();
38 -
39 - if(force || now - last_loaded >= check_for_new_mountpoints_every) {
40 - // mountinfo_free() can be called with NULL disk_mountinfo_root
41 - mountinfo_free(disk_mountinfo_root);
42 -
43 - // re-read mountinfo in case something changed
44 - disk_mountinfo_root = mountinfo_read(0);
45 -
46 - last_loaded = now;
47 - }
48 -}
49 -
31 static struct disk *get_disk(unsigned long major, unsigned long minor, char *disk) {
32 static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
33 static char path_to_get_hw_sector_size_partitions[FILENAME_MAX + 1] = "";
34 static char path_find_block_device[FILENAME_MAX + 1] = "";
35 + static struct mountinfo *disk_mountinfo_root = NULL;
36 +
37 struct disk *d;
38
39 // search for it in our RAM list.
@@ -59,11 +42,7 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
42 // should not be that many, it should be acceptable
43 for(d = disk_root; d ; d = d->next)
44 if(unlikely(d->major == major && d->minor == minor))
62 - break;
63 -
64 - // if we found it, return it
65 - if(likely(d))
66 - return d;
45 + return d;
46
47 // not found
48 // create a new disk structure
@@ -131,6 +110,13 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
110
111 // mountinfo_find() can be called with NULL disk_mountinfo_root
112 struct mountinfo *mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
113 + if(unlikely(!mi)) {
114 + // mountinfo_free can be called with NULL
115 + mountinfo_free(disk_mountinfo_root);
116 + disk_mountinfo_root = mountinfo_read(0);
117 + mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
118 + }
119 +
120 if(unlikely(mi))
121 d->mount_point = strdupz(mi->mount_point);
122 else
@@ -242,18 +228,9 @@ int do_proc_diskstats(int update_every, usec_t dt) {
228 global_do_util = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "utilization percentage for all disks", global_do_util);
229 global_do_backlog = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "backlog for all disks", global_do_backlog);
230
245 - check_for_new_mountpoints_every = (int)config_get_number("plugin:proc:/proc/diskstats", "check for new mount points every", check_for_new_mountpoints_every);
246 - if(check_for_new_mountpoints_every < update_every)
247 - check_for_new_mountpoints_every = update_every;
248 -
231 globals_initialized = 1;
232 }
233
252 - // --------------------------------------------------------------------------
253 - // this is smart enough not to reload it every time
254 -
255 - mountinfo_reload(0);
256 -
234 // --------------------------------------------------------------------------
235
236 if(unlikely(!ff)) {