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/vm/vm_zone.h

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, 1998 John S. Dyson
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *      notice immediately at the beginning of the file, without modification,
   10  *      this list of conditions, and the following disclaimer.
   11  * 2. Absolutely no warranty of function or purpose is made by the author
   12  *      John S. Dyson.
   13  *
   14  * $FreeBSD$
   15  */
   16 
   17 #ifndef _SYS_ZONE_H
   18 
   19 #define _SYS_ZONE_H
   20 
   21 #define ZONE_INTERRUPT 1 /* Use this if you need to allocate at int time */
   22 #define ZONE_BOOT 16     /* This is an internal flag used by zbootinit */
   23 
   24 #include        <machine/lock.h>
   25 
   26 typedef struct vm_zone {
   27         struct simplelock zlock;        /* lock for data structure */
   28         void            *zitems;        /* linked list of items */
   29         int             zfreecnt;       /* free entries */
   30         int             zfreemin;       /* minimum number of free entries */
   31         int             znalloc;        /* number of allocations */
   32         vm_offset_t     zkva;           /* Base kva of zone */
   33         int             zpagecount;     /* Total # of allocated pages */
   34         int             zpagemax;       /* Max address space */
   35         int             zmax;           /* Max number of entries allocated */
   36         int             ztotal;         /* Total entries allocated now */
   37         int             zsize;          /* size of each entry */
   38         int             zalloc;         /* hint for # of pages to alloc */
   39         int             zflags;         /* flags for zone */
   40         int             zallocflag;     /* flag for allocation */
   41         struct vm_object *zobj;         /* object to hold zone */
   42         char            *zname;         /* name for diags */
   43         struct vm_zone  *znext;         /* list of zones for sysctl */
   44 } *vm_zone_t;
   45 
   46 
   47 void            zerror __P((int)) __dead2;
   48 vm_zone_t       zinit __P((char *name, int size, int nentries, int flags,
   49                            int zalloc));
   50 int             zinitna __P((vm_zone_t z, struct vm_object *obj, char *name,
   51                              int size, int nentries, int flags, int zalloc));
   52 static void *   zalloc __P((vm_zone_t z));
   53 static void     zfree __P((vm_zone_t z, void *item));
   54 void *          zalloci __P((vm_zone_t z));
   55 void            zfreei __P((vm_zone_t z, void *item));
   56 void            zbootinit __P((vm_zone_t z, char *name, int size, void *item,
   57                                int nitems));
   58 void *          _zget __P((vm_zone_t z));
   59 
   60 #define ZONE_ERROR_INVALID 0
   61 #define ZONE_ERROR_NOTFREE 1
   62 #define ZONE_ERROR_ALREADYFREE 2
   63 
   64 #define ZONE_ROUNDING   32
   65 
   66 #define ZENTRY_FREE     0x12342378
   67 /*
   68  * void *zalloc(vm_zone_t zone) --
   69  *      Returns an item from a specified zone.
   70  *
   71  * void zfree(vm_zone_t zone, void *item) --
   72  *  Frees an item back to a specified zone.
   73  */
   74 static __inline__ void *
   75 _zalloc(vm_zone_t z)
   76 {
   77         void *item;
   78 
   79 #ifdef INVARIANTS
   80         if (z == 0)
   81                 zerror(ZONE_ERROR_INVALID);
   82 #endif
   83 
   84         if (z->zfreecnt <= z->zfreemin)
   85                 return _zget(z);
   86 
   87         item = z->zitems;
   88         z->zitems = ((void **) item)[0];
   89 #ifdef INVARIANTS
   90         if (((void **) item)[1] != (void *) ZENTRY_FREE)
   91                 zerror(ZONE_ERROR_NOTFREE);
   92         ((void **) item)[1] = 0;
   93 #endif
   94 
   95         z->zfreecnt--;
   96         z->znalloc++;
   97         return item;
   98 }
   99 
  100 static __inline__ void
  101 _zfree(vm_zone_t z, void *item)
  102 {
  103         ((void **) item)[0] = z->zitems;
  104 #ifdef INVARIANTS
  105         if (((void **) item)[1] == (void *) ZENTRY_FREE)
  106                 zerror(ZONE_ERROR_ALREADYFREE);
  107         ((void **) item)[1] = (void *) ZENTRY_FREE;
  108 #endif
  109         z->zitems = item;
  110         z->zfreecnt++;
  111 }
  112 
  113 static __inline__ void *
  114 zalloc(vm_zone_t z)
  115 {
  116 #if defined(SMP)
  117         return zalloci(z);
  118 #else
  119         return _zalloc(z);
  120 #endif
  121 }
  122 
  123 static __inline__ void
  124 zfree(vm_zone_t z, void *item)
  125 {
  126 #ifdef SMP
  127         zfreei(z, item);
  128 #else
  129         _zfree(z, item);
  130 #endif
  131 }
  132 
  133 #endif

Cache object: c2aa4051558b6444db199dddc6f19c66


[ 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.