From owner-svn-src-projects@FreeBSD.ORG Fri Jun 29 14:15:55 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9C6301065673; Fri, 29 Jun 2012 14:15:55 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E78F8FC0C; Fri, 29 Jun 2012 14:15:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5TEFtEo050200; Fri, 29 Jun 2012 14:15:55 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5TEFtTo050198; Fri, 29 Jun 2012 14:15:55 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201206291415.q5TEFtTo050198@svn.freebsd.org> From: Attilio Rao Date: Fri, 29 Jun 2012 14:15:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237781 - projects/amd64_xen_pv/sys/amd64/xen X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jun 2012 14:15:55 -0000 Author: attilio Date: Fri Jun 29 14:15:54 2012 New Revision: 237781 URL: http://svn.freebsd.org/changeset/base/237781 Log: Introduce a new allocator backed by numa to replace mmu_alloc() as long as it is safe to go with it. Please note that the interface needs to be cleaned up in order to just allow page size allocation and not pass an arbitrary length. Reviewed by: cherry Modified: projects/amd64_xen_pv/sys/amd64/xen/pmap.c Modified: projects/amd64_xen_pv/sys/amd64/xen/pmap.c ============================================================================== --- projects/amd64_xen_pv/sys/amd64/xen/pmap.c Fri Jun 29 14:14:49 2012 (r237780) +++ projects/amd64_xen_pv/sys/amd64/xen/pmap.c Fri Jun 29 14:15:54 2012 (r237781) @@ -10,6 +10,8 @@ * All rights reserved. * Copyright (c) 2012 Spectra Logic Corporation * All rights reserved. + * Copyright (c) 2012 Citrix Systems + * All rights reserved. * * This code is derived from software contributed to Berkeley by * the Systems Programming Group of the University of Utah Computer @@ -120,6 +122,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -136,6 +139,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -179,6 +183,7 @@ static vm_paddr_t boot_ptendphys; /* phy * bootstrap page tables */ +static uma_zone_t xen_pagezone; static size_t tsz; /* mmu_map.h opaque cookie size */ static vm_offset_t (*ptmb_mappedalloc)(size_t) = NULL; static void (*ptmb_mappedfree)(size_t) = NULL; @@ -1160,3 +1165,51 @@ pmap_change_attr(vm_offset_t va, vm_size KASSERT(0, ("XXX: TODO\n")); return -1; } + +static vm_offset_t +xen_pagezone_alloc(size_t size) +{ + vm_offset_t ret; + + KASSERT(size == PAGE_SIZE, ("%s: invalid size", __func__)); + + ret = (vm_offset_t)uma_zalloc(xen_pagezone, M_NOWAIT | M_ZERO); + if (ret == 0) + panic("%s: failed allocation\n", __func__); + return (ret); +} + +static void +xen_pagezone_free(vm_offset_t page) +{ + + uma_zfree(xen_pagezone, (void *)page); +} + +static int +xen_pagezone_init(void *mem, int size, int flags) +{ + vm_offset_t va; + + va = (vm_offset_t)mem; + + /* Xen requires the page table hierarchy to be R/O. */ + pmap_xen_setpages_ro(va, atop(size)); + return (0); +} + +/* + * Replace the custom mmu_alloc(), backed by vallocpages(), with an + * uma backed allocator, as soon as it is possible. + */ +static void +setup_xen_pagezone(void *dummy __unused) +{ + + xen_pagezone = uma_zcreate("XEN PAGEZONE", PAGE_SIZE, NULL, NULL, + xen_pagezone_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_VM); + ptmb_mappedalloc = xen_pagezone_alloc; + ptmb_mappedfree = xen_pagezone_free; +} +SYSINIT(setup_xen_pagezone, SI_SUB_VM_CONF, SI_ORDER_ANY, setup_xen_pagezone, + NULL);