---
name: "kmalloc"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/kmalloc"
---

# kmalloc(9)

allocate memory

## NAME

kmalloc - allocate memory

## SYNOPSIS

**void \* kmalloc(size\_t** *size***, gfp\_t** *flags***);**

## ARGUMENTS

*size*

how many bytes of memory are required.

*flags*

the type of memory to allocate.

## DESCRIPTION

kmalloc is the normal method of allocating memory for objects smaller than page size in the kernel.

The *flags* argument may be one of:

**GFP\_USER** - Allocate memory on behalf of user. May sleep.

**GFP\_KERNEL** - Allocate normal kernel ram. May sleep.

**GFP\_ATOMIC** - Allocation will not sleep. May use emergency pools. For example, use this inside interrupt handlers.

**GFP\_HIGHUSER** - Allocate pages from high memory.

**GFP\_NOIO** - Do not do any I/O at all while trying to get memory.

**GFP\_NOFS** - Do not make any fs calls while trying to get memory.

**GFP\_NOWAIT** - Allocation will not sleep.

**\_\_GFP\_THISNODE** - Allocate node-local memory only.

**GFP\_DMA** - Allocation suitable for DMA. Should only be used for **kmalloc** caches. Otherwise, use a slab created with SLAB\_DMA.

Also it is possible to set different flags by OR'ing in one or more of the following additional *flags*:

**\_\_GFP\_COLD** - Request cache-cold pages instead of trying to return cache-warm pages.

**\_\_GFP\_HIGH** - This allocation has high priority and may use emergency pools.

**\_\_GFP\_NOFAIL** - Indicate that this allocation is in no way allowed to fail (think twice before using).

**\_\_GFP\_NORETRY** - If memory is not immediately available, then give up at once.

**\_\_GFP\_NOWARN** - If allocation fails, don't issue any warnings.

**\_\_GFP\_REPEAT** - If allocation fails initially, try once more before failing.

There are other flags available as well, but these are not intended for general use, and so are not documented here. For a full list of potential flags, always refer to linux/gfp.h.

## COPYRIGHT
