From owner-svn-src-all@freebsd.org Mon Jan 7 22:10:49 2019 Return-Path: Delivered-To: svn-src-all@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 BC18114A145A; Mon, 7 Jan 2019 22:10:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 62EFB83A6C; Mon, 7 Jan 2019 22:10:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3D6811E160; Mon, 7 Jan 2019 22:10:49 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x07MAnL6096062; Mon, 7 Jan 2019 22:10:49 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x07MAm67096060; Mon, 7 Jan 2019 22:10:48 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201901072210.x07MAm67096060@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Mon, 7 Jan 2019 22:10:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r342853 - in head: lib/libc/sys sys/vm X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head: lib/libc/sys sys/vm X-SVN-Commit-Revision: 342853 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 62EFB83A6C X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.98)[-0.980,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.998,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2019 22:10:50 -0000 Author: kib Date: Mon Jan 7 22:10:48 2019 New Revision: 342853 URL: https://svnweb.freebsd.org/changeset/base/342853 Log: Add a tunable which changes mincore(2) algorithm to only report data from the local mapping. Enable the setting by default. The article behind the change: https://arxiv.org/abs/1901.01161 Reviewed by: markj Discussed with: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D18764 Modified: head/lib/libc/sys/mincore.2 head/sys/vm/vm_mmap.c Modified: head/lib/libc/sys/mincore.2 ============================================================================== --- head/lib/libc/sys/mincore.2 Mon Jan 7 19:39:31 2019 (r342852) +++ head/lib/libc/sys/mincore.2 Mon Jan 7 22:10:48 2019 (r342853) @@ -28,7 +28,7 @@ .\" @(#)mincore.2 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd June 1, 2018 +.Dd January 7, 2019 .Dt MINCORE 2 .Os .Sh NAME @@ -47,7 +47,8 @@ system call determines whether each of the pages in th .Fa addr and continuing for .Fa len -bytes is resident. +bytes is resident or mapped, depending on the value of sysctl +.Va vm.mincore_mapped . .\"The beginning address, .\".Fa addr , .\"is first rounded down to a multiple of the page size (see @@ -85,6 +86,18 @@ The only way to ensure that a page is resident is to l with the .Xr mlock 2 system call. +.Pp +If the +.Va vm.mincore_mapped +sysctl is set to a non-zero value (default), only the current process' +mappings of the pages in the specified virtual address range are examined. +This does not preclude the system from returning +.Dv MINCORE_REFERENCED_OTHER +and +.Dv MINCORE_MODIFIED_OTHER +statuses. +Otherwise, if the sysctl value is zero, all resident pages backing the +specified address range are examined, regardless of the mapping state. .Sh RETURN VALUES .Rv -std mincore .Sh ERRORS Modified: head/sys/vm/vm_mmap.c ============================================================================== --- head/sys/vm/vm_mmap.c Mon Jan 7 19:39:31 2019 (r342852) +++ head/sys/vm/vm_mmap.c Mon Jan 7 22:10:48 2019 (r342853) @@ -97,6 +97,9 @@ __FBSDID("$FreeBSD$"); int old_mlock = 0; SYSCTL_INT(_vm, OID_AUTO, old_mlock, CTLFLAG_RWTUN, &old_mlock, 0, "Do not apply RLIMIT_MEMLOCK on mlockall"); +static int mincore_mapped = 1; +SYSCTL_INT(_vm, OID_AUTO, mincore_mapped, CTLFLAG_RWTUN, &mincore_mapped, 0, + "mincore reports mappings, not residency"); #ifdef MAP_32BIT #define MAP_32BIT_MAX_ADDR ((vm_offset_t)1 << 31) @@ -808,7 +811,16 @@ RestartScan: retry: m = NULL; mincoreinfo = pmap_mincore(pmap, addr, &locked_pa); - if (locked_pa != 0) { + if (mincore_mapped) { + /* + * We only care about this pmap's + * mapping of the page, if any. + */ + if (locked_pa != 0) { + vm_page_unlock(PHYS_TO_VM_PAGE( + locked_pa)); + } + } else if (locked_pa != 0) { /* * The page is mapped by this process but not * both accessed and modified. It is also