topology: restructured code to get host wan stats
To get host wan statistics, created new thread topology_pm. this thread is invoked on each 10 seconds timer expiry. parent process sends message to thread on 10 seconds tiemr expiry. thread will collect statistics for all connections in conntrack entries. it also gets connections count for each host ip. on completion of processing for all conntrack connection it send message to parent process and parent process further updated statistics per host. parent process also updated active connections per host. parent process again strat 10 seconds timer. communication between parent process and thread is non-blocking.
with 15K conntrack entries, observation is that memory usage increased by 2636KB. output of /proc//status info is as below. after re-structuring of code: root@eagle-44d43771bf00:/tmp# cat /proc/10302/status Name: topologyd Umask: 0022 State: S (sleeping) Tgid: 10302 Ngid: 0 Pid: 10302 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 32 Groups: NStgid: 10302 NSpid: 10302 NSpgid: 1 NSsid: 1 VmPeak: 5544 kB VmSize: 5528 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 4060 kB VmRSS: 4048 kB RssAnon: 2664 kB RssFile: 1384 kB RssShmem: 0 kB VmData: 2892 kB VmStk: 132 kB VmExe: 100 kB VmLib: 2316 kB VmPTE: 12 kB VmSwap: 0 kB CoreDumping: 0 Threads: 2 SigQ: 1/3727 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000004003 SigIgn: 0000000000001000 SigCgt: 0000000000014002 CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Speculation_Store_Bypass: unknown Cpus_allowed: 3 Cpus_allowed_list: 0-1 Cpus_hint: 3 Cpus_hint_list: 0-1 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 11663 nonvoluntary_ctxt_switches: 359 root@eagle-44d43771bf00:/tmp# root@eagle-44d43771bf00:/tmp# ps | grep topology 10302 root 5528 S /usr/sbin/topologyd
root@eagle-44d43771bf00:/tmp# cat /proc/10302/stat 10302 (topologyd) S 1 1 1 0 -1 4194560 5403 133645 0 0 2023 1388 165 497 20 0 2 0 3975 5660672 1012 4294967295 65536 165744 3199643344 0 0 0 16387 4096 81922 0 0 0 17 0 0 0 1 0 0 232200 233504 24641536 3199643551 3199643571 3199643571 3199643624 0
Before restructuring of stats collection code: root@smarthub3-002207000000:/tmp# cat /proc/11625/status Name: topologyd Umask: 0022 State: S (sleeping) Tgid: 11625 Ngid: 0 Pid: 11625 PPid: 1 TracerPid: 0 Uid: 0 0 0 0 Gid: 0 0 0 0 FDSize: 64 Groups: NStgid: 11625 NSpid: 11625 NSpgid: 1 NSsid: 1 VmPeak: 2912 kB VmSize: 2884 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1688 kB VmRSS: 1688 kB RssAnon: 216 kB RssFile: 1472 kB RssShmem: 0 kB VmData: 256 kB VmStk: 132 kB VmExe: 100 kB VmLib: 2316 kB VmPTE: 28 kB VmSwap: 0 kB CoreDumping: 0 Threads: 1 SigQ: 1/7687 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000004003 SigIgn: 0000000000001000 SigCgt: 0000000000014002 CapInh: 0000000000000000 CapPrm: 0000003fffffffff CapEff: 0000003fffffffff CapBnd: 0000003fffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Speculation_Store_Bypass: unknown Cpus_allowed: f Cpus_allowed_list: 0-3 Cpus_hint: f Cpus_hint_list: 0-3 Mems_allowed: 1 Mems_allowed_list: 0 voluntary_ctxt_switches: 969 nonvoluntary_ctxt_switches: 445 root@smarthub3-002207000000:/tmp#
root@smarthub3-002207000000:/tmp# cat /proc/11625/stat 11625 (topologyd) S 1 1 1 0 -1 4194560 364 0 0 0 188 94 0 0 20 0 1 0 4423 2953216 422 18446744073709551615 65536 164152 4289241568 0 0 0 16387 4096 81922 1 0 0 17 0 0 0 0 0 0 232244 233504 16375808 4289245083 4289245103 4289245103 4289245156 0