svn commit: r309017 - in head/sys: cddl/compat/opensolaris/sys compat/linprocfs fs/tmpfs sys vm
Alan Cox
alc at rice.edu
Sat Mar 3 19:15:32 UTC 2018
On 03/03/2018 02:48, Alexey Dokuchaev wrote:
> 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?
The former.
More information about the svn-src-head
mailing list