From owner-freebsd-questions@FreeBSD.ORG Sun Mar 10 00:30:56 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 20CC9BD2 for ; Sun, 10 Mar 2013 00:30:56 +0000 (UTC) (envelope-from mexas@bristol.ac.uk) Received: from dirg.bris.ac.uk (dirg.bris.ac.uk [137.222.10.102]) by mx1.freebsd.org (Postfix) with ESMTP id BDB3127A for ; Sun, 10 Mar 2013 00:30:55 +0000 (UTC) Received: from irix.bris.ac.uk ([137.222.10.39] helo=ncs.bris.ac.uk) by dirg.bris.ac.uk with esmtp (Exim 4.72) (envelope-from ) id 1UEUA8-0007MD-2o; Sun, 10 Mar 2013 00:30:54 +0000 Received: from mech-cluster241.men.bris.ac.uk ([137.222.187.241]) by ncs.bris.ac.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1UEUA7-0001j5-Pq; Sun, 10 Mar 2013 00:30:51 +0000 Received: from mech-cluster241.men.bris.ac.uk (localhost [127.0.0.1]) by mech-cluster241.men.bris.ac.uk (8.14.6/8.14.6) with ESMTP id r2A0Uj95058403; Sun, 10 Mar 2013 00:30:45 GMT (envelope-from mexas@mech-cluster241.men.bris.ac.uk) Received: (from mexas@localhost) by mech-cluster241.men.bris.ac.uk (8.14.6/8.14.6/Submit) id r2A0UjoS058395; Sun, 10 Mar 2013 00:30:45 GMT (envelope-from mexas) Date: Sun, 10 Mar 2013 00:30:45 GMT From: Anton Shterenlikht Message-Id: <201303100030.r2A0UjoS058395@mech-cluster241.men.bris.ac.uk> To: m.e.sanliturk@gmail.com, mexas@bristol.ac.uk Subject: Re: how to forbid a process to use swap? In-Reply-To: X-Spam-Score: -3.8 X-Spam-Level: --- Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: mexas@bristol.ac.uk List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Mar 2013 00:30:56 -0000 From m.e.sanliturk@gmail.com Sun Mar 10 00:25:27 2013 On Sat, Mar 9, 2013 at 3:55 PM, Anton Shterenlikht wrote: > I run a program that uses large arrays. > I don't want it to use swap, because it's > too slow. I want the program to fail when > there's not enough RAM, rather than using > swap. How to do this? > > Is it something to do with these kernel > variables: > > kern.dfldsiz: 34359738368 > kern.dflssiz: 8388608 > > kern.maxdsiz: 34359738368 > kern.maxssiz: 536870912 > kern.maxtsiz: 134217728 > > Many thanks > > Anton > If you have program source , you may do the following : Define a constant : Maximum_Allocatable_Memory = ? Define a variable : Total_Allocated_Memory = 0 Before allocating a memory of size M , check whether Total_Allocated_Memory + M < Maximum_Allocatable_Memory If yes : Allocate memory ; Add M to Total_Allocated_Memory . If no : Return an error and gracefully stop your program instead of a crash which will loose data . It's a fortran program. I'm not very stong in C. Ideally I'd just use the OS (shell) means, but I need to understand better which resourse limit controls what. For example, with sh limits(1), I see: $ limits Resource limits (current): cputime infinity secs filesize infinity kB datasize 524168 kB stacksize 524168 kB coredumpsize infinity kB memoryuse infinity kB memorylocked 64 kB maxprocesses 12200 openfiles 117594 sbsize infinity bytes vmemoryuse infinity kB pseudo-terminals infinity swapuse infinity kB $ Which of these are relevant to my case? Finally, the actual problem is on linux, but I hope if I'm able to understand how things work on FreeBSD, then I could do it on linux too, especially if it's just a sh command. Thanks Anton