From owner-freebsd-i386@FreeBSD.ORG Wed Nov 24 18:20:27 2004 Return-Path: Delivered-To: freebsd-i386@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E95B116A4CF for ; Wed, 24 Nov 2004 18:20:26 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6612943D5E for ; Wed, 24 Nov 2004 18:20:26 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id iAOIKQ5Q028078 for ; Wed, 24 Nov 2004 18:20:26 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id iAOIKQRS028077; Wed, 24 Nov 2004 18:20:26 GMT (envelope-from gnats) Resent-Date: Wed, 24 Nov 2004 18:20:26 GMT Resent-Message-Id: <200411241820.iAOIKQRS028077@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-i386@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Denis Koreshkov Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 77C0116A4CE for ; Wed, 24 Nov 2004 18:13:57 +0000 (GMT) Received: from mail.icn.bmstu.ru (h133.net37.bmstu.ru [195.19.37.133]) by mx1.FreeBSD.org (Postfix) with ESMTP id B271043D39 for ; Wed, 24 Nov 2004 18:13:56 +0000 (GMT) (envelope-from deniskv@mail.ru) Received: by mail.icn.bmstu.ru (Postfix, from userid 8) id D7BD6932C3; Wed, 24 Nov 2004 21:13:59 +0300 (MSK) Received: from wk (Marx.icn.bmstu.ru [192.168.52.101]) by mail.icn.bmstu.ru (Postfix) with ESMTP id C10D193247 for ; Wed, 24 Nov 2004 21:13:58 +0300 (MSK) Message-Id: <7114180390.20041124211337@mail.ru> Date: Wed, 24 Nov 2004 21:13:37 +0300 From: Denis Koreshkov To: FreeBSD-gnats-submit@FreeBSD.org Subject: i386/74327: [PATCH] mlock() causes physical memory leakage X-BeenThere: freebsd-i386@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Denis Koreshkov List-Id: I386-specific issues for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2004 18:20:27 -0000 >Number: 74327 >Category: i386 >Synopsis: mlock() causes physical memory leakage >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-i386 >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Nov 24 18:20:26 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Denis Koreshkov >Release: FreeBSD 4.10-RELEASE i386 >Organization: >Environment: System: FreeBSD doscrypt 4.8-RELEASE FreeBSD 4.8-RELEASE #0: Sat Oct 30 02:38:01 MSD 2004 root@doscrypt:/usr/obj/usr/src/sys/LITE i386 >Description: On FreeBSD/i386, mlock()'ing an memory area cause underlying pages to become unusable (to both kernel and applications) following exit(), when the following conditions are met: 1) The area had already been accessed before a call to mlock(), and 2) No corresponding call to munlock() had been issued before exit(). >How-To-Repeat: 1) malloc() a few megs of memory, 2) bzero() it, 3) mlock() it, 4) exit(). sysctl vm.stats.vm.v_wire_count will have grown by the amount of pages locked >Fix: The bug is confined in pmap_enter() (file sys/i386/i386/pmap.c) One should toggle PG_W bit of pte to reflect wiring changes, as vm_fault_user_wire() does vm_fault() to bring pages into physmem. *** sys/i386/i386/pmap.c.orig Sun Nov 14 11:12:34 2004 --- sys/i386/i386/pmap.c Sun Nov 14 11:21:25 2004 *************** *** 1962,1971 **** * are valid mappings in them. Hence, if a user page is wired, * the PT page will be also. */ ! if (wired && ((origpte & PG_W) == 0)) pmap->pm_stats.wired_count++; ! else if (!wired && (origpte & PG_W)) pmap->pm_stats.wired_count--; #if defined(PMAP_DIAGNOSTIC) if (pmap_nw_modified((pt_entry_t) origpte)) { --- 1962,1974 ---- * are valid mappings in them. Hence, if a user page is wired, * the PT page will be also. */ ! if (wired && ((origpte & PG_W) == 0)) { ! *pte |= PG_W; pmap->pm_stats.wired_count++; ! } else if (!wired && (origpte & PG_W)) { ! *pte &= ~PG_W; pmap->pm_stats.wired_count--; + } #if defined(PMAP_DIAGNOSTIC) if (pmap_nw_modified((pt_entry_t) origpte)) { >Release-Note: >Audit-Trail: >Unformatted: