From owner-freebsd-questions@FreeBSD.ORG Sun Mar 10 00:18:24 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 CBB609DC for ; Sun, 10 Mar 2013 00:18:24 +0000 (UTC) (envelope-from m.e.sanliturk@gmail.com) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx1.freebsd.org (Postfix) with ESMTP id 88D7722F for ; Sun, 10 Mar 2013 00:18:24 +0000 (UTC) Received: by mail-ve0-f172.google.com with SMTP id cz11so2053618veb.3 for ; Sat, 09 Mar 2013 16:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=Kt8YEi6RKACkBwaKRSnHBcShCJ8IPJv+sqM9DD21tZs=; b=lABp/ca//dbzUkQFXXWigfhokQNFidFTG/Ex/TxLavu3cM4HTPqgma7vbPigDO1Otf mdy01EZucp1RWfu5IAfhQXozUkjog2Kqn9aH6U+YDE9soT9yLeryv+td62FCHz0eTv+3 MZ0iE8EBlDvtinAH6riar9LwQBV76qwc7S09qOHHkSRc/0V0DDbf4X1KfPodq7kZjrh4 3BnbVT8WVfYrInlB8tISUwwIlVAOKcykL3zSnm4zopx8ooLnlPnElX+QAzWYHyT5vx+I n2zsBK6qy/WtmsQWqfhr3HXoBCkII4ZPz8ML2Qdq7DLoxVOa6iaInaepo1kOSJpbK9pN xd/Q== MIME-Version: 1.0 X-Received: by 10.220.40.9 with SMTP id i9mr2919594vce.23.1362874703667; Sat, 09 Mar 2013 16:18:23 -0800 (PST) Received: by 10.58.220.33 with HTTP; Sat, 9 Mar 2013 16:18:23 -0800 (PST) In-Reply-To: <201303092355.r29NtRX4015510@mech-cluster241.men.bris.ac.uk> References: <201303092355.r29NtRX4015510@mech-cluster241.men.bris.ac.uk> Date: Sat, 9 Mar 2013 16:18:23 -0800 Message-ID: Subject: Re: how to forbid a process to use swap? From: Mehmet Erol Sanliturk To: mexas@bristol.ac.uk Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Mar 2013 00:18:24 -0000 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 . Thank you very much . Mehmet Erol Sanliturk