From owner-freebsd-hackers@FreeBSD.ORG Fri Mar 29 13:57:31 2013 Return-Path: Delivered-To: freebsd-hackers@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 B6229778 for ; Fri, 29 Mar 2013 13:57:31 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-da0-x230.google.com (mail-da0-x230.google.com [IPv6:2607:f8b0:400e:c00::230]) by mx1.freebsd.org (Postfix) with ESMTP id 90BDE715 for ; Fri, 29 Mar 2013 13:57:31 +0000 (UTC) Received: by mail-da0-f48.google.com with SMTP id p8so229626dan.7 for ; Fri, 29 Mar 2013 06:57:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=qYUFuSq104eyNTHjaOnxikd7SQNUAJorVb6UQrXcO5Q=; b=s2b9ivmk0sgaIKpns3xo4KUIrLL6ztyTL3DxxLQVZ2J0VqQe4wX5eBkMcB4+kqJscM ua+B/jF/5sDLUJhdfDSU0XHBXJbD4JZ0EM1Iw4ChHD9QCp6UmUFuvrbjqE0dU+Dongbg skY0iGKZjfsNth2gfNwdwD1Zzr+wCh0Fr93oY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:x-gm-message-state; bh=qYUFuSq104eyNTHjaOnxikd7SQNUAJorVb6UQrXcO5Q=; b=M9+12NXykJiWOuwh/jW4cbKxj65I40cb2m1NTe2z7O2G6l4x0Quic06lbNVIG0fZpQ bdN37ABETAJPywdDm214IK3X2aeb2L6vKjpe0xcZxKgFK0zXFTrsbDceBWSitKzFJzgh MZMJGudNfo4z9TnU33mG2oLsz03c6YxyX27QlR2ntjdP9vmYEuHk2fbjf8Xz9H+28NO2 KR9iCFd85sICwca+w6KnRPryYwazU4AgdDxwL0knGKK7QXU++AbNjU4mkoS3UA1knqs7 7VsSJ2JC56peIjka0K7hCX/ZtOW9+8eTVTLljT1y5igj9j8lQaFZ6np2NZWyVzpTWPRX sDEQ== X-Received: by 10.66.233.34 with SMTP id tt2mr4425935pac.160.1364565451167; Fri, 29 Mar 2013 06:57:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.66.246.3 with HTTP; Fri, 29 Mar 2013 06:57:01 -0700 (PDT) In-Reply-To: <51559451.9050708@rodperson.com> References: <5156316F.9050202@rodperson.com> <20130329032845.GG81066@server.rulingia.com> <44li962xmp.fsf@lowell-desk.lan> <51559451.9050708@rodperson.com> From: Eitan Adler Date: Fri, 29 Mar 2013 09:57:01 -0400 Message-ID: Subject: Re: Help porting Linux app - getting Free Memory and Real Memory To: Rod Person Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQkdi7h9emSlZScTDS4I/hRjFkacEvhsFyO5K23Q5s3cVig5VXtGc38BGAYJdwniqLL+8Bzn Cc: Lowell Gilbert , freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2013 13:57:31 -0000 On 29 March 2013 09:17, Rod Person wrote: > On 03/29/13 08:34, Lowell Gilbert wrote: >> Peter Jeremy writes: >> >>> On 2013-Mar-29 20:27:27 -0400, Rod Person wrote: >>>> Everything is going we except that the program gives warnings that there >>>> isn't enough free memory on the system to perform certain actions. >>> That premise sounds suspiciously like the upstream author doesn't >>> understand how Unix VM works. >> To be more blunt, these checks may well be useless on Linux. >> On a quick look, you seem to maintain three ports: idutils, mspdebug, >> and jogl. I wouldn't expect a free-memory check to be appropriate on any >> of those. > Really? The port in question if graphics/fotoxx. I have no involvement > in the others. For the latter two, I'm not even sure what they are. > >> In any case, the definition of "free memory" is different between the VM >> systems in Linux and BSD . Even if the checks do make sense, the FreeBSD >> implementation would at the minimum have to include all of the pages >> that are allocated but not mapped. > Yes I have read this. Fotoxx uses free memory calculation when applying > effects to images. It looks at the image size then calculates how much > memory it needs to apply an effect, such as image sharpening. For > example, on a 4.5MB jpg file it seems to calculate that 40MB of free > memory is need to apply sharpening to the image. 40MB doesn't seem like > a lot of memory to me, but since the application way of figuring free > memory is Linux specific the warning dialog appear, although it seem to > have no ill effect on actually applying the sharpening effect. This is also racy and wrong. The application has the memory free (I doubt it allocates 2^32 = bytes of space). What happens if I start 1000 of this programs at the same time, the each check the free memory at the same time, find it to be sufficient, allocate memory, and it now becomes insufficient according to the program? The application should trust the operating system to manage this correctly unless it has *very* good reason not to (for instance, database programs often perform their own swapping/paging). My suggestion if you are to patch this program at all is to remove the check entirely and submit this upstream. -- Eitan Adler