From owner-svn-src-head@freebsd.org Sat Mar 3 08:48:17 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 99173F2708F; Sat, 3 Mar 2018 08:48:17 +0000 (UTC) (envelope-from danfe@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4F7D775468; Sat, 3 Mar 2018 08:48:17 +0000 (UTC) (envelope-from danfe@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1033) id 4766A49F9; Sat, 3 Mar 2018 08:48:17 +0000 (UTC) Date: Sat, 3 Mar 2018 08:48:17 +0000 From: Alexey Dokuchaev To: Alan Cox Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r309017 - in head/sys: cddl/compat/opensolaris/sys compat/linprocfs fs/tmpfs sys vm Message-ID: <20180303084817.GA66382@FreeBSD.org> References: <201611221813.uAMIDkHQ071392@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201611221813.uAMIDkHQ071392@repo.freebsd.org> User-Agent: Mutt/1.9.2 (2017-12-15) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Mar 2018 08:48:17 -0000 On Tue, Nov 22, 2016 at 06:13:46PM +0000, Alan Cox wrote: > New Revision: 309017 > URL: https://svnweb.freebsd.org/changeset/base/309017 > > Log: > Remove PG_CACHED-related fields from struct vmmeter, because they are no > longer used. More precisely, they are always zero because the code that > decremented and incremented them no longer exists. > > Bump __FreeBSD_version to mark this change. > > Reviewed by: kib, markj > Sponsored by: Dell EMC Isilon > Differential Revision: https://reviews.freebsd.org/D8583 > > Modified: head/sys/cddl/compat/opensolaris/sys/kmem.h > ... > -#define freemem (vm_cnt.v_free_count + vm_cnt.v_cache_count) > +#define freemem vm_cnt.v_free_count This looks correct now. > Modified: head/sys/compat/linprocfs/linprocfs.c > ... > @@ -176,7 +176,7 @@ linprocfs_domeminfo(PFS_FILL_ARGS) > * like unstaticizing it just for linprocfs's sake. > */ > buffers = 0; > - cached = vm_cnt.v_cache_count * PAGE_SIZE; > + cached = vm_cnt.v_inactive_count * PAGE_SIZE; Some applications that make calculations based on the readings from the /usr/compat/linux/proc/meminfo are broken after this change, e.g. those that do things like: return (totalMem - (freeMem + buffers + cache)) / totalMem; because now free memory includes cached one, and above formula gives bogus negative result. In `sys/compat/linprocfs/linprocfs.c', memfree is calculated as follows: memtotal = physmem * PAGE_SIZE; /* * The correct thing here would be: * memfree = vm_cnt.v_free_count * PAGE_SIZE; memused = memtotal - memfree; * * but it might mislead linux binaries into thinking there * is very little memory left, so we cheat and tell them that * all memory that isn't wired down is free. */ memused = vm_cnt.v_wire_count * PAGE_SIZE; memfree = memtotal - memused; So, when vm.stats.vm.v_cache_count was yielding some (typically small) result, using the aforementioned trick made sense (because even when vm_cnt.v_free_count added to vm.stats.vm.v_cache_count it would still be rather small). This logic no longer applies after this change. On my 12-CURRENT i386 system, /usr/compat/linux/proc/meminfo reports: % cat /usr/compat/linux/proc/meminfo | head -4 MemTotal: 3132504 kB MemFree: 2925936 kB <<< that's a lot Buffers: 0 kB Cached: 2212196 kB <<< that's also a lot On an older 4.11-STABLE box (also i386), it reports: MemTotal: 521828 kB MemFree: 383976 kB MemShared: 7480 kB Buffers: 0 kB Cached: 22732 kB (can be added to MemFree and still < MemTotal) So either the "cheat" have to go away and vm_cnt.v_free_count used as it should, or cached memory should not be read from vm_cnt.v_inactive_count but estimated somehow else. Which approach would be more correct? ./danfe