Sun Jan 24 17:29:11 2021 UTC ()
Add kmem_tmpbuf_alloc(), 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
kmem_alloc().  Add a corresponding kmem_tmpbuf_free() function that frees
the memory using kmem_free() if it is not the tempory stack buffer location.


(thorpej)
diff -r1.2372 -r1.2373 src/distrib/sets/lists/comp/mi
diff -r1.454 -r1.455 src/share/man/man9/Makefile
diff -r1.26 -r1.27 src/share/man/man9/kmem.9
diff -r1.80 -r1.81 src/sys/kern/subr_kmem.c
diff -r1.11 -r1.12 src/sys/sys/kmem.h

cvs diff -r1.2372 -r1.2373 src/distrib/sets/lists/comp/mi (expand / switch to unified diff)

--- src/distrib/sets/lists/comp/mi 2021/01/21 15:53:15 1.2372
+++ src/distrib/sets/lists/comp/mi 2021/01/24 17:29:11 1.2373
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mi,v 1.2372 2021/01/21 15:53:15 thorpej Exp $ 1# $NetBSD: mi,v 1.2373 2021/01/24 17:29:11 thorpej Exp $
2# 2#
3# Note: don't delete entries from here - mark them as "obsolete" instead. 3# Note: don't delete entries from here - mark them as "obsolete" instead.
4./etc/mtree/set.comp comp-sys-root 4./etc/mtree/set.comp comp-sys-root
5./usr/bin/addr2line comp-debug-bin binutils 5./usr/bin/addr2line comp-debug-bin binutils
6./usr/bin/ar comp-util-bin binutils 6./usr/bin/ar comp-util-bin binutils
7./usr/bin/as comp-util-bin binutils 7./usr/bin/as comp-util-bin binutils
8./usr/bin/asa comp-fortran-bin 8./usr/bin/asa comp-fortran-bin
9./usr/bin/atf-compile comp-obsolete obsolete 9./usr/bin/atf-compile comp-obsolete obsolete
10./usr/bin/c++ comp-cxx-bin gcccmds 10./usr/bin/c++ comp-cxx-bin gcccmds
11./usr/bin/c++filt comp-cxx-bin binutils 11./usr/bin/c++filt comp-cxx-bin binutils
12./usr/bin/c11 comp-c-bin 12./usr/bin/c11 comp-c-bin
13./usr/bin/c89 comp-c-bin 13./usr/bin/c89 comp-c-bin
14./usr/bin/c99 comp-c-bin 14./usr/bin/c99 comp-c-bin
@@ -11640,26 +11640,28 @@ @@ -11640,26 +11640,28 @@
11640./usr/share/man/cat9/kfilter_unregister.0 comp-sys-catman .cat 11640./usr/share/man/cat9/kfilter_unregister.0 comp-sys-catman .cat
11641./usr/share/man/cat9/killproc.0 comp-sys-catman .cat 11641./usr/share/man/cat9/killproc.0 comp-sys-catman .cat
11642./usr/share/man/cat9/klua_lock.0 comp-sys-catman .cat 11642./usr/share/man/cat9/klua_lock.0 comp-sys-catman .cat
11643./usr/share/man/cat9/klua_mod_register.0 comp-sys-catman .cat 11643./usr/share/man/cat9/klua_mod_register.0 comp-sys-catman .cat
11644./usr/share/man/cat9/kmem.0 comp-sys-catman .cat 11644./usr/share/man/cat9/kmem.0 comp-sys-catman .cat
11645./usr/share/man/cat9/kmem_alloc.0 comp-sys-catman .cat 11645./usr/share/man/cat9/kmem_alloc.0 comp-sys-catman .cat
11646./usr/share/man/cat9/kmem_asprintf.0 comp-sys-catman .cat 11646./usr/share/man/cat9/kmem_asprintf.0 comp-sys-catman .cat
11647./usr/share/man/cat9/kmem_free.0 comp-sys-catman .cat 11647./usr/share/man/cat9/kmem_free.0 comp-sys-catman .cat
11648./usr/share/man/cat9/kmem_intr_alloc.0 comp-sys-catman .cat 11648./usr/share/man/cat9/kmem_intr_alloc.0 comp-sys-catman .cat
11649./usr/share/man/cat9/kmem_intr_free.0 comp-sys-catman .cat 11649./usr/share/man/cat9/kmem_intr_free.0 comp-sys-catman .cat
11650./usr/share/man/cat9/kmem_intr_zalloc.0 comp-sys-catman .cat 11650./usr/share/man/cat9/kmem_intr_zalloc.0 comp-sys-catman .cat
11651./usr/share/man/cat9/kmem_strdupsize.0 comp-sys-catman .cat 11651./usr/share/man/cat9/kmem_strdupsize.0 comp-sys-catman .cat
11652./usr/share/man/cat9/kmem_strfree.0 comp-sys-catman .cat 11652./usr/share/man/cat9/kmem_strfree.0 comp-sys-catman .cat
 11653./usr/share/man/cat9/kmem_tmpbuf_alloc.0 comp-sys-catman .cat
 11654./usr/share/man/cat9/kmem_tmpbuf_free.0 comp-sys-catman .cat
