diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:59:05 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-04-25 19:59:05 -0400 |
| commit | 1f19f33e45791ea59aed048796fc68672c6723a5 (patch) | |
| tree | 54625fba89e91d1c2177801ec635e8528bba937f /static/netbsd/man9/kmem.9 3.html | |
| parent | ac5e55f5f2af5b92794c2aded46c6bae85b5f5ed (diff) | |
docs: Removed Precompiled HTML
Diffstat (limited to 'static/netbsd/man9/kmem.9 3.html')
| -rw-r--r-- | static/netbsd/man9/kmem.9 3.html | 297 |
1 files changed, 0 insertions, 297 deletions
diff --git a/static/netbsd/man9/kmem.9 3.html b/static/netbsd/man9/kmem.9 3.html deleted file mode 100644 index 1acd9611..00000000 --- a/static/netbsd/man9/kmem.9 3.html +++ /dev/null @@ -1,297 +0,0 @@ -<table class="head"> - <tr> - <td class="head-ltitle">KMEM(9)</td> - <td class="head-vol">Kernel Developer's Manual</td> - <td class="head-rtitle">KMEM(9)</td> - </tr> -</table> -<div class="manual-text"> -<section class="Sh"> -<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1> -<p class="Pp"><code class="Nm">kmem</code> — <span class="Nd">kernel - wired memory allocator</span></p> -</section> -<section class="Sh"> -<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1> -<p class="Pp"><code class="In">#include - <<a class="In">sys/kmem.h</a>></code></p> -<p class="Pp"><var class="Ft">void *</var> - <br/> - <code class="Fn">kmem_alloc</code>(<var class="Fa" style="white-space: nowrap;">size_t - size</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void *</var> - <br/> - <code class="Fn">kmem_zalloc</code>(<var class="Fa" style="white-space: nowrap;">size_t - size</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void</var> - <br/> - <code class="Fn">kmem_free</code>(<var class="Fa" style="white-space: nowrap;">void - *p</var>, <var class="Fa" style="white-space: nowrap;">size_t - size</var>);</p> -<p class="Pp"><var class="Ft">void *</var> - <br/> - <code class="Fn">kmem_intr_alloc</code>(<var class="Fa" style="white-space: nowrap;">size_t - size</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void *</var> - <br/> - <code class="Fn">kmem_intr_zalloc</code>(<var class="Fa" style="white-space: nowrap;">size_t - size</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void</var> - <br/> - <code class="Fn">kmem_intr_free</code>(<var class="Fa" style="white-space: nowrap;">void - *p</var>, <var class="Fa" style="white-space: nowrap;">size_t - size</var>);</p> -<p class="Pp"><var class="Ft">char *</var> - <br/> - <code class="Fn">kmem_asprintf</code>(<var class="Fa" style="white-space: nowrap;">const - char *fmt</var>, - <var class="Fa" style="white-space: nowrap;">...</var>);</p> -<p class="Pp"><var class="Ft">char *</var> - <br/> - <code class="Fn">kmem_strdupsize</code>(<var class="Fa" style="white-space: nowrap;">const - char *str</var>, <var class="Fa" style="white-space: nowrap;">size_t - *size</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">char *</var> - <br/> - <code class="Fn">kmem_strdup</code>(<var class="Fa" style="white-space: nowrap;">const - char *str</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">char *</var> - <br/> - <code class="Fn">kmem_strndup</code>(<var class="Fa" style="white-space: nowrap;">const - char *str</var>, <var class="Fa" style="white-space: nowrap;">size_t - manxlen</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void</var> - <br/> - <code class="Fn">kmem_strfree</code>(<var class="Fa" style="white-space: nowrap;">char - *str</var>);</p> -<p class="Pp"><var class="Ft">void *</var> - <br/> - <code class="Fn">kmem_tmpbuf_alloc</code>(<var class="Fa" style="white-space: nowrap;">size_t - size</var>, <var class="Fa" style="white-space: nowrap;">void - *stackbuf</var>, <var class="Fa" style="white-space: nowrap;">size_t - stackbufsize</var>, <var class="Fa" style="white-space: nowrap;">km_flag_t - kmflags</var>);</p> -<p class="Pp"><var class="Ft">void</var> - <br/> - <code class="Fn">kmem_tmpbuf_free</code>(<var class="Fa" style="white-space: nowrap;">void - *p</var>, <var class="Fa" style="white-space: nowrap;">size_t size</var>, - <var class="Fa" style="white-space: nowrap;">void *stackbuf</var>);</p> -<p class="Pp"> - <br/> - <code class="Cd">options KMEM_SIZE</code></p> -</section> -<section class="Sh"> -<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1> -<p class="Pp"><a class="permalink" href="#kmem_alloc"><code class="Fn" id="kmem_alloc">kmem_alloc</code></a>() - allocates kernel wired memory. It takes the following arguments.</p> -<dl class="Bl-tag"> - <dt><var class="Fa">size</var></dt> - <dd>Specify the size of allocation in bytes.</dd> - <dt><var class="Fa">kmflags</var></dt> - <dd>Either of the following: - <dl class="Bl-tag"> - <dt id="KM_SLEEP"><a class="permalink" href="#KM_SLEEP"><code class="Dv">KM_SLEEP</code></a></dt> - <dd>If the allocation cannot be satisfied immediately, sleep until enough - memory is available. If <code class="Dv">KM_SLEEP</code> is specified, - then the allocation cannot fail.</dd> - <dt id="KM_NOSLEEP"><a class="permalink" href="#KM_NOSLEEP"><code class="Dv">KM_NOSLEEP</code></a></dt> - <dd>Don't sleep. Immediately return <code class="Dv">NULL</code> if there - is not enough memory available. It should only be used when failure to - allocate will not have harmful, user-visible effects. - <p class="Pp"></p> - <div class="Bf Sy">Use of <code class="Dv">KM_NOSLEEP</code> is strongly - discouraged as it can create transient, hard to debug failures that - occur when the system is under memory pressure.</div> - <p class="Pp">In situations where it is not possible to sleep, for - example because locks are held by the caller, the code path should - be restructured to allow the allocation to be made in another - place.</p> - </dd> - </dl> - </dd> -</dl> -<p class="Pp">The contents of allocated memory are uninitialized.</p> -<p class="Pp">Unlike Solaris, kmem_alloc(0, flags) is illegal.</p> -<p class="Pp" id="kmem_zalloc"><a class="permalink" href="#kmem_zalloc"><code class="Fn">kmem_zalloc</code></a>() - is the equivalent of <code class="Fn">kmem_alloc</code>(), except that it - initializes the memory to zero.</p> -<p class="Pp" id="kmem_asprintf"><a class="permalink" href="#kmem_asprintf"><code class="Fn">kmem_asprintf</code></a>() - functions as the well known - <a class="permalink" href="#asprintf"><code class="Fn" id="asprintf">asprintf</code></a>() - function, but allocates memory using <code class="Fn">kmem_alloc</code>(). - This routine can sleep during allocation. The size of the allocated area is - the length of the returned character string, plus one (for the NUL - terminator). This must be taken into consideration when freeing the returned - area with <code class="Fn">kmem_free</code>().</p> -<p class="Pp" id="kmem_free"><a class="permalink" href="#kmem_free"><code class="Fn">kmem_free</code></a>() - frees kernel wired memory allocated by <code class="Fn">kmem_alloc</code>() - or <code class="Fn">kmem_zalloc</code>() so that it can be used for other - purposes. It takes the following arguments.</p> -<dl class="Bl-tag"> - <dt><var class="Fa">p</var></dt> - <dd>The pointer to the memory being freed. It must be the one returned by - <code class="Fn">kmem_alloc</code>() or - <code class="Fn">kmem_zalloc</code>().</dd> - <dt><var class="Fa">size</var></dt> - <dd>The size of the memory being freed, in bytes. It must be the same as the - <var class="Fa">size</var> argument used for - <code class="Fn">kmem_alloc</code>() or - <code class="Fn">kmem_zalloc</code>() when the memory was allocated.</dd> -</dl> -<p class="Pp">Freeing <code class="Dv">NULL</code> is illegal.</p> -<p class="Pp" id="kmem_intr_alloc"><a class="permalink" href="#kmem_intr_alloc"><code class="Fn">kmem_intr_alloc</code></a>(), - <a class="permalink" href="#kmem_intr_zalloc"><code class="Fn" id="kmem_intr_zalloc">kmem_intr_zalloc</code></a>() - and - <a class="permalink" href="#kmem_intr_free"><code class="Fn" id="kmem_intr_free">kmem_intr_free</code></a>() - are the equivalents of the above kmem routines which can be called from the - interrupt context. These routines are for the special cases. Normally, - <a class="Xr">pool_cache(9)</a> should be used for memory allocation from - interrupt context.</p> -<p class="Pp" id="kmem_strdupsize">The - <a class="permalink" href="#kmem_strdupsize"><code class="Fn">kmem_strdupsize</code></a>() - function is a utility function that can be used to copy the string in the - <var class="Fa">str</var> argument to a new buffer allocated using - <code class="Fn">kmem_alloc</code>() and optionally return the size of the - allocation (the length of the string plus the trailing - <code class="Dv">NUL</code>) in the <var class="Fa">size</var> argument if - that is not <code class="Dv">NULL</code>.</p> -<p class="Pp" id="kmem_strdup">The - <a class="permalink" href="#kmem_strdup"><code class="Fn">kmem_strdup</code></a>() - function is a simplified version of - <code class="Fn">kmem_strdupsize</code>() that does not return the size of - the allocation.</p> -<p class="Pp" id="kmem_strndup">The - <a class="permalink" href="#kmem_strndup"><code class="Fn">kmem_strndup</code></a>() - function is variation of <code class="Fn">kmem_strdup</code>() that copies - at most <var class="Fa">maxlen</var> characters from the string - <var class="Fa">str</var> always NUL terminating the copied string.</p> -<p class="Pp" id="kmem_strfree">The - <a class="permalink" href="#kmem_strfree"><code class="Fn">kmem_strfree</code></a>() - function can be used to free a <code class="Dv">NUL</code> terminated string - computing the length of the string using <a class="Xr">strlen(3)</a> and - adding one for the <code class="Dv">NUL</code> and then using - <code class="Fn">kmem_free</code>().</p> -<p class="Pp" id="kmem_tmpbuf_alloc">The - <a class="permalink" href="#kmem_tmpbuf_alloc"><code class="Fn">kmem_tmpbuf_alloc</code></a>() - function is a utility function for allocating memory for temporary use, - where allocation on the stack is desirable, but only up to a certain size. - If the requested size fits within the specified stack buffer, the stack - buffer is returned. Otherwise, memory is allocated with - <code class="Fn">kmem_alloc</code>(). The - <a class="permalink" href="#kmem_tmpbuf_free"><code class="Fn" id="kmem_tmpbuf_free">kmem_tmpbuf_free</code></a>() - function compares the result of a previous call to - <code class="Fn">kmem_tmpbuf_alloc</code>() and frees the memory using - <code class="Fn">kmem_free</code>() if it is not the specified stack - buffer.</p> -</section> -<section class="Sh"> -<h1 class="Sh" id="NOTES"><a class="permalink" href="#NOTES">NOTES</a></h1> -<p class="Pp">Making <code class="Dv">KM_SLEEP</code> allocations while holding - mutexes or reader/writer locks is discouraged, as the caller can sleep for - an unbounded amount of time in order to satisfy the allocation. This can in - turn block other threads that wish to acquire locks held by the caller. It - should be noted that <code class="Fn">kmem_free</code>() may also block.</p> -<p class="Pp">For some locks this is permissible or even unavoidable. For - others, particularly locks that may be taken from soft interrupt context, it - is a serious problem. As a general rule it is better not to allow this type - of situation to develop. One way to circumvent the problem is to make - allocations speculative and part of a retryable sequence. For example:</p> -<div class="Bd Pp Li"> -<pre> retry: - /* speculative unlocked check */ - if (need to allocate) { - new_item = kmem_alloc(sizeof(*new_item), KM_SLEEP); - } else { - new_item = NULL; - } - mutex_enter(lock); - /* check while holding lock for true status */ - if (need to allocate) { - if (new_item == NULL) { - mutex_exit(lock); - goto retry; - } - consume(new_item); - new_item = NULL; - } - mutex_exit(lock); - if (new_item != NULL) { - /* did not use it after all */ - kmem_free(new_item, sizeof(*new_item)); - }</pre> -</div> -</section> -<section class="Sh"> -<h1 class="Sh" id="OPTIONS"><a class="permalink" href="#OPTIONS">OPTIONS</a></h1> -<section class="Ss"> -<h2 class="Ss" id="KMEM_SIZE"><a class="permalink" href="#KMEM_SIZE">KMEM_SIZE</a></h2> -<p class="Pp">Kernels compiled with the <code class="Dv">KMEM_SIZE</code> option - ensure the size given in - <a class="permalink" href="#kmem_free~2"><code class="Fn" id="kmem_free~2">kmem_free</code></a>() - matches the actual allocated size. On <code class="Fn">kmem_alloc</code>(), - the kernel will allocate an additional contiguous kmem page of eight bytes - in the buffer, will register the allocated size in the first kmem page of - that buffer, and will return a pointer to the second kmem page in that same - buffer. When freeing, the kernel reads the first page, and compares the size - registered with the one given in <code class="Fn">kmem_free</code>(). Any - mismatch triggers a panic.</p> -<p class="Pp"><code class="Dv">KMEM_SIZE</code> is enabled by default on - <code class="Dv">DIAGNOSTIC</code>.</p> -</section> -</section> -<section class="Sh"> -<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN - VALUES</a></h1> -<p class="Pp">On success, <code class="Fn">kmem_alloc</code>(), - <code class="Fn">kmem_asprintf</code>(), - <code class="Fn">kmem_intr_alloc</code>(), - <code class="Fn">kmem_intr_zalloc</code>(), - <code class="Fn">kmem_strdupsize</code>(), and - <code class="Fn">kmem_zalloc</code>() return a pointer to allocated memory. - Otherwise, <code class="Dv">NULL</code> is returned.</p> -</section> -<section class="Sh"> -<h1 class="Sh" id="CODE_REFERENCES"><a class="permalink" href="#CODE_REFERENCES">CODE - REFERENCES</a></h1> -<p class="Pp">The <code class="Nm">kmem</code> subsystem is implemented within - the file <span class="Pa">sys/kern/subr_kmem.c</span>.</p> -</section> -<section class="Sh"> -<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE - ALSO</a></h1> -<p class="Pp"><a class="Xr">intro(9)</a>, <a class="Xr">memoryallocators(9)</a>, - <a class="Xr">percpu(9)</a>, <a class="Xr">pool_cache(9)</a>, - <a class="Xr">uvm_km(9)</a></p> -</section> -<section class="Sh"> -<h1 class="Sh" id="CAVEATS"><a class="permalink" href="#CAVEATS">CAVEATS</a></h1> -<p class="Pp">The <code class="Fn">kmem_alloc</code>(), - <code class="Fn">kmem_asprintf</code>(), - <code class="Fn">kmem_free</code>(), - <code class="Fn">kmem_strdupsize</code>(), - <code class="Fn">kmem_strfree</code>(), and - <code class="Fn">kmem_zalloc</code>() functions cannot be used from - interrupt context, from a soft interrupt, or from a callout. Use - <a class="Xr">pool_cache(9)</a> in these situations.</p> -</section> -<section class="Sh"> -<h1 class="Sh" id="SECURITY_CONSIDERATIONS"><a class="permalink" href="#SECURITY_CONSIDERATIONS">SECURITY - CONSIDERATIONS</a></h1> -<p class="Pp">As the memory allocated by <code class="Fn">kmem_alloc</code>() is - uninitialized, it can contain security-sensitive data left by its previous - user. It is the caller's responsibility not to expose it to the world.</p> -</section> -</div> -<table class="foot"> - <tr> - <td class="foot-date">January 24, 2021</td> - <td class="foot-os">NetBSD 10.1</td> - </tr> -</table> |
