1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/libcfs/user-mem.c
38 * Userspace memory management.
43 #error "This is not kernel code."
46 #include <libcfs/libcfs.h>
49 #include <malloc.h> /* memalign declared here on linux */
56 cfs_page_t *cfs_alloc_pages(int mask, unsigned long order)
58 cfs_page_t *pg = malloc(sizeof(*pg));
62 #if 0 //#ifdef MAP_ANONYMOUS
63 pg->addr = mmap(0, PAGE_SIZE << order, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
64 #elif defined (__DARWIN__)
65 pg->addr = valloc(CFS_PAGE_SIZE << order);
67 pg->addr = memalign(CFS_PAGE_SIZE, CFS_PAGE_SIZE << order);
77 void cfs_free_pages(cfs_page_t *pg, int what)
79 #if 0 //#ifdef MAP_ANONYMOUS
80 munmap(pg->addr, PAGE_SIZE);
87 cfs_page_t *cfs_alloc_page(unsigned int flags)
89 cfs_page_t *pg = malloc(sizeof(*pg));
93 pg->addr = malloc(CFS_PAGE_SIZE);
102 void cfs_free_page(cfs_page_t *pg)
108 void *cfs_page_address(cfs_page_t *pg)
113 void *cfs_kmap(cfs_page_t *pg)
118 void cfs_kunmap(cfs_page_t *pg)
127 cfs_mem_cache_create(const char *name, size_t objsize, size_t off, unsigned long flags)
131 c = malloc(sizeof(*c));
135 CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n",
136 name, c, (int)objsize);
140 int cfs_mem_cache_destroy(cfs_mem_cache_t *c)
142 CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", c, c->size);
147 void *cfs_mem_cache_alloc(cfs_mem_cache_t *c, int gfp)
149 return cfs_alloc(c->size, gfp);
152 void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr)