Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754683AbZJLMCf (ORCPT ); Mon, 12 Oct 2009 08:02:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751790AbZJLMCe (ORCPT ); Mon, 12 Oct 2009 08:02:34 -0400 Received: from lo.gmane.org ([80.91.229.12]:43571 "EHLO lo.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751364AbZJLMCe (ORCPT ); Mon, 12 Oct 2009 08:02:34 -0400 X-Injected-Via-Gmane: http://gmane.org/ To: linux-kernel@vger.kernel.org From: =?UTF-8?B?VmVkcmFuIEZ1cmHEjQ==?= Subject: Memory overcommit Date: Mon, 12 Oct 2009 13:51:07 +0200 Message-ID: Reply-To: vedran.furac@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 89-201-144-125.dsl.optinet.hr User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090701 Thunderbird/2.0.0.22 Mnenhy/0.7.5.0 X-Age: 25 X-Location: Lovran, Croatia X-OS: Debian GNU/Linux X-Face: +Lg7^E:?#]P.Y{N@61yW{aY#>fRcOE6MMqgAM|Kwk"fK!y!i4+h6&?E`Jt@uame[-SLu#*?k:)dZv X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2060 Lines: 66 Hi! I don't know if this is appropriate place to ask such questions and if not, please point me to such place. Let's simulate a process gone berserk with this piece of code: #include #include #include #include int main() { char *buf; while(1) { buf = malloc (1024*1024*100); if ( buf == NULL ) { perror("malloc"); getchar(); exit(EXIT_FAILURE); } sleep(1); memset(buf, 1, 1024*1024*100); } return 0; } # echo 0 > /proc/sys/vm/overcommit_memory Compile, run and soon result is: - System freezes for a second or two - OOMK wakes up - X crashes Now, I'm back to VT1 and dmesg shows 8 process were killed by OOMK (including X server and some long running daemons with small memory footprint like automount) before the real culprit was killed. This random killing spree *really* gives bad reputation to linux and people usually point this out as an argument against it. But, there is an easy fix: # echo 2 > /proc/sys/vm/overcommit_memory Run the program again and after a few seconds you'll get: "malloc: Cannot allocate memory" and that's all what happens. Nothing gets killed and one (and others too) can continue to work without loosing time, data or both. Only somewhat strange is that kernel contradicts itself when it says there is no more and in the same time saying: /proc/meminfo MemTotal: 3542532 kB MemFree: 892972 kB Buffers: 2664 kB Cached: 130940 kB ...that there is almost 900MB free memory. But OK, I can live with it. So, my question is: why today overcommit isn't turned off *by default*? I have it turned off for a few years now and only side effect is that I don't get processes killed randomly anymore, I don't loose valuable time and data. Regards, Vedran -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/