linux/drivers/staging/lustre/lustre/libcfs/linux/linux-mem.c
<<
>>
Prefs
   1/*
   2 * This program is free software; you can redistribute it and/or modify
   3 * it under the terms of the GNU General Public License version 2 only,
   4 * as published by the Free Software Foundation.
   5 *
   6 * This program is distributed in the hope that it will be useful, but
   7 * WITHOUT ANY WARRANTY; without even the implied warranty of
   8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   9 * General Public License version 2 for more details (a copy is included
  10 * in the LICENSE file that accompanied this code).
  11 *
  12 * You should have received a copy of the GNU General Public License
  13 * version 2 along with this program; If not, see
  14 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  15 *
  16 */
  17/*
  18 * This file creates a memory allocation primitive for Lustre, that
  19 * allows to fallback to vmalloc allocations should regular kernel allocations
  20 * fail due to size or system memory fragmentation.
  21 *
  22 * Author: Oleg Drokin <green@linuxhacker.ru>
  23 *
  24 */
  25/*
  26 * This file is part of Lustre, http://www.lustre.org/
  27 * Lustre is a trademark of Seagate Technology.
  28 */
  29#include <linux/slab.h>
  30#include <linux/vmalloc.h>
  31
  32#include "../../../include/linux/libcfs/libcfs.h"
  33
  34void *libcfs_kvzalloc(size_t size, gfp_t flags)
  35{
  36        void *ret;
  37
  38        ret = kzalloc(size, flags | __GFP_NOWARN);
  39        if (!ret)
  40                ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
  41        return ret;
  42}
  43EXPORT_SYMBOL(libcfs_kvzalloc);
  44
  45void *libcfs_kvzalloc_cpt(struct cfs_cpt_table *cptab, int cpt, size_t size,
  46                          gfp_t flags)
  47{
  48        void *ret;
  49
  50        ret = kzalloc_node(size, flags | __GFP_NOWARN,
  51                           cfs_cpt_spread_node(cptab, cpt));
  52        if (!ret) {
  53                WARN_ON(!(flags & (__GFP_FS|__GFP_HIGH)));
  54                ret = vmalloc_node(size, cfs_cpt_spread_node(cptab, cpt));
  55        }
  56
  57        return ret;
  58}
  59EXPORT_SYMBOL(libcfs_kvzalloc_cpt);
  60