11653./usr/share/man/cat9/kmem_zalloc.0 comp-sys-catman .cat 11655./usr/share/man/cat9/kmem_zalloc.0 comp-sys-catman .cat
11654./usr/share/man/cat9/knote.0 comp-sys-catman .cat 11656./usr/share/man/cat9/knote.0 comp-sys-catman .cat
11655./usr/share/man/cat9/kpause.0 comp-sys-catman .cat 11657./usr/share/man/cat9/kpause.0 comp-sys-catman .cat
11656./usr/share/man/cat9/kpgsignal.0 comp-sys-catman .cat 11658./usr/share/man/cat9/kpgsignal.0 comp-sys-catman .cat
11657./usr/share/man/cat9/kpreempt.0 comp-sys-catman .cat 11659./usr/share/man/cat9/kpreempt.0 comp-sys-catman .cat
11658./usr/share/man/cat9/kpreempt_disable.0 comp-sys-catman .cat 11660./usr/share/man/cat9/kpreempt_disable.0 comp-sys-catman .cat
11659./usr/share/man/cat9/kpreempt_disabled.0 comp-sys-catman .cat 11661./usr/share/man/cat9/kpreempt_disabled.0 comp-sys-catman .cat
11660./usr/share/man/cat9/kpreempt_enable.0 comp-sys-catman .cat 11662./usr/share/man/cat9/kpreempt_enable.0 comp-sys-catman .cat
11661./usr/share/man/cat9/kprintf.0 comp-sys-catman .cat 11663./usr/share/man/cat9/kprintf.0 comp-sys-catman .cat
11662./usr/share/man/cat9/kpsignal.0 comp-sys-catman .cat 11664./usr/share/man/cat9/kpsignal.0 comp-sys-catman .cat
11663./usr/share/man/cat9/kthread.0 comp-sys-catman .cat 11665./usr/share/man/cat9/kthread.0 comp-sys-catman .cat
11664./usr/share/man/cat9/kthread_create.0 comp-sys-catman .cat 11666./usr/share/man/cat9/kthread_create.0 comp-sys-catman .cat
11665./usr/share/man/cat9/kthread_create1.0 comp-obsolete obsolete 11667./usr/share/man/cat9/kthread_create1.0 comp-obsolete obsolete
@@ -19805,26 +19807,28 @@ @@ -19805,26 +19807,28 @@
19805./usr/share/man/html9/kfilter_unregister.html comp-sys-htmlman html 19807./usr/share/man/html9/kfilter_unregister.html comp-sys-htmlman html
19806./usr/share/man/html9/killproc.html comp-sys-htmlman html 19808./usr/share/man/html9/killproc.html comp-sys-htmlman html
19807./usr/share/man/html9/klua_lock.html comp-sys-htmlman html 19809./usr/share/man/html9/klua_lock.html comp-sys-htmlman html
19808./usr/share/man/html9/klua_mod_register.html comp-sys-htmlman html 19810./usr/share/man/html9/klua_mod_register.html comp-sys-htmlman html
19809./usr/share/man/html9/kmem.html comp-sys-htmlman html 19811./usr/share/man/html9/kmem.html comp-sys-htmlman html
19810./usr/share/man/html9/kmem_alloc.html comp-sys-htmlman html 19812./usr/share/man/html9/kmem_alloc.html comp-sys-htmlman html
19811./usr/share/man/html9/kmem_asprintf.html comp-sys-htmlman html 19813./usr/share/man/html9/kmem_asprintf.html comp-sys-htmlman html
19812./usr/share/man/html9/kmem_free.html comp-sys-htmlman html 19814./usr/share/man/html9/kmem_free.html comp-sys-htmlman html
19813./usr/share/man/html9/kmem_intr_alloc.html comp-sys-htmlman html 19815./usr/share/man/html9/kmem_intr_alloc.html comp-sys-htmlman html
19814./usr/share/man/html9/kmem_intr_free.html comp-sys-htmlman html 19816./usr/share/man/html9/kmem_intr_free.html comp-sys-htmlman html
19815./usr/share/man/html9/kmem_intr_zalloc.html comp-sys-htmlman html 19817./usr/share/man/html9/kmem_intr_zalloc.html comp-sys-htmlman html
19816./usr/share/man/html9/kmem_strdupsize.html comp-sys-htmlman html 19818./usr/share/man/html9/kmem_strdupsize.html comp-sys-htmlman html
19817./usr/share/man/html9/kmem_strfree.html comp-sys-htmlman html 19819./usr/share/man/html9/kmem_strfree.html comp-sys-htmlman html
 19820./usr/share/man/html9/kmem_tmpbuf_alloc.html comp-sys-htmlman html
 19821./usr/share/man/html9/kmem_tmpbuf_free.html comp-sys-htmlman html
19818./usr/share/man/html9/kmem_zalloc.html comp-sys-htmlman html 19822./usr/share/man/html9/kmem_zalloc.html comp-sys-htmlman html
19819./usr/share/man/html9/knote.html comp-sys-htmlman html 19823./usr/share/man/html9/knote.html comp-sys-htmlman html
19820./usr/share/man/html9/kpause.html comp-sys-htmlman html 19824./usr/share/man/html9/kpause.html comp-sys-htmlman html
19821./usr/share/man/html9/kpgsignal.html comp-sys-htmlman html 19825./usr/share/man/html9/kpgsignal.html comp-sys-htmlman html
19822./usr/share/man/html9/kpreempt.html comp-sys-htmlman html 19826./usr/share/man/html9/kpreempt.html comp-sys-htmlman html
19823./usr/share/man/html9/kpreempt_disable.html comp-sys-htmlman html 19827./usr/share/man/html9/kpreempt_disable.html comp-sys-htmlman html
19824./usr/share/man/html9/kpreempt_disabled.html comp-sys-htmlman html 19828./usr/share/man/html9/kpreempt_disabled.html comp-sys-htmlman html
19825./usr/share/man/html9/kpreempt_enable.html comp-sys-htmlman html 19829./usr/share/man/html9/kpreempt_enable.html comp-sys-htmlman html
19826./usr/share/man/html9/kprintf.html comp-sys-htmlman html 19830./usr/share/man/html9/kprintf.html comp-sys-htmlman html
19827./usr/share/man/html9/kpsignal.html comp-sys-htmlman html 19831./usr/share/man/html9/kpsignal.html comp-sys-htmlman html
19828./usr/share/man/html9/kthread.html comp-sys-htmlman html 19832./usr/share/man/html9/kthread.html comp-sys-htmlman html
19829./usr/share/man/html9/kthread_create.html comp-sys-htmlman html 19833./usr/share/man/html9/kthread_create.html comp-sys-htmlman html
19830./usr/share/man/html9/kthread_destroy.html comp-obsolete obsolete 19834./usr/share/man/html9/kthread_destroy.html comp-obsolete obsolete
@@ -28122,26 +28126,28 @@ @@ -28122,26 +28126,28 @@
28122./usr/share/man/man9/kfilter_unregister.9 comp-sys-man .man 28126./usr/share/man/man9/kfilter_unregister.9 comp-sys-man .man
28123./usr/share/man/man9/killproc.9 comp-sys-man .man 28127./usr/share/man/man9/killproc.9 comp-sys-man .man
28124./usr/share/man/man9/klua_lock.9 comp-sys-man .man 28128./usr/share/man/man9/klua_lock.9 comp-sys-man .man
28125./usr/share/man/man9/klua_mod_register.9 comp-sys-man .man 28129./usr/share/man/man9/klua_mod_register.9 comp-sys-man .man
28126./usr/share/man/man9/kmem.9 comp-sys-man .man 28130./usr/share/man/man9/kmem.9 comp-sys-man .man
28127./usr/share/man/man9/kmem_alloc.9 comp-sys-man .man 28131./usr/share/man/man9/kmem_alloc.9 comp-sys-man .man
28128./usr/share/man/man9/kmem_asprintf.9 comp-sys-man .man 28132./usr/share/man/man9/kmem_asprintf.9 comp-sys-man .man
28129./usr/share/man/man9/kmem_free.9 comp-sys-man .man 28133./usr/share/man/man9/kmem_free.9 comp-sys-man .man
28130./usr/share/man/man9/kmem_intr_alloc.9 comp-sys-man .man 28134./usr/share/man/man9/kmem_intr_alloc.9 comp-sys-man .man
28131./usr/share/man/man9/kmem_intr_free.9 comp-sys-man .man 28135./usr/share/man/man9/kmem_intr_free.9 comp-sys-man .man
28132./usr/share/man/man9/kmem_intr_zalloc.9 comp-sys-man .man 28136./usr/share/man/man9/kmem_intr_zalloc.9 comp-sys-man .man
28133./usr/share/man/man9/kmem_strdupsize.9 comp-sys-man .man 28137./usr/share/man/man9/kmem_strdupsize.9 comp-sys-man .man
28134./usr/share/man/man9/kmem_strfree.9 comp-sys-man .man 28138./usr/share/man/man9/kmem_strfree.9 comp-sys-man .man
 28139./usr/share/man/man9/kmem_tmpbuf_alloc.9 comp-sys-man .man
 28140./usr/share/man/man9/kmem_tmpbuf_free.9 comp-sys-man .man
