Skip to content

Commit 4780b4e

Browse files
authored
Merge pull request #110 from pythonspeed/96-better-oom
Significantly better OOM detection.
2 parents be580f7 + 8029559 commit 4780b4e

20 files changed

Lines changed: 803 additions & 101 deletions

.changelog/96.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Out-of-memory detection should work in many more cases than before.

Cargo.lock

Lines changed: 191 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target/release/libpymemprofile_api.a: Cargo.lock memapi/Cargo.toml memapi/src/*.
2121

2222
venv:
2323
python3 -m venv venv/
24+
venv/bin/pip install --upgrade pip setuptools
2425

2526
.PHONY: test
2627
test:

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,21 @@ $ python -m filprofiler run yourscript.py --input-file=yourfile
126126

127127
### <a name="oom">Debugging out-of-memory crashes</a>
128128

129-
First, run `free` to figure out how much memory is available—in this case about 6.3GB—and then set a corresponding limit on virtual memory with `ulimit`:
130-
131-
```console
132-
$ free -h
133-
total used free shared buff/cache available
134-
Mem: 7.7Gi 1.1Gi 6.3Gi 50Mi 334Mi 6.3Gi
135-
Swap: 3.9Gi 3.0Gi 871Mi
136-
$ ulimit -Sv 6300000
137-
```
138-
139-
Then, run your program under Fil, and it will generate a SVG at the point in time when memory runs out:
129+
**New in v0.14 and later:** Just run your program under Fil, and it will generate a SVG at the point in time when memory runs out, and then exit with exit code 53:
140130

141131
```console
142132
$ fil-profile run oom.py
143133
...
144134
=fil-profile= Wrote memory usage flamegraph to fil-result/2020-06-15T12:37:13.033/out-of-memory.svg
145135
```
146136

137+
Fil uses three heuristics to determine if the process is close to running out of memory:
138+
139+
* A failed allocation, indicating insufficient memory is available.
140+
* The operating system or memory-limited cgroup (e.g. a Docker container) only has 100MB of RAM available.
141+
* The process swap is larger than available memory, indicating heavy swapping by the process.
142+
In general you want to avoid swapping, and e.g. [explicitly use `mmap()`](https://pythonspeed.com/articles/mmap-vs-zarr-hdf5/) if you expect to be using disk as a backfill for memory.
143+
147144
## <a name="reducing-memory-usage">Reducing memory usage in your code</a>
148145

149146
You've found where memory usage is coming from—now what?
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"D1mr": 5978523,
3-
"D1mw": 3953746,
4-
"DLmr": 2137435,
5-
"DLmw": 2799987,
6-
"Dr": 274430190,
7-
"Dw": 110583840,
8-
"I1mr": 5066143,
9-
"ILmr": 11684,
10-
"Ir": 1053389932,
11-
"Overall": 1646870790
2+
"D1mr": 6076063,
3+
"D1mw": 3991557,
4+
"DLmr": 2074284,
5+
"DLmw": 2800063,
6+
"Dr": 276437733,
7+
"Dw": 112029864,
8+
"I1mr": 5056035,
9+
"ILmr": 15211,
10+
"Ir": 1058474678,
11+
"Overall": 1654123635
1212
}

0 commit comments

Comments
 (0)