1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>kmalloc</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="The Linux Kernel API"><link rel="up" href="mm.html#idp1123724580" title="The Slab Cache"><link rel="prev" href="mm.html" title="Chapter&#160;4.&#160;Memory Management in Linux"><link rel="next" href="API-kmalloc-array.html" title="kmalloc_array"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"><span class="phrase">kmalloc</span></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="mm.html">Prev</a>&#160;</td><th width="60%" align="center">The Slab Cache</th><td width="20%" align="right">&#160;<a accesskey="n" href="API-kmalloc-array.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="API-kmalloc"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>kmalloc &#8212; 
2  allocate memory
3 </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void * <b class="fsfunc">kmalloc </b>(</code></td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>&#160;</td><td>gfp_t <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1123730100"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>size</code></em></span></dt><dd><p>
4     how many bytes of memory are required.
5    </p></dd><dt><span class="term"><em class="parameter"><code>flags</code></em></span></dt><dd><p>
6     the type of memory to allocate.
7    </p></dd></dl></div></div><div class="refsect1"><a name="idp1123732764"></a><h2>Description</h2><p>
8   kmalloc is the normal method of allocating memory
9   for objects smaller than page size in the kernel.
10   </p><p>
11
12   The <em class="parameter"><code>flags</code></em> argument may be one of:
13   </p><p>
14
15   <code class="constant">GFP_USER</code> - Allocate memory on behalf of user.  May sleep.
16   </p><p>
17
18   <code class="constant">GFP_KERNEL</code> - Allocate normal kernel ram.  May sleep.
19   </p><p>
20
21   <code class="constant">GFP_ATOMIC</code> - Allocation will not sleep.  May use emergency pools.
22   For example, use this inside interrupt handlers.
23   </p><p>
24
25   <code class="constant">GFP_HIGHUSER</code> - Allocate pages from high memory.
26   </p><p>
27
28   <code class="constant">GFP_NOIO</code> - Do not do any I/O at all while trying to get memory.
29   </p><p>
30
31   <code class="constant">GFP_NOFS</code> - Do not make any fs calls while trying to get memory.
32   </p><p>
33
34   <code class="constant">GFP_NOWAIT</code> - Allocation will not sleep.
35   </p><p>
36
37   <code class="constant">__GFP_THISNODE</code> - Allocate node-local memory only.
38   </p><p>
39
40   <code class="constant">GFP_DMA</code> - Allocation suitable for DMA.
41   Should only be used for <code class="function">kmalloc</code> caches. Otherwise, use a
42   slab created with SLAB_DMA.
43   </p><p>
44
45   Also it is possible to set different flags by OR'ing
46   in one or more of the following additional <em class="parameter"><code>flags</code></em>:
47   </p><p>
48
49   <code class="constant">__GFP_COLD</code> - Request cache-cold pages instead of
50   trying to return cache-warm pages.
51   </p><p>
52
53   <code class="constant">__GFP_HIGH</code> - This allocation has high priority and may use emergency pools.
54   </p><p>
55
56   <code class="constant">__GFP_NOFAIL</code> - Indicate that this allocation is in no way allowed to fail
57   (think twice before using).
58   </p><p>
59
60   <code class="constant">__GFP_NORETRY</code> - If memory is not immediately available,
61   then give up at once.
62   </p><p>
63
64   <code class="constant">__GFP_NOWARN</code> - If allocation fails, don't issue any warnings.
65   </p><p>
66
67   <code class="constant">__GFP_REPEAT</code> - If allocation fails initially, try once more before failing.
68   </p><p>
69
70   There are other flags available as well, but these are not intended
71   for general use, and so are not documented here. For a full list of
72   potential flags, always refer to linux/gfp.h.
73</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="mm.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="mm.html#idp1123724580">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="API-kmalloc-array.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&#160;4.&#160;Memory Management in Linux&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;<span class="phrase">kmalloc_array</span></td></tr></table></div></body></html>
74