28135./usr/share/man/man9/kmem_zalloc.9 comp-sys-man .man 28141./usr/share/man/man9/kmem_zalloc.9 comp-sys-man .man
28136./usr/share/man/man9/knote.9 comp-sys-man .man 28142./usr/share/man/man9/knote.9 comp-sys-man .man
28137./usr/share/man/man9/kpause.9 comp-sys-man .man 28143./usr/share/man/man9/kpause.9 comp-sys-man .man
28138./usr/share/man/man9/kpgsignal.9 comp-sys-man .man 28144./usr/share/man/man9/kpgsignal.9 comp-sys-man .man
28139./usr/share/man/man9/kpreempt.9 comp-sys-man .man 28145./usr/share/man/man9/kpreempt.9 comp-sys-man .man
28140./usr/share/man/man9/kpreempt_disable.9 comp-sys-man .man 28146./usr/share/man/man9/kpreempt_disable.9 comp-sys-man .man
28141./usr/share/man/man9/kpreempt_disabled.9 comp-sys-man .man 28147./usr/share/man/man9/kpreempt_disabled.9 comp-sys-man .man
28142./usr/share/man/man9/kpreempt_enable.9 comp-sys-man .man 28148./usr/share/man/man9/kpreempt_enable.9 comp-sys-man .man
28143./usr/share/man/man9/kprintf.9 comp-sys-man .man 28149./usr/share/man/man9/kprintf.9 comp-sys-man .man
28144./usr/share/man/man9/kpsignal.9 comp-sys-man .man 28150./usr/share/man/man9/kpsignal.9 comp-sys-man .man
28145./usr/share/man/man9/kthread.9 comp-sys-man .man 28151./usr/share/man/man9/kthread.9 comp-sys-man .man
28146./usr/share/man/man9/kthread_create.9 comp-sys-man .man 28152./usr/share/man/man9/kthread_create.9 comp-sys-man .man
28147./usr/share/man/man9/kthread_create1.9 comp-obsolete obsolete 28153./usr/share/man/man9/kthread_create1.9 comp-obsolete obsolete

cvs diff -r1.454 -r1.455 src/share/man/man9/Makefile (expand / switch to unified diff)

