Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/deadlock: support specifies maxnum of threads and edge cases #3455

Merged
merged 2 commits into from
May 27, 2021
Merged

tools/deadlock: support specifies maxnum of threads and edge cases #3455

merged 2 commits into from
May 27, 2021

Conversation

chenyuezhou
Copy link
Contributor

#3453

support specifies maxnum of threads and edge cases.

The default size of memory that deadlock needs to allocate is too large. Sometimes this will cause OOM for particular system, or the memory limit has been exceeded.

[16536.857153] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-0.slice/session-1.scope,task=trace.py,pid=4971,uid=0
[16536.857622] Out of memory: Killed process 4971 (trace.py) total-vm:470116kB, anon-rss:0kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:528kB oom_score_adj:0

@@ -465,7 +475,10 @@ def main():
print('%s. Is the process (pid=%d) running?' % (str(e), args.pid))
sys.exit(1)

bpf = BPF(src_file=b'deadlock.c')
text = open('deadlock.c').read()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use something like with open('deadlock', 'r') as f: :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjusted.

@yonghong-song
Copy link
Collaborator

[buildbot, test this please]

@yonghong-song yonghong-song merged commit 77f5252 into iovisor:master May 27, 2021
jeromemarchand added a commit to jeromemarchand/bcc that referenced this pull request Apr 25, 2023
Commit 77f5252 ("tools/deadlock: support specifies maxnum of threads
and edge cases (iovisor#3455)") allow to set the maximum number of threads
and edge cases to be able to reduce the memory usage of the deadlock
tool. It however let the size of the map of stack traces fixed. It's
current size, 640k (actually rounded up to 1M) takes 1Gb of vmalloced
kernel memory.

This patch adds an option to make the maximum number of stack traces
user defined. It also set the default value to 64k, in line with the
current default for the number of edge cases and threads.

It fix the following issue on system with limited memory ressources:
could not open bpf map: stack_traces, error: Cannot allocate memory
Traceback (most recent call last):
  File "/tmp/./deadlock.py", line 577, in <module>
    main()
  File "/tmp/./deadlock.py", line 489, in main
    bpf = BPF(text=text)
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 479, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

Signed-off-by: Jerome Marchand <[email protected]>
yonghong-song pushed a commit that referenced this pull request Apr 29, 2023
Commit 77f5252 ("tools/deadlock: support specifies maxnum of threads
and edge cases (#3455)") allow to set the maximum number of threads
and edge cases to be able to reduce the memory usage of the deadlock
tool. It however let the size of the map of stack traces fixed. It's
current size, 640k (actually rounded up to 1M) takes 1Gb of vmalloced
kernel memory.

This patch adds an option to make the maximum number of stack traces
user defined. It also set the default value to 64k, in line with the
current default for the number of edge cases and threads.

It fix the following issue on system with limited memory ressources:
could not open bpf map: stack_traces, error: Cannot allocate memory
Traceback (most recent call last):
  File "/tmp/./deadlock.py", line 577, in <module>
    main()
  File "/tmp/./deadlock.py", line 489, in main
    bpf = BPF(text=text)
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 479, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

Signed-off-by: Jerome Marchand <[email protected]>
captain5050 pushed a commit to captain5050/bcc that referenced this pull request Oct 12, 2023
Commit 77f5252 ("tools/deadlock: support specifies maxnum of threads
and edge cases (iovisor#3455)") allow to set the maximum number of threads
and edge cases to be able to reduce the memory usage of the deadlock
tool. It however let the size of the map of stack traces fixed. It's
current size, 640k (actually rounded up to 1M) takes 1Gb of vmalloced
kernel memory.

This patch adds an option to make the maximum number of stack traces
user defined. It also set the default value to 64k, in line with the
current default for the number of edge cases and threads.

It fix the following issue on system with limited memory ressources:
could not open bpf map: stack_traces, error: Cannot allocate memory
Traceback (most recent call last):
  File "/tmp/./deadlock.py", line 577, in <module>
    main()
  File "/tmp/./deadlock.py", line 489, in main
    bpf = BPF(text=text)
  File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 479, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

Signed-off-by: Jerome Marchand <[email protected]>
CrackerCat pushed a commit to CrackerCat/bcc that referenced this pull request Jul 31, 2024
…ovisor#3455)

support to specify maxinum of threads and edge cases. The default values make map taking more than 0.5G memory which cause out-of-memory issue on some systems.
also fix an issue with python `open` so the open file is automatically closed upon file reading is done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants