Skip to content

Commit 61e6c87

Browse files
[auto-techsupport] support techsupport generation on potential memory leaks (#939)
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
1 parent 31b8462 commit 61e6c87

1 file changed

Lines changed: 125 additions & 32 deletions

File tree

doc/auto_techsupport_and_coredump_mgmt.md

Lines changed: 125 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
* [2. High Level Requirements](#2-high-level-requirements)
99
* [3. Core Dump Generation in SONiC](#3-core-dump-generation-in-sonic)
1010
* [4. Schema Additions](#4-schema-additions)
11-
* [5. CLI Enhancements](#5-cli-enhancements)
12-
* [6. Design](#6-design)
11+
* [6. CLI Enhancements](#5-cli-enhancements)
12+
* [7. Design](#6-design)
1313
* [6.1 Modifications to coredump-compress script](#61-Modifications-to-coredump-compress-script)
1414
* [6.2 coredump_gen_handler script](#62-coredump_gen_handler-script)
1515
* [6.3 Modifications to generate_dump script](#64-Modifications-to-generate-dump-script)
1616
* [6.4 techsupport_cleanup script](#65-techsupport_cleanup-script)
1717
* [6.5 Warmboot consideration](#65-Warmboot-consideration)
1818
* [6.6 MultiAsic consideration](#66-MultiAsic-consideration)
1919
* [6.7 Design choices for max-techsupport-limit & max-techsupport-limit arguments](#67-Design-choices-for-max-core-limit-&-max-techsupport-limit-arguments)
20-
* [7. Test Plan](#7-Test-Plan)
21-
* [8. SONiC-to-SONiC Upgrade Considerations](#8-SONiC-to-SONiC-Upgrade-Considerations)
20+
* [8. Test Plan](#7-Test-Plan)
21+
* [9. SONiC-to-SONiC Upgrade Considerations](#8-SONiC-to-SONiC-Upgrade-Considerations)
2222

2323

2424
### Revision
@@ -27,6 +27,7 @@
2727
| 1.0 | 06/22/2021 | Vivek Reddy Karri | Auto Invocation of Techsupport, triggered by a core dump |
2828
| 1.1 | TBD | Vivek Reddy Karri | Add the capability to Register/Deregister app extension to AUTO_TECHSUPPORT_FEATURE table |
2929
| 2.0 | TBD | Vivek Reddy Karri | Extending Support for Kernel Dumps |
30+
| 3.0 | 02/2022 | Stepan Blyshchak | Extending Support for memory usage threshold crossed |
3031

3132
## About this Manual
3233
This document describes the details of the system which facilitates the auto techsupport invocation support in SONiC. The auto invocation is triggered when any process inside the docker crashes and a core dump is generated.
@@ -36,13 +37,20 @@ Currently, techsupport is run by invoking `show techsupport` either by orchestra
3637

3738
However if the techsupport invocation can be made event-driven based on core dump generation, that would definitely improve the debuggability. That is the overall idea behind this HLD. All the high-level requirements are summarized in the next section
3839

40+
Another use case is to gather more information about the system in case there is a memory usage threshold crossed.
41+
SONiC dump generated after system reboots due to out of memory is not enough for debugging the issue
42+
as all the information about processes and their mem usage, smaps (/proc/PID/smaps) is lost.
43+
Once the system detects abnormal memory usage SONiC dump is generated automatically.
44+
3945
## 2. High Level Requirements
4046
### Global Scope
4147
* Techsupport invocation should also be made event-driven based on core dump generation.
4248
* This is only applicable for the processes running inside the dockers. Does not apply for other processes.
4349
* init_cfg.json will be enhanced to include the "CONFIG" required for this feature (described in section 4) and is enabled by default.
4450
* To provide flexibility, a compile time flag "ENABLE_AUTO_TECH_SUPPORT" should be provided to enable/disable the "CONFIG" for this feature.
4551
* Users should have the abiliity to enable/disable this capability through CLI.
52+
* Techsupport invocation should also be made event-driven based on memory usage threshold crossing.
53+
* The memory usage threshold should be configurable system-wise and per container.
4654

4755
### Configurable Params
4856
* A configurable "rate_limit_interval" should be introduced to limit the number consecutive of techsupport invocations.
@@ -68,14 +76,59 @@ The naming format and compression is governed by the script `/usr/local/bin/core
6876

6977
Where `<comm>` value in the command name associated with a process. comm value of a running process can be read from `/proc/[pid]/comm` file
7078

71-
## 4. Schema Additions
79+
## 4. Memory usage based techsupport invocation
80+
81+
If the following condition resolves to true:
82+
```
83+
(mem_usage > mem_usage_threshold || ${container}_mem_usage > ${container}_mem_usage_threshold) || mem_free <= mem_free_threshold
84+
```
85+
86+
where ```mem_usage``` is total system memory used (MemAvailable from /proc/meminfo),
87+
```mem_usage_threshold``` configured threshold, (100 - available_mem_threshold),
88+
89+
```${container}_mem_usage``` used memory by $container ("docker stats --no-stream --format {{.MemUsage}}" $container),
90+
91+
```${container}_mem_usage_threshold``` configured memory threshold for $container, (100 - ${container}available_mem_threshold),
92+
93+
```mem_free``` is the total minus mem usage, ```mem_free_threshold``` - mem free threshold.
94+
95+
the SONiC techsupport is automatically generated.
96+
97+
```mem_free_threshold``` is there to invoke dump when there is quite small amount of memory left that is needed to successfully execute "show techsupport". This is going to be 200 MB by default, as at least 80-90 MB takes "show techsupport" execution.
98+
99+
The check will be implemented as a script that is ran by monit periodically:
100+
101+
```
102+
check program mem_checker with path "/usr/bin/mem_threshold_check"
103+
if status != 0 for 10 times within 20 cycles then exec /usr/local/bin/mem_threshold_check_handler"
104+
```
105+
106+
The action is going to be ran only once the mem_check script detects memory usage above threshold.
107+
108+
The "10 times within 20 cycles" part is kept in sync with mem_usage alert from sonic-host monit configuration.
109+
It is possible to make those values configurable however, only the threshold value is considered to be configurable.
110+
111+
The rate limit as well as techsupport maximum limit is applicable to techsupport generated by memory check.
112+
113+
#### 202106 and older
114+
115+
To support thechsupport generation on memory leaks a simple rule to monit is added:
116+
117+
```
118+
check system $HOST
119+
if memory usage > 90% for 10 times within 20 cycles then exec /usr/bin/generate_dump
120+
```
121+
122+
## 5. Schema Additions
72123

73124
### Config DB
74125

75126
#### AUTO_TECHSUPPORT Table
76127
```
77128
key = "AUTO_TECHSUPPORT|global"
78129
state = "enabled" / "disabled" ; Enable this to make the Techsupport Invocation event driven based on core-dump generation
130+
available_mem_threshold = 1*2DIGIT ; Memory threshold; 0 to disable techsupport invocation on mem leak.
131+
min_available_mem = 1*5DIGIT ; Minimum free memory amount in MB when techsupport will be executed.
79132
rate_limit_interval = 1*5DIGIT ; Minimum Time in seconds, between two successive techsupport invocations.
80133
Manual Invocations will be considered as well in the calculation.
81134
Configure 0 to explicitly disable
@@ -99,6 +152,7 @@ since = 1*32VCHAR; ; This limits the auto-invoke
99152
```
100153
key = feature name
101154
state = "enabled" / "disabled" ; Enable auto techsupport invocation on the critical processes running inside this feature
155+
available_mem_threshold = 1*2DIGIT ; Memory threshold; 0 to disable techsupport invocation on mem leak in this container.
102156
rate_limit_interval = 1*5DIGIT ; Rate limit interval for the corresponding feature. Configure 0 to explicitly disable
103157
```
104158

@@ -143,6 +197,18 @@ module sonic-auto_techsupport {
143197
type stypes:admin_mode;
144198
}
145199
200+
leaf available_mem_threshold {
201+
description "Enable techsupport invocation on available memory threshold crossing; 0 to disable"
202+
type decimal-repr;
203+
default 10.0;
204+
}
205+
206+
leaf min_available_mem {
207+
description "Minimum free memory amount in MB when techsupport will be executed"
208+
type uint32;
209+
default 200;
210+
}
211+
146212
leaf rate_limit_interval {
147213
description "Minimum time in seconds between two successive techsupport invocations. Configure 0 to explicitly disable";
148214
type uint16;
@@ -206,6 +272,12 @@ module sonic-auto_techsupport {
206272
type stypes:admin_mode;
207273
}
208274
275+
leaf available_mem_threshold {
276+
description "Enable techsupport invocation on available memory threshold crossing; 0 to disable"
277+
type decimal-repr;
278+
default 10.0;
279+
}
280+
209281
leaf rate_limit_interval {
210282
description "Rate limit interval for the corresponding feature. Configure 0 to explicitly disable";
211283
type uint16;
@@ -226,27 +298,43 @@ module sonic-auto_techsupport {
226298
#### AUTO_TECHSUPPORT_DUMP_INFO Table
227299
```
228300
key = Techsupport Dump Name
229-
core_dump = 1*64VCHAR ; Core Dump Name
230-
timestamp = 1*12DIGIT ; epoch of this record creation
231-
container_name = 1*64VCHAR ; Container in which the process crashed
301+
event_type = "core" / "memory" ; Type of event caused techsupport invocation
302+
core_dump = 1*64VCHAR ; Core Dump Name
303+
timestamp = 1*12DIGIT ; epoch of this record creation
304+
container_name = 1*64VCHAR ; Container in which the process crashed/mem threshold. Unset when triggered from host.
305+
```
232306

233307
Eg:
234308

309+
```
235310
hgetall "AUTO_TECHSUPPORT_DUMP_INFO|sonic_dump_sonic_20210412_223645"
236-
1) "core_dump"
237-
2) "orchagent.1599047232.39.core"
311+
1) "event_type"
312+
2) "core"
313+
2) "core_dump"
314+
3) "orchagent.1599047232.39.core"
315+
4) "timestamp"
316+
5) "1599047233"
317+
6) "container_name"
318+
7) "swss"
319+
```
320+
321+
```
322+
hgetall "AUTO_TECHSUPPORT_DUMP_INFO|sonic_dump_sonic_20210412_223123"
323+
1) "event_type"
324+
2) "memory"
238325
3) "timestamp"
239-
4) "1599047233"
326+
4) "1612045251"
240327
5) "container_name"
241328
6) "swss"
242329
```
243330

244-
245-
## 5. CLI Enhancements.
331+
## 6. CLI Enhancements.
246332

247333
### config cli
248334
```
249335
config auto-techsupport global state <enabled/disabled>
336+
config auto-techsupport global available-mem-threshold <float upto two decimal places>
337+
config auto-techsupport global min-available-mem <float upto two decimal places>
250338
config auto-techsupport global rate-limit-interval <uint16>
251339
config auto-techsupport global max-techsupport-limit <float upto two decimal places>
252340
config auto-techsupport global max-core-limit <float upto two decimal places>
@@ -261,26 +349,26 @@ config auto-techsupport-feature delete restapi
261349

262350
```
263351
admin@sonic:~$ show auto-techsupport global
264-
STATE RATE LIMIT INTERVAL (sec) MAX TECHSUPPORT LIMIT (%) MAX CORE SIZE (%) SINCE
265-
------- --------------------------- -------------------------- ------------------ ----------
266-
enabled 180 10.0 5.0 2 days ago
352+
STATE RATE LIMIT INTERVAL (sec) MAX TECHSUPPORT LIMIT (%) MAX CORE SIZE (%) MEM THRESHOLD (%) MEM THRESHOLD (%) SINCE
353+
------- --------------------------- -------------------------- ------------------ ------------------ ------------------- ---------
354+
enabled 180 10.0 5.0 10.0 10.0 2 days ago
267355
268356
admin@sonic:~$ show auto-techsupport-feature
269-
FEATURE NAME STATE RATE LIMIT INTERVAL (sec)
270-
-------------- -------- --------------------------
271-
bgp enabled 600
272-
database enabled 600
273-
dhcp_relay enabled 600
274-
lldp enabled 600
275-
macsec enabled 600
276-
mgmt-framework enabled 600
277-
nat enabled 600
278-
pmon enabled 600
279-
radv enabled 600
280-
restapi disabled 800
281-
sflow enabled 600
282-
snmp enabled 600
283-
swss disabled 800
357+
FEATURE NAME STATE MEM THRESHOLD (%) RATE LIMIT INTERVAL (sec)
358+
-------------- -------- ------------------ --------------------------
359+
bgp enabled 10.0 600
360+
database enabled 10.0 600
361+
dhcp_relay enabled 10.0 600
362+
lldp enabled 10.0 600
363+
macsec enabled 10.0 600
364+
mgmt-framework enabled 10.0 600
365+
nat enabled 10.0 600
366+
pmon enabled 10.0 600
367+
radv enabled 10.0 600
368+
restapi disabled 10.0 800
369+
sflow enabled 10.0 600
370+
snmp enabled 10.0 600
371+
swss disabled 10.0 800
284372
285373
286374
admin@sonic:~$ show auto-techsupport history
@@ -374,7 +462,7 @@ Enhance the existing techsupport sonic-mgmt test with the following cases.
374462
| 2 | Check if the techsupport cleanup is working as expected |
375463
| 3 | Check if the global rate-& & per-process rate-limit-interval is working as expected |
376464
| 4 | Check if the core-dump cleanup is working as expected |
377-
465+
| 5 | Check if the core-dump generated when reaching memory threshold |
378466
## 8. SONiC-to-SONiC Upgrade Considerations
379467

380468
The default config required for auto_techsupport is present in the init_cfg.json. Therefore, when a clean installation of SONiC is performed, the configuration is found in the config DB and the feature is active.
@@ -391,6 +479,7 @@ Load this Example config provided below to enable the feature. Each of the field
391479
"rate_limit_interval": "180",
392480
"max_techsupport_limit": "10.0",
393481
"max_core_limit": "5.0",
482+
"available_mem_threashold": "10.0",
394483
"since": "2 days ago"
395484
}
396485
},
@@ -461,4 +550,8 @@ Load this Example config provided below to enable the feature. Each of the field
461550
}
462551
}
463552
}
553+
```
554+
555+
# Open question
464556

557+
1. Is 10 % free memory/90 % used memory threshold a reasonable default?

0 commit comments

Comments
 (0)