--- src/share/man/man9/Makefile 2021/01/21 15:53:16 1.454
+++ src/share/man/man9/Makefile 2021/01/24 17:29:11 1.455
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: Makefile,v 1.454 2021/01/21 15:53:16 thorpej Exp $ 1# $NetBSD: Makefile,v 1.455 2021/01/24 17:29:11 thorpej Exp $
2 2
3# Makefile for section 9 (kernel function and variable) manual pages. 3# Makefile for section 9 (kernel function and variable) manual pages.
4 4
5MAN= accept_filter.9 accf_data.9 accf_http.9 \ 5MAN= accept_filter.9 accf_data.9 accf_http.9 \
6 altq.9 arp.9 audio.9 autoconf.9 \ 6 altq.9 arp.9 audio.9 autoconf.9 \
7 bcdtobin.9 bcmp.9 bcopy.9 bintime_add.9 bluetooth.9 boothowto.9 bpf.9 \ 7 bcdtobin.9 bcmp.9 bcopy.9 bintime_add.9 bluetooth.9 boothowto.9 bpf.9 \
8 buffercache.9 bufferio.9 bufq.9 bus_dma.9 bus_space.9 byteorder.9 \ 8 buffercache.9 bufferio.9 bufq.9 bus_dma.9 bus_space.9 byteorder.9 \
9 bzero.9 \ 9 bzero.9 \
10 callback.9 callout.9 cardbus.9 clock.9 cnmagic.9 condvar.9 config.9 \ 10 callback.9 callout.9 cardbus.9 clock.9 cnmagic.9 condvar.9 config.9 \
11 cons.9 copy.9 coredump_write.9 \ 11 cons.9 copy.9 coredump_write.9 \
12 cpu_configure.9 cpu_coredump.9 cpu_dumpconf.9 \ 12 cpu_configure.9 cpu_coredump.9 cpu_dumpconf.9 \
13 cpu_lwp_fork.9 \ 13 cpu_lwp_fork.9 \
14 cpu_idle.9 cpu_initclocks.9 cpu_need_resched.9 \ 14 cpu_idle.9 cpu_initclocks.9 cpu_need_resched.9 \
@@ -446,27 +446,29 @@ MLINKS+=kcpuset.9 kcpuset_create.9 \ @@ -446,27 +446,29 @@ MLINKS+=kcpuset.9 kcpuset_create.9 \
446 kcpuset.9 kcpuset_match.9 \ 446 kcpuset.9 kcpuset_match.9 \
447 kcpuset.9 kcpuset_merge.9 \ 447 kcpuset.9 kcpuset_merge.9 \
448 kcpuset.9 kcpuset_export_32.9 \ 448 kcpuset.9 kcpuset_export_32.9 \
449 kcpuset.9 kcpuset_atomic_set.9 \ 449 kcpuset.9 kcpuset_atomic_set.9 \
450 kcpuset.9 kcpuset_atomic_clear.9 450 kcpuset.9 kcpuset_atomic_clear.9
451MLINKS+=kmem.9 kmem_alloc.9 \ 451MLINKS+=kmem.9 kmem_alloc.9 \
452 kmem.9 kmem_free.9 \ 452 kmem.9 kmem_free.9 \
453 kmem.9 kmem_zalloc.9 \ 453 kmem.9 kmem_zalloc.9 \
454 kmem.9 kmem_intr_alloc.9 \ 454 kmem.9 kmem_intr_alloc.9 \
455 kmem.9 kmem_intr_free.9 \ 455 kmem.9 kmem_intr_free.9 \
456 kmem.9 kmem_intr_zalloc.9 \ 456 kmem.9 kmem_intr_zalloc.9 \
457 kmem.9 kmem_asprintf.9 \ 457 kmem.9 kmem_asprintf.9 \
458 kmem.9 kmem_strdupsize.9 \ 458 kmem.9 kmem_strdupsize.9 \
459 kmem.9 kmem_strfree.9 459 kmem.9 kmem_strfree.9 \
 460 kmem.9 kmem_tmpbuf_alloc.9 \
 461 kmem.9 kmem_tmpbuf_free.9
460MAN+= kpreempt.9 462MAN+= kpreempt.9
461MLINKS+=kpreempt.9 kpreempt_disable.9 \ 463MLINKS+=kpreempt.9 kpreempt_disable.9 \
462 kpreempt.9 kpreempt_disabled.9 \ 464 kpreempt.9 kpreempt_disabled.9 \
463 kpreempt.9 kpreempt_enable.9 465 kpreempt.9 kpreempt_enable.9
464MLINKS+=proc_find.9 pgrp_find.9 466MLINKS+=proc_find.9 pgrp_find.9
465MLINKS+=kprintf.9 printf.9 kprintf.9 printf_nolog.9 \ 467MLINKS+=kprintf.9 printf.9 kprintf.9 printf_nolog.9 \
466 kprintf.9 snprintf.9 kprintf.9 vprintf.9 \ 468 kprintf.9 snprintf.9 kprintf.9 vprintf.9 \
467 kprintf.9 vsnprintf.9 kprintf.9 uprintf.9 kprintf.9 ttyprintf.9 \ 469 kprintf.9 vsnprintf.9 kprintf.9 uprintf.9 kprintf.9 ttyprintf.9 \
468 kprintf.9 tprintf.9 kprintf.9 tprintf_open.9 kprintf.9 tprintf_close.9 \ 470 kprintf.9 tprintf.9 kprintf.9 tprintf_open.9 kprintf.9 tprintf_close.9 \
469 kprintf.9 aprint_normal.9 kprintf.9 aprint_naive.9 \ 471 kprintf.9 aprint_normal.9 kprintf.9 aprint_naive.9 \
470 kprintf.9 aprint_verbose.9 kprintf.9 aprint_debug.9 \ 472 kprintf.9 aprint_verbose.9 kprintf.9 aprint_debug.9 \
471 kprintf.9 aprint_error.9 \ 473 kprintf.9 aprint_error.9 \
472 kprintf.9 aprint_normal_dev.9 kprintf.9 aprint_naive_dev.9 \ 474 kprintf.9 aprint_normal_dev.9 kprintf.9 aprint_naive_dev.9 \

