cregit-Linux how code gets into the kernel

Release 4.10 fs/xfs/kmem.c

Directory: fs/xfs
/*
 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include <linux/mm.h>
#include <linux/highmem.h>
#include <linux/slab.h>
#include <linux/swap.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include "kmem.h"
#include "xfs_message.h"

/*
 * Greedy allocation.  May fail and may return vmalloced memory.
 */

void * kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize) { void *ptr; size_t kmsize = maxsize; while (!(ptr = vzalloc(kmsize))) { if ((kmsize >>= 1) <= minsize) kmsize = minsize; } if (ptr) *size = kmsize; return ptr; }

Contributors

PersonTokensPropCommitsCommitProp
christoph hellwigchristoph hellwig6498.46%150.00%
dave chinnerdave chinner11.54%150.00%
Total65100.00%2100.00%


void * kmem_alloc(size_t size, xfs_km_flags_t flags) { int retries = 0; gfp_t lflags = kmem_flags_convert(flags); void *ptr; do { ptr = kmalloc(size, lflags); if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP))) return ptr; if (!(++retries % 100)) xfs_err(NULL, "%s(%u) possible memory allocation deadlock size %u in %s (mode:0x%x)", current->comm, current->pid, (unsigned int)size, __func__, lflags); congestion_wait(BLK_RW_ASYNC, HZ/50); } while (1); }

Contributors

PersonTokensPropCommitsCommitProp
nathan scottnathan scott8478.50%220.00%
tetsuo handatetsuo handa87.48%110.00%
eric sandeeneric sandeen76.54%110.00%
dave chinnerdave chinner32.80%110.00%
al viroal viro21.87%220.00%
andrew mortonandrew morton10.93%110.00%
harvey harrisonharvey harrison10.93%110.00%
jens axboejens axboe10.93%110.00%
Total107100.00%10100.00%


void * kmem_zalloc_large(size_t size, xfs_km_flags_t flags) { unsigned noio_flag = 0; void *ptr; gfp_t lflags; ptr = kmem_zalloc(size, flags | KM_MAYFAIL); if (ptr) return ptr; /* * __vmalloc() will allocate data pages and auxillary structures (e.g. * pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context * here. Hence we need to tell memory reclaim that we are in such a * context via PF_MEMALLOC_NOIO to prevent memory reclaim re-entering * the filesystem here and potentially deadlocking. */ if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS)) noio_flag = memalloc_noio_save(); lflags = kmem_flags_convert(flags); ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS)) memalloc_noio_restore(noio_flag); return ptr; }

Contributors

PersonTokensPropCommitsCommitProp
dave chinnerdave chinner10898.18%266.67%
nathan scottnathan scott21.82%133.33%
Total110100.00%3100.00%


void * kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags) { int retries = 0; gfp_t lflags = kmem_flags_convert(flags); void *ptr; do { ptr = krealloc(old, newsize, lflags); if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP))) return ptr; if (!(++retries % 100)) xfs_err(NULL, "%s(%u) possible memory allocation deadlock size %zu in %s (mode:0x%x)", current->comm, current->pid, newsize, __func__, lflags); congestion_wait(BLK_RW_ASYNC, HZ/50); } while (1); }

Contributors

PersonTokensPropCommitsCommitProp
christoph hellwigchristoph hellwig6861.82%120.00%
nathan scottnathan scott3935.45%120.00%
al viroal viro10.91%120.00%
barry naujokbarry naujok10.91%120.00%
dave chinnerdave chinner10.91%120.00%
Total110100.00%5100.00%


void * kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags) { int retries = 0; gfp_t lflags = kmem_flags_convert(flags); void *ptr; do { ptr = kmem_cache_alloc(zone, lflags); if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP))) return ptr; if (!(++retries % 100)) xfs_err(NULL, "%s(%u) possible memory allocation deadlock in %s (mode:0x%x)", current->comm, current->pid, __func__, lflags); congestion_wait(BLK_RW_ASYNC, HZ/50); } while (1); }

Contributors

PersonTokensPropCommitsCommitProp
nathan scottnathan scott8583.33%222.22%
tetsuo handatetsuo handa98.82%111.11%
dave chinnerdave chinner32.94%111.11%
al viroal viro21.96%222.22%
jens axboejens axboe10.98%111.11%
andrew mortonandrew morton10.98%111.11%
harvey harrisonharvey harrison10.98%111.11%
Total102100.00%9100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
nathan scottnathan scott22643.46%422.22%
christoph hellwigchristoph hellwig13225.38%211.11%
dave chinnerdave chinner12023.08%316.67%
tetsuo handatetsuo handa173.27%15.56%
eric sandeeneric sandeen71.35%15.56%
al viroal viro50.96%211.11%
andrew mortonandrew morton50.96%15.56%
tejun heotejun heo30.58%15.56%
jens axboejens axboe20.38%15.56%
harvey harrisonharvey harrison20.38%15.56%
barry naujokbarry naujok10.19%15.56%
Total520100.00%18100.00%
Directory: fs/xfs
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.