From owner-freebsd-mips@FreeBSD.ORG Thu Jun 3 05:30:06 2010 Return-Path: Delivered-To: mips@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0975C1065670 for ; Thu, 3 Jun 2010 05:30:06 +0000 (UTC) (envelope-from alc@imimic.com) Received: from mail.cs.rice.edu (mail.cs.rice.edu [128.42.1.31]) by mx1.freebsd.org (Postfix) with ESMTP id C87C88FC0C for ; Thu, 3 Jun 2010 05:30:05 +0000 (UTC) Received: from mail.cs.rice.edu (localhost.localdomain [127.0.0.1]) by mail.cs.rice.edu (Postfix) with ESMTP id BE6F12C2AAC for ; Wed, 2 Jun 2010 23:59:27 -0500 (CDT) X-Virus-Scanned: by amavis-2.4.0 at mail.cs.rice.edu Received: from mail.cs.rice.edu ([127.0.0.1]) by mail.cs.rice.edu (mail.cs.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QvJxFThEkpU5; Wed, 2 Jun 2010 23:59:18 -0500 (CDT) Received: from adsl-216-63-78-18.dsl.hstntx.swbell.net (adsl-216-63-78-18.dsl.hstntx.swbell.net [216.63.78.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.cs.rice.edu (Postfix) with ESMTP id 333682C2A81; Wed, 2 Jun 2010 23:59:17 -0500 (CDT) Message-ID: <4C0736A5.1010101@imimic.com> Date: Wed, 02 Jun 2010 23:59:17 -0500 From: Alan Cox Organization: iMimic Networking, Inc. User-Agent: Thunderbird 2.0.0.24 (X11/20100501) MIME-Version: 1.0 To: mips@freebsd.org Content-Type: multipart/mixed; boundary="------------070309000303080603080902" Cc: Alan Cox Subject: init_pte_prot() patch X-BeenThere: freebsd-mips@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to MIPS List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2010 05:30:06 -0000 This is a multi-part message in MIME format. --------------070309000303080603080902 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I would appreciate it if someone would test the attached patch. (A "buildworld" would probably suffice.) Essentially, it does two things: 1. The virtual memory system only cares about the contents of a page's dirty field if that page is managed (i.e., it is pageable). And, in fact, if you survey the calls to vm_page_dirty() in the MIPS or any other pmap, they are generally conditioned on the mapping having been for a managed page. The MIPS pmap_enter() is an exception to this rule. It is unconditionally calling vm_page_dirty() on any page mapped within the kernel address space, managed or otherwise. In fact, it is highly unusual for pmap_enter() to be calling vm_page_dirty() on the page being mapped, regardless of whether it is managed. This call to vm_page_dirty() shouldn't be needed if change #2 below is also made. The attached patch eliminates the call. 2. Since the virtual memory system only cares about the contents of a page's dirty field if that page is managed, then dirty bit emulation need only be performed on managed pages. At present, init_pte_prot() skips emulation if the address being mapped is in the kernel. However, this is not really the right condition to test for. There do exist some managed pages in the kernel address space, and it is also possible through System V shared memory to have unmanaged pages in the user address space. The attached patch bases the emulation decision on whether the page is managed. Thanks, Alan --------------070309000303080603080902 Content-Type: text/plain; name="init_pte_prot.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="init_pte_prot.patch" Index: mips/mips/pmap.c =================================================================== --- mips/mips/pmap.c (revision 208667) +++ mips/mips/pmap.c (working copy) @@ -3067,26 +3067,20 @@ page_is_managed(vm_offset_t pa) static int init_pte_prot(vm_offset_t va, vm_page_t m, vm_prot_t prot) { - int rw = 0; + int rw; if (!(prot & VM_PROT_WRITE)) rw = PTE_ROPAGE; - else { - if (va >= VM_MIN_KERNEL_ADDRESS) { - /* - * Don't bother to trap on kernel writes, just - * record page as dirty. - */ + else if ((m->flags & (PG_FICTITIOUS | PG_UNMANAGED)) == 0) { + if ((m->md.pv_flags & PV_TABLE_MOD) != 0) rw = PTE_RWPAGE; - vm_page_dirty(m); - } else if ((m->md.pv_flags & PV_TABLE_MOD) || - m->dirty == VM_PAGE_BITS_ALL) - rw = PTE_RWPAGE; else rw = PTE_CWPAGE; vm_page_flag_set(m, PG_WRITEABLE); - } - return rw; + } else + /* Needn't emulate a modified bit for unmanaged pages. */ + rw = PTE_RWPAGE; + return (rw); } /* --------------070309000303080603080902--