cvs diff -r1.26 -r1.27 src/share/man/man9/kmem.9 (expand / switch to unified diff)

--- src/share/man/man9/kmem.9 2020/06/19 07:25:20 1.26
+++ src/share/man/man9/kmem.9 2021/01/24 17:29:11 1.27
@@ -1,41 +1,41 @@ @@ -1,41 +1,41 @@
1.\" $NetBSD: kmem.9,v 1.26 2020/06/19 07:25:20 wiz Exp $ 1.\" $NetBSD: kmem.9,v 1.27 2021/01/24 17:29:11 thorpej Exp $
2.\" 2.\"
3.\" Copyright (c)2006 YAMAMOTO Takashi, 3.\" Copyright (c)2006 YAMAMOTO Takashi,
4.\" All rights reserved. 4.\" All rights reserved.
5.\" 5.\"
6.\" Redistribution and use in source and binary forms, with or without 6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions 7.\" modification, are permitted provided that the following conditions
8.\" are met: 8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright 9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer. 10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the 12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution. 13.\" documentation and/or other materials provided with the distribution.
14.\" 14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE. 25.\" SUCH DAMAGE.
26.\" 26.\"
27.\" ------------------------------------------------------------ 27.\" ------------------------------------------------------------
28.Dd June 19, 2020 28.Dd January 24, 2021
29.Dt KMEM 9 29.Dt KMEM 9
30.Os 30.Os
31.\" ------------------------------------------------------------ 31.\" ------------------------------------------------------------
32.Sh NAME 32.Sh NAME
33.Nm kmem 33.Nm kmem
34.Nd kernel wired memory allocator 34.Nd kernel wired memory allocator
35.\" ------------------------------------------------------------ 35.\" ------------------------------------------------------------
36.Sh SYNOPSIS 36.Sh SYNOPSIS
37.In sys/kmem.h 37.In sys/kmem.h
38.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38.\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39.Ft void * 39.Ft void *
40.Fn kmem_alloc \ 40.Fn kmem_alloc \
41"size_t size" "km_flag_t kmflags" 41"size_t size" "km_flag_t kmflags"
@@ -63,26 +63,33 @@ @@ -63,26 +63,33 @@
63.Ft char * 63.Ft char *
64.Fn kmem_strdupsize \ 64.Fn kmem_strdupsize \
65"const char *str" "size_t *size" "km_flag_t kmflags" 65"const char *str" "size_t *size" "km_flag_t kmflags"
66.Ft char * 66.Ft char *
67.Fn kmem_strdup \ 67.Fn kmem_strdup \
68"const char *str" "km_flag_t kmflags" 68"const char *str" "km_flag_t kmflags"
69.Ft char * 69.Ft char *
70.Fn kmem_strndup \ 70.Fn kmem_strndup \
71"const char *str" "size_t manxlen" "km_flag_t kmflags" 71"const char *str" "size_t manxlen" "km_flag_t kmflags"
72.Ft void 72.Ft void
73.Fn kmem_strfree \ 73.Fn kmem_strfree \
74"char *str" 74"char *str"
75.\" ------------------------------------------------------------ 75.\" ------------------------------------------------------------
 76.Ft void *
 77.Fn kmem_tmpbuf_alloc \
 78"size_t size" "void *stackbuf" "size_t stackbufsize" "km_flag_t kmflags"
 79.Ft void
 80.Fn kmem_tmpbuf_free \
 81"void *p" "size_t size" "void *stsackbuf"
 82.\" ------------------------------------------------------------
