The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/uipc_jumbo.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1997, Duke University
    3  * All rights reserved.
    4  *
    5  * Author:
    6  *         Andrew Gallatin <gallatin@cs.duke.edu>  
    7  *            
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. The name of Duke University may not be used to endorse or promote 
   17  *    products derived from this software without specific prior written 
   18  *    permission.
   19  * 
   20  * THIS SOFTWARE IS PROVIDED BY DUKE UNIVERSITY ``AS IS'' AND ANY
   21  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DUKE UNIVERSITY BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITSOR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
   28  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   30  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
   31  *
   32  * $FreeBSD: releng/5.1/sys/kern/uipc_jumbo.c 113720 2003-04-19 19:13:25Z alc $
   33  */
   34 /*
   35  * This is a set of routines for allocating large-sized mbuf payload
   36  * areas, and is primarily intended for use in receive side mbuf
   37  * allocation.
   38  */
   39 
   40 #include <sys/param.h>
   41 #include <sys/systm.h>
   42 #include <sys/types.h>
   43 #include <sys/sockio.h>
   44 #include <sys/uio.h>
   45 #include <sys/lock.h>
   46 #include <sys/kernel.h>
   47 #include <sys/mutex.h>
   48 #include <sys/malloc.h>
   49 #include <vm/vm.h>
   50 #include <vm/pmap.h>
   51 #include <vm/vm_extern.h>
   52 #include <vm/vm_map.h>
   53 #include <vm/vm_param.h>
   54 #include <vm/vm_pageout.h>
   55 #include <sys/vmmeter.h>
   56 #include <vm/vm_page.h>
   57 #include <vm/vm_object.h>
   58 #include <vm/vm_kern.h>
   59 #include <sys/proc.h>
   60 #include <sys/jumbo.h>
   61 
   62 /*
   63  * XXX this may be too high or too low.
   64  */
   65 #define JUMBO_MAX_PAGES 3072
   66 
   67 struct jumbo_kmap {
   68         vm_offset_t kva;
   69         SLIST_ENTRY(jumbo_kmap) entries;     /* Singly-linked List. */
   70 };
   71 
   72 static SLIST_HEAD(jumbo_kmap_head, jumbo_kmap) jumbo_kmap_free,
   73                                                jumbo_kmap_inuse;
   74 
   75 static struct mtx jumbo_mutex;
   76 MTX_SYSINIT(jumbo_lock, &jumbo_mutex, "jumbo mutex", MTX_DEF);
   77 
   78 static struct vm_object *jumbo_vm_object;
   79 static unsigned long jumbo_vmuiomove_pgs_freed = 0;
   80 #if 0
   81 static int jumbo_vm_wakeup_wanted = 0;
   82 #endif
   83 vm_offset_t jumbo_basekva;
   84 
   85 int
   86 jumbo_vm_init(void)
   87 {
   88         int i;
   89         struct jumbo_kmap *entry;
   90 
   91         mtx_lock(&jumbo_mutex);
   92 
   93         if (jumbo_vm_object != NULL) {
   94                 mtx_unlock(&jumbo_mutex);
   95                 return (1);
   96         }
   97 
   98         /* allocate our object */
   99         jumbo_vm_object = vm_object_allocate_wait(OBJT_DEFAULT, JUMBO_MAX_PAGES,
  100                                                   M_NOWAIT);
  101 
  102         if (jumbo_vm_object == NULL) {
  103                 mtx_unlock(&jumbo_mutex);
  104                 return (0);
  105         }
  106 
  107         SLIST_INIT(&jumbo_kmap_free);
  108         SLIST_INIT(&jumbo_kmap_inuse);
  109 
  110         /* grab some kernel virtual address space */
  111         jumbo_basekva = kmem_alloc_pageable(kernel_map,
  112                 PAGE_SIZE * JUMBO_MAX_PAGES);
  113         if (jumbo_basekva == 0) {
  114                 vm_object_deallocate(jumbo_vm_object);
  115                 jumbo_vm_object = NULL;
  116                 mtx_unlock(&jumbo_mutex);
  117                 return 0;
  118         }
  119         for (i = 0; i < JUMBO_MAX_PAGES; i++) {
  120                 entry = malloc(sizeof(struct jumbo_kmap), M_TEMP, M_NOWAIT);
  121                 if (!entry && !i)  {
  122                         mtx_unlock(&jumbo_mutex);
  123                         panic("jumbo_vm_init: unable to allocated kvas");
  124                 } else if (!entry) {
  125                         printf("warning: jumbo_vm_init allocated only %d kva\n",
  126                                i);
  127                         mtx_unlock(&jumbo_mutex);
  128                         return 1;
  129                 }
  130                 entry->kva = jumbo_basekva + (vm_offset_t)i * PAGE_SIZE;
  131                 SLIST_INSERT_HEAD(&jumbo_kmap_free, entry, entries);
  132         }
  133         mtx_unlock(&jumbo_mutex);
  134         return 1;
  135 }
  136 
  137 void
  138 jumbo_freem(void *addr, void *args)
  139 {
  140         vm_page_t frame;
  141 
  142         frame = PHYS_TO_VM_PAGE(pmap_kextract((vm_offset_t)addr));
  143 
  144         /*
  145          * Need giant for looking at the hold count below.  Convert this
  146          * to the vm mutex once the VM code has been moved out from under
  147          * giant.
  148          */
  149         GIANT_REQUIRED;
  150 
  151         if (frame->hold_count == 0)
  152                 jumbo_pg_free((vm_offset_t)addr);
  153         else
  154                 printf("jumbo_freem: hold count for %p is %d!!??\n",
  155                        frame, frame->hold_count);
  156 }
  157 
  158 void 
  159 jumbo_pg_steal(vm_page_t pg)
  160 {
  161         vm_offset_t addr;
  162         struct jumbo_kmap *entry;
  163 
  164         addr = ptoa(pg->pindex) + jumbo_basekva;
  165 
  166         if (pg->object != jumbo_vm_object)
  167                 panic("stealing a non jumbo_vm_object page");
  168         vm_page_remove(pg);
  169 
  170         mtx_lock(&jumbo_mutex);
  171 
  172         pmap_qremove(addr,1);
  173         entry = SLIST_FIRST(&jumbo_kmap_inuse);
  174         entry->kva = addr;
  175         SLIST_REMOVE_HEAD(&jumbo_kmap_inuse, entries);
  176         SLIST_INSERT_HEAD(&jumbo_kmap_free, entry, entries);
  177 
  178         mtx_unlock(&jumbo_mutex);
  179 
  180 #if 0
  181         if (jumbo_vm_wakeup_wanted)
  182                 wakeup(jumbo_vm_object);
  183 #endif
  184 }
  185 
  186 
  187 vm_page_t 
  188 jumbo_pg_alloc(void)
  189 {
  190         vm_page_t pg;
  191         vm_pindex_t pindex;
  192         struct jumbo_kmap *entry;
  193 
  194         pg = NULL;
  195         mtx_lock(&jumbo_mutex);
  196 
  197         entry = SLIST_FIRST(&jumbo_kmap_free);
  198         if (entry != NULL){
  199                 pindex = atop(entry->kva - jumbo_basekva);
  200                 VM_OBJECT_LOCK(jumbo_vm_object);
  201                 pg = vm_page_alloc(jumbo_vm_object, pindex, VM_ALLOC_INTERRUPT);
  202                 VM_OBJECT_UNLOCK(jumbo_vm_object);
  203                 if (pg != NULL) {
  204                         SLIST_REMOVE_HEAD(&jumbo_kmap_free, entries);
  205                         SLIST_INSERT_HEAD(&jumbo_kmap_inuse, entry, entries);
  206                         pmap_qenter(entry->kva, &pg, 1);
  207                 }
  208         }
  209         mtx_unlock(&jumbo_mutex);
  210         return(pg);
  211 }
  212 
  213 void 
  214 jumbo_pg_free(vm_offset_t addr)
  215 {
  216         struct jumbo_kmap *entry;
  217         vm_paddr_t paddr;
  218         vm_page_t pg;
  219 
  220         paddr = pmap_kextract((vm_offset_t)addr);
  221         pg = PHYS_TO_VM_PAGE(paddr);
  222 
  223         if (pg->object != jumbo_vm_object) {
  224                 jumbo_vmuiomove_pgs_freed++;
  225 /*              if(vm_page_lookup(jumbo_vm_object, atop(addr - jumbo_basekva)))
  226                         panic("vm_page_rename didn't");
  227                 printf("freeing uiomoved pg:\t pindex = %d, padd = 0x%lx\n",
  228                        atop(addr - jumbo_basekva), paddr);
  229 */
  230         } else {
  231                 vm_page_lock_queues();
  232                 vm_page_busy(pg); /* vm_page_free wants pages to be busy*/
  233                 vm_page_free(pg);
  234                 vm_page_unlock_queues();
  235         }
  236 
  237         mtx_lock(&jumbo_mutex);
  238 
  239         pmap_qremove(addr,1);
  240         entry = SLIST_FIRST(&jumbo_kmap_inuse);
  241         entry->kva = addr;
  242         SLIST_REMOVE_HEAD(&jumbo_kmap_inuse, entries);
  243         SLIST_INSERT_HEAD(&jumbo_kmap_free, entry, entries);
  244 
  245         mtx_unlock(&jumbo_mutex);
  246 
  247 #if 0
  248         if (jumbo_vm_wakeup_wanted)
  249                 wakeup(jumbo_vm_object);
  250 #endif
  251 }

Cache object: 0581f60a7758bf8616b540d17bb9018c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.