PostgreSQL और OOM killer: हम strict memory overcommit का उपयोग क्यों करते हैं
Linux overcommit modes & PostgreSQL
- कई टिप्पणीकार इस बात पर ज़ोर देते हैं कि strict overcommit (
vm.overcommit_memory=2)fork()और application restarts को तोड़ सकता है, खासकर अगर overcommit ratios पहले से tuned हों। - सिफ़ारिश: इसे पहले QA/perf में strictly test करें, load test करें, और
sysctlमें स्थायी रूप से जोड़ने से पहले deployment scripts के ज़रिए roll out करें। - कुछ लोग heuristic mode (
0) को बहुत कमovercommit_ratioऔरoom_score_adjके भारी उपयोग (जैसे critical services के लिए -1000) के साथ, plus kernel reserve tuning, पसंद करते हैं। - PostgreSQL के लिए खास तौर पर, strict overcommit आकर्षक हो सकता है क्योंकि यह
ENOMEMको साफ़ तरीके से संभालता है और crash होने के बजाय transactions को rollback कर देता है।
Shared hosts: Go / managed languages vs Postgres
- वास्तविक दुनिया की समस्या: एक ही host पर Go backend और Postgres।
- Heuristic overcommit ने Postgres allocation failures पैदा किए; strict overcommit ने Go की बड़ी virtual reservations के कारण पूरे system को unstable बना दिया।
- Workarounds: empirically tuned
overcommit_ratio,GOMEMLIMITका उपयोग करके Go heap को cap करना, या DB और app को अलग nodes पर, या containers/cgroups के ज़रिए isolate करना।
OOM killer vs allocation failures
- इस पर ज़ोरदार असहमति है कि overcommit को disable करना समझदारी है या नहीं।
- कुछ उपयोगकर्ता overcommit disable करते हैं और ऐसे short freezes पसंद करते हैं जहाँ वे खुद apps बंद कर दें, बजाय इसके कि kernel “random” या critical processes को kill करे।
- दूसरों का तर्क है कि यह बस OOM kills को
ENOMEMपर crashes से बदल देता है, क्योंकि ज़्यादातर desktop software allocation failures को handle नहीं करता और state corrupt कर सकता है। - desktops पर kernel OOM killer का व्यवहार व्यापक रूप से slow, unpredictable, और user-hostile माना जाता है।
Windows/macOS and swap / compression
- कई टिप्पणियाँ Linux की तुलना Windows से करती हैं: Windows commit charge को track करता है, कभी overcommit नहीं करता, और आम तौर पर low-memory situations को अधिक gracefully संभालता है।
- कुछ लोग कहते हैं कि Windows में प्रभावी रूप से “OOM killer” नहीं है, बल्कि वह unreasonable allocations को reject करता है; अन्य लोग बताते हैं कि वह offending app को kill भी कर सकता है या उसे close करने के लिए prompt कर सकता है।
- Windows page file disable करने पर बहस: कुछ लोग इसे “overcommit disable” करने के लिए करते हैं, जबकि अन्य इसे लगभग हमेशा खराब विचार कहते हैं और page file को safety के रूप में महत्व देते हैं।
- Linux पर, टिप्पणीकार swap, zram/zswap, MGLRU, और user-space OOM daemons की वकालत करते हैं, खासकर hyperscaler-style “no swap” setups की तुलना में, जिन्हें वे कम समझदार default मानते हैं।
Broader design / language angles
- कुछ लोग तर्क देते हैं कि desktop पर strict overcommit एक footgun है, क्योंकि
mallocerror handling की व्यापक अनदेखी होती है। - अन्य लोग बताते हैं कि robust systems (विशेषकर databases) को अपनी memory accounting और OOM strategies खुद implement करनी चाहिए।
- एक side thread सुझाव देता है कि Rust के richer types (enums/Result) ने article में चर्चा किए गए specific C integer/boolean bug को रोक दिया होता।