76.Pp 83.Pp
77.Cd "options KMEM_SIZE" 84.Cd "options KMEM_SIZE"
78.Sh DESCRIPTION 85.Sh DESCRIPTION
79.Fn kmem_alloc 86.Fn kmem_alloc
80allocates kernel wired memory. 87allocates kernel wired memory.
81It takes the following arguments. 88It takes the following arguments.
82.Bl -tag -width kmflags 89.Bl -tag -width kmflags
83.It Fa size 90.It Fa size
84Specify the size of allocation in bytes. 91Specify the size of allocation in bytes.
85.It Fa kmflags 92.It Fa kmflags
86Either of the following: 93Either of the following:
87.Bl -tag -width KM_NOSLEEP 94.Bl -tag -width KM_NOSLEEP
88.It Dv KM_SLEEP 95.It Dv KM_SLEEP
@@ -205,26 +212,43 @@ characters from the string @@ -205,26 +212,43 @@ characters from the string
205.Fa str 212.Fa str
206always NUL terminating the copied string. 213always NUL terminating the copied string.
207.Pp 214.Pp
208The 215The
209.Fn kmem_strfree 216.Fn kmem_strfree
210function can be used to free a 217function can be used to free a
211.Dv NUL 218.Dv NUL
212terminated string computing the length of the string using 219terminated string computing the length of the string using
213.Xr strlen 3 220.Xr strlen 3
214and adding one for the 221and adding one for the
215.Dv NUL 222.Dv NUL
216and then using 223and then using
217.Fn kmem_free . 224.Fn kmem_free .
 225.Pp
 226The
 227.Fn kmem_tmpbuf_alloc
 228function is a utility function for allocating memory for temporary
 229use, where allocation on the stack is desirable, but only up to a
 230certain size.
 231If the requested size fits within the specified stack buffer, the
 232stack buffer is returned.
 233Otherwise, memory is allocated with
 234.Fn kmem_alloc .
 235The
 236.Fn kmem_tmpbuf_free
 237function compares the result of a previous call to
 238.Fn kmem_tmpbuf_alloc
 239and frees the memory using
 240.Fn kmem_free
 241if it is not the specified stack buffer.
218.\" ------------------------------------------------------------ 242.\" ------------------------------------------------------------
219.Sh NOTES 243.Sh NOTES
220Making 244Making
221.Dv KM_SLEEP 245.Dv KM_SLEEP
222allocations while holding mutexes or reader/writer locks is discouraged, as the 246allocations while holding mutexes or reader/writer locks is discouraged, as the
223caller can sleep for an unbounded amount of time in order to satisfy the 247caller can sleep for an unbounded amount of time in order to satisfy the
224allocation. 248allocation.
225This can in turn block other threads that wish to acquire locks held by the 249This can in turn block other threads that wish to acquire locks held by the
226caller. 250caller.
227It should be noted that 251It should be noted that
228.Fn kmem_free 252.Fn kmem_free
229may also block. 253may also block.
230.Pp 254.Pp

cvs diff -r1.80 -r1.81 src/sys/kern/subr_kmem.c (expand / switch to unified diff)

--- src/sys/kern/subr_kmem.c 2020/05/14 17:01:34 1.80
+++ src/sys/kern/subr_kmem.c 2021/01/24 17:29:11 1.81
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_kmem.c,v 1.80 2020/05/14 17:01:34 maxv Exp $ */ 1/* $NetBSD: subr_kmem.c,v 1.81 2021/01/24 17:29:11 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009-2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009-2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran and Maxime Villard. 8 * by Andrew Doran and Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -68,27 +68,27 @@ @@ -68,27 +68,27 @@
68 * 68 *
69 * This option is enabled on DIAGNOSTIC. 69 * This option is enabled on DIAGNOSTIC.
70 * 70 *
71 * |CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK| | 71 * |CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK|CHUNK| |
72 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-+ 72 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-+
73 * | | | | | | | | |/////|U| 73 * | | | | | | | | |/////|U|
74 * | | | | | | | | |/HSZ/|U| 74 * | | | | | | | | |/HSZ/|U|
75 * | | | | | | | | |/////|U| 75 * | | | | | | | | |/////|U|
76 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-+ 76 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+-+
77 * | Buffer usable by the caller (requested size) |Size |Unused 77 * | Buffer usable by the caller (requested size) |Size |Unused
78 */ 78 */
79 79
80#include <sys/cdefs.h> 80#include <sys/cdefs.h>
81__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.80 2020/05/14 17:01:34 maxv Exp $"); 81__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.81 2021/01/24 17:29:11 thorpej Exp $");
82 82
83#ifdef _KERNEL_OPT 83#ifdef _KERNEL_OPT
84#include "opt_kmem.h" 84#include "opt_kmem.h"
85#endif 85#endif
86 86
87#include <sys/param.h> 87#include <sys/param.h>
88#include <sys/callback.h> 88#include <sys/callback.h>
89#include <sys/kmem.h> 89#include <sys/kmem.h>
90#include <sys/pool.h> 90#include <sys/pool.h>
91#include <sys/debug.h> 91#include <sys/debug.h>
92#include <sys/lockdebug.h> 92#include <sys/lockdebug.h>
93#include <sys/cpu.h> 93#include <sys/cpu.h>
94#include <sys/asan.h> 94#include <sys/asan.h>
@@ -466,26 +466,49 @@ kmem_strndup(const char *str, size_t max @@ -466,26 +466,49 @@ kmem_strndup(const char *str, size_t max
466 466
467 return ptr; 467 return ptr;
468} 468}
469 469
470void 470void
471kmem_strfree(char *str) 471kmem_strfree(char *str)
472{ 472{
473 if (str == NULL) 473 if (str == NULL)
474 return; 474 return;
475 475
476 kmem_free(str, strlen(str) + 1); 476 kmem_free(str, strlen(str) + 1);
477} 477}
478 478
 479/*
 480 * Utility routine to maybe-allocate a temporary buffer if the size
 481 * is larger than we're willing to put on the stack.
 482 */
 483void *
 484kmem_tmpbuf_alloc(size_t size, void *stackbuf, size_t stackbufsize,
 485 km_flag_t flags)
 486{
 487 if (size <= stackbufsize) {
 488 return stackbuf;
 489 }
 490
 491 return kmem_alloc(size, flags);
 492}
 493
 494void
 495kmem_tmpbuf_free(void *buf, size_t size, void *stackbuf)
 496{
 497 if (buf != stackbuf) {
 498 kmem_free(buf, size);
 499 }
 500}
 501
