oom detection rework v5
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest11 patches 27 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/11 | mm, oom: rework oom detectioninclude/ mm/ mm/ | +97 | 0 replies | |
| 2/11 | mm: throttle on IO only when there are too many dirty and writeback pagesmm/ mm/ | +39 | 0 replies | |
| 3/11 | mm, compaction: change COMPACT_ constants into enuminclude/ mm/ mm/ | +42 | 0 replies | |
| 4/11 | mm, compaction: cover all compaction mode in compact_zonemm/ | +5 | 0 replies | |
| 5/11 | mm, compaction: distinguish COMPACT_DEFERRED from COMPACT_SKIPPEDinclude/ include/ mm/ | +11 | 2 replies | |
| 6/11 | mm, compaction: distinguish between full and partial COMPACT_COMPLETEinclude/ include/ mm/ +1 more | +22 | 6 replies | |
| 7/11 | mm, compaction: Update compaction_result orderinginclude/ | +16 | 1 reply | |
| 8/11 | mm, compaction: Simplify __alloc_pages_direct_compact feedback interfacemm/ | +31 | 1 reply | |
| 9/11 | mm, compaction: Abstract compaction feedback to helpersinclude/ mm/ | +80 | 12 replies | |
| 10/11 | mm, oom: protect !costly allocations some moremm/ | +78 | 3 replies | |
| 11/11 | mm: consider compaction feedback also for costly allocationmm/ | +32 | 2 replies |
Reviews trailers per patch
10 of 11 patches have a Reviewed-by or Acked-by.
| Patch | Hillf Danton | Vlastimil Babka |
|---|---|---|
| 1/11 | A-b | |
| 2/11 | A-b | |
| 3/11 | A-b | A-b |
| 4/11 | A-b | A-b |
| 5/11 | A-b | |
| 6/11 | A-b | |
| 7/11 | A-b | |
| 8/11 | A-b | |
| 9/11 | ||
| 10/11 | A-b | |
| 11/11 | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 00/11] oom detection rework v5
Hi,
This is v5 of the series. The previous version was posted [1]. There was a number of changes since then. Mostly driven by premature oom killer invocation for higher order requests reported by Hugh [2]. That forced me to look into compaction because it became clear that we have to consider its feedback to make any retry decisions especially for !costly high order requests. As a result we have 7 compaction related patches because the code wasn't really prepared to tell its caller about a feedback. I have tried hard to not change compaction logic and profile it for my specific test cases and rather come up with a generic feedback mechanism which would be mostly independent on the current implementation.
As pointed by Linus [3][4] relying on zone_reclaimable as a way to communicate the reclaim progress is rater dubious. I tend to agree, not only it is really obscure, it is not hard to imagine cases where a single page freed in the loop keeps all the reclaimers looping without getting any progress because their gfp_mask wouldn't allow to get that page anyway (e.g. single GFP_ATOMIC alloc and free loop). This is rather rare so it doesn't happen in the practice but the current logic which we have is rather obscure and hard to follow a also non-deterministic.
This is an attempt to make the OOM detection more deterministic and easier to follow because each reclaimer basically tracks its own progress which is implemented at the page allocator layer rather spread out between the allocator and the reclaim. The more on the implementation is described in the first patch.
I have tested several different scenarios but it should be clear that testing OOM killer is quite hard to be representative. There is usually a tiny gap between almost OOM and full blown OOM which is often time sensitive. Anyway, I have tested the following 2 scenarios and I would appreciate if there are more to test.
Testing environment: a virtual machine with 2G of RAM and 2CPUs without any swap to make the OOM more deterministic.
1) 2 writers (each doing dd with 4M blocks to an xfs partition with 1G file size, removes the files and starts over again) running in parallel for 10s to build up a lot of dirty pages when 100 parallel mem_eaters (anon private populated mmap which waits until it gets signal) with 80M each.
This causes an OOM flood of course and I have compared both patched and unpatched kernels. The test is considered finished after there are no OOM conditions detected. This should tell us whether there are any excessive kills or some of them premature (e.g. due to dirty pages):
I have performed two runs this time each after a fresh boot.
* base kernel
$ grep "Out of memory:" base-oom-run1.log | wc -l 78 $ grep "Out of memory:" base-oom-run2.log | wc -l 78
$ grep "Kill process" base-oom-run1.log | tail -n1 [ 91.391203] Out of memory: Kill process 3061 (mem_eater) score 39 or sacrifice child $ grep "Kill process" base-oom-run2.log | tail -n1 [ 82.141919] Out of memory: Kill process 3086 (mem_eater) score 39 or sacrifice child
$ grep "DMA32 free:" base-oom-run1.log | sed 's@.*free:\([0-9]*\)kB.*@\1@' | calc_min_max.awk min: 5376.00 max: 6776.00 avg: 5530.75 std: 166.50 nr: 61 $ grep "DMA32 free:" base-oom-run2.log | sed 's@.*free:\([0-9]*\)kB.*@\1@' | calc_min_max.awk min: 5416.00 max: 5608.00 avg: 5514.15 std: 42.94 nr: 52
$ grep "DMA32.*all_unreclaimable? no" base-oom-run1.log | wc -l 1 $ grep "DMA32.*all_unreclaimable? no" base-oom-run2.log | wc -l 3
* patched kernel
$ grep "Out of memory:" patched-oom-run1.log | wc -l 78 miso@tiehlicka /mnt/share/devel/miso/kvm $ grep "Out of memory:" patched-oom-run2.log | wc -l 77
e grep "Kill process" patched-oom-run1.log | tail -n1
[ 497.317732] Out of memory: Kill process 3108 (mem_eater) score 39 or sacrifice child $ grep "Kill process" patched-oom-run2.log | tail -n1 [ 316.169920] Out of memory: Kill process 3093 (mem_eater) score 39 or sacrifice child
$ grep "DMA32 free:" patched-oom-run1.log | sed 's@.*free:\([0-9]*\)kB.*@\1@' | calc_min_max.awk min: 5420.00 max: 5808.00 avg: 5513.90 std: 60.45 nr: 78 $ grep "DMA32 free:" patched-oom-run2.log | sed 's@.*free:\([0-9]*\)kB.*@\1@' | calc_min_max.awk min: 5380.00 max: 6384.00 avg: 5520.94 std: 136.84 nr: 77
e grep "DMA32.*all_unreclaimable? no" patched-oom-run1.log | wc -l 2
$ grep "DMA32.*all_unreclaimable? no" patched-oom-run2.log | wc -l 3
The patched kernel run noticeably longer while invoking OOM killer same number of times. This means that the original implementation is much more aggressive and triggers the OOM killer sooner. free pages stats show that neither kernels went OOM too early most of the time, though. I guess the difference is in the backoff when retries without any progress do sleep for a while if there is memory under writeback or dirty which is highly likely considering the parallel IO.
Both kernels have seen races where zone wasn't marked unreclaimable and we still hit the OOM killer. This is most likely a race where a task managed to exit between the last allocation attempt and the oom killer invocation.
2) 2 writers again with 10s of run and then 10 mem_eaters to consume as much memory as possible without triggering the OOM killer. This required a lot of tuning but I've considered 3 consecutive runs in three different boots without OOM as a success.
* base kernel
size=$(awk '/MemFree/{printf "%dK", ($2/10)-(16*1024)}' /proc/meminfo)
* patched kernel
size=$(awk '/MemFree/{printf "%dK", ($2/10)-(12*1024)}' /proc/meminfo)
That means 40M more memory was usable without triggering OOM killer. The base kernel sometimes managed to handle the same as patched but it wasn't consistent and failed in at least on of the 3 runs. This seems like a minor improvement.
I was testing also GPF_REPEAT costly requests (hughetlb) with fragmented memory and under memory pressure. The results are in patch 11 where the logic is implemented. In short I can see huge improvement there.
I am certainly interested in other usecases as well as well as any feedback. Especially those which require higher order requests.
* Changes since v4
- dropped __GFP_REPEAT for costly allocation as it is now replaced by the compaction based feedback logic
- !costly high order requests are retried based on the compaction feedback
- compaction feedback has been tweaked to give us an useful information to make decisions in the page allocator
- rebased on the current mmotm-2016-04-01-16-24 with the previous version of the rework reverted
* Changes since v3
- factor out the new heuristic into its own function as suggested by Johannes (no functional changes)
* Changes since v2
- rebased on top of mmotm-2015-11-25-17-08 which includes wait_iff_congested related changes which needed refresh in patch#1 and patch#2
- use zone_page_state_snapshot for NR_FREE_PAGES per David
- shrink_zones doesn't need to return anything per David
- retested because the major kernel version has changed since the last time (4.2 -> 4.3 based kernel + mmotm patches)
* Changes since v1
- backoff calculation was de-obfuscated by using DIV_ROUND_UP
- __GFP_NOFAIL high order migh fail fixed - theoretical bug
[1] http://lkml.kernel.org/r/[email protected]
[2] http://lkml.kernel.org/r/[email protected]
[3] http://lkml.kernel.org/r/CA+55aFwapaED7JV6zm-NVkP-jKie+eQ1vDXWrKD=SkbshZSgmw@mail.gmail.com
[4] http://lkml.kernel.org/r/CA+55aFxwg=vS2nrXsQhAUzPQDGb8aQpZi0M7UUh21ftBo-z46Q@mail.gmail.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>