479/* --------------------------- DEBUG / DIAGNOSTIC --------------------------- */ 502/* --------------------------- DEBUG / DIAGNOSTIC --------------------------- */
480 503
481#if defined(KMEM_SIZE) 504#if defined(KMEM_SIZE)
482static void 505static void
483kmem_size_set(void *p, size_t sz) 506kmem_size_set(void *p, size_t sz)
484{ 507{
485 memcpy((size_t *)((uintptr_t)p + sz), &sz, sizeof(size_t)); 508 memcpy((size_t *)((uintptr_t)p + sz), &sz, sizeof(size_t));
486} 509}
487 510
488static void 511static void
489kmem_size_check(void *p, size_t sz) 512kmem_size_check(void *p, size_t sz)
490{ 513{
491 size_t hsz; 514 size_t hsz;

cvs diff -r1.11 -r1.12 src/sys/sys/kmem.h (expand / switch to unified diff)

--- src/sys/sys/kmem.h 2018/01/09 01:53:55 1.11
+++ src/sys/sys/kmem.h 2021/01/24 17:29:11 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kmem.h,v 1.11 2018/01/09 01:53:55 christos Exp $ */ 1/* $NetBSD: kmem.h,v 1.12 2021/01/24 17:29:11 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2006 YAMAMOTO Takashi, 4 * Copyright (c)2006 YAMAMOTO Takashi,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -41,20 +41,23 @@ void * kmem_zalloc(size_t, km_flag_t); @@ -41,20 +41,23 @@ void * kmem_zalloc(size_t, km_flag_t);
41void kmem_free(void *, size_t); 41void kmem_free(void *, size_t);
42 42
43void * kmem_intr_alloc(size_t, km_flag_t); 43void * kmem_intr_alloc(size_t, km_flag_t);
44void * kmem_intr_zalloc(size_t, km_flag_t); 44void * kmem_intr_zalloc(size_t, km_flag_t);
45void kmem_intr_free(void *, size_t); 45void kmem_intr_free(void *, size_t);
46 46
47char * kmem_asprintf(const char *, ...) __printflike(1, 2); 47char * kmem_asprintf(const char *, ...) __printflike(1, 2);
48 48
49char * kmem_strdupsize(const char *, size_t *, km_flag_t); 49char * kmem_strdupsize(const char *, size_t *, km_flag_t);
50#define kmem_strdup(s, f) kmem_strdupsize((s), NULL, (f)) 50#define kmem_strdup(s, f) kmem_strdupsize((s), NULL, (f))
51char * kmem_strndup(const char *, size_t, km_flag_t); 51char * kmem_strndup(const char *, size_t, km_flag_t);
52void kmem_strfree(char *); 52void kmem_strfree(char *);
53 53
 54void * kmem_tmpbuf_alloc(size_t, void *, size_t, km_flag_t);
 55void kmem_tmpbuf_free(void *, size_t, void *);
 56
54/* 57/*
55 * km_flag_t values: 58 * km_flag_t values:
56 */ 59 */
57#define KM_SLEEP 0x00000001 /* can sleep */ 60#define KM_SLEEP 0x00000001 /* can sleep */
58#define KM_NOSLEEP 0x00000002 /* don't sleep */ 61#define KM_NOSLEEP 0x00000002 /* don't sleep */
59 62
60#endif /* !_SYS_KMEM_H_ */ 63#endif /* !_SYS_KMEM_H_ */