Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-7]: src Pull up following revision(s) (requested by mlelstv in ti...



details:   https://anonhg.NetBSD.org/src/rev/ce04c3aeece6
branches:  netbsd-7
changeset: 800365:ce04c3aeece6
user:      snj <snj%NetBSD.org@localhost>
date:      Sun Dec 03 10:25:02 2017 +0000

description:
Pull up following revision(s) (requested by mlelstv in ticket #1521):
        share/man/man9/kmem.9: revision 1.20 via patch
        share/man/man9/vmem.9: revision 1.16
        sys/kern/subr_kmem.c: revision 1.62
        sys/kern/subr_vmem.c: revision 1.94
fix vmem_alloc() to never return an error for VM_SLEEP requests,
thus fixing kmem_alloc() to never return NULL for KM_SLEEP requests.
instead these operations will retry forever, which was the intent.

diffstat:

 share/man/man9/kmem.9 |   7 +++-
 share/man/man9/vmem.9 |  65 ++++++++++++++++++++++++++++----------------------
 sys/kern/subr_kmem.c  |  16 +++++++++---
 sys/kern/subr_vmem.c  |  55 +++++++++++++++++++++++++++---------------
 4 files changed, 88 insertions(+), 55 deletions(-)

diffs (truncated from 414 to 300 lines):

diff -r 72fbc0d70c14 -r ce04c3aeece6 share/man/man9/kmem.9
--- a/share/man/man9/kmem.9     Sat Dec 02 10:54:01 2017 +0000
+++ b/share/man/man9/kmem.9     Sun Dec 03 10:25:02 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: kmem.9,v 1.14 2013/11/26 20:47:26 rmind Exp $
+.\"    $NetBSD: kmem.9,v 1.14.4.1 2017/12/03 10:25:02 snj Exp $
 .\"
 .\" Copyright (c)2006 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -25,7 +25,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" ------------------------------------------------------------
-.Dd November 26, 2013
+.Dd October 31, 2017
 .Dt KMEM 9
 .Os
 .\" ------------------------------------------------------------
@@ -75,6 +75,9 @@
 .It KM_SLEEP
 If the allocation cannot be satisfied immediately, sleep until enough
 memory is available.
+If
+.Dv KM_SLEEP
+is specified, then the allocation cannot fail.
 .It KM_NOSLEEP
 Don't sleep.
 Immediately return
diff -r 72fbc0d70c14 -r ce04c3aeece6 share/man/man9/vmem.9
--- a/share/man/man9/vmem.9     Sat Dec 02 10:54:01 2017 +0000
+++ b/share/man/man9/vmem.9     Sun Dec 03 10:25:02 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: vmem.9,v 1.15 2013/01/29 22:02:17 wiz Exp $
+.\"    $NetBSD: vmem.9,v 1.15.8.1 2017/12/03 10:25:02 snj Exp $
 .\"
 .\" Copyright (c)2006 YAMAMOTO Takashi,
 .\" All rights reserved.
@@ -25,7 +25,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\" ------------------------------------------------------------
-.Dd January 29, 2013
+.Dd February 28, 2016
 .Dt VMEM 9
 .Os
 .\" ------------------------------------------------------------
@@ -83,7 +83,7 @@
 .Fn vmem_create
 creates a new vmem arena.
 .Pp
-.Bl -tag -width qcache_max
+.Bl -tag -offset indent -width qcache_max
 .It Fa name
 The string to describe the vmem.
 .It Fa base
@@ -118,7 +118,7 @@
 to import a span of size at least
 .Fa size .
 .Fa allocfn
-should accept the same
+must accept the same
 .Fa flags
 as
 .Fn vmem_alloc .
@@ -169,7 +169,8 @@
 Either of:
 .Bl -tag -width VM_NOSLEEP
 .It Dv VM_SLEEP
-Can sleep until enough resources are available.
+If the allocation cannot be satisfied immediately, sleep until enough
+resources are available.
 .It Dv VM_NOSLEEP
 Don't sleep.
 Immediately return
@@ -184,7 +185,7 @@
 .Fn vmem_xcreate
 creates a new vmem arena.
 .Pp
-.Bl -tag -width qcache_max
+.Bl -tag -offset indent -width qcache_max
 .It Fa name
 The string to describe the vmem.
 .It Fa base
@@ -220,7 +221,7 @@
 to import a span of size at least
 .Fa size .
 .Fa allocfn
-should accept the same
+must accept the same
 .Fa flags
 as
 .Fn vmem_alloc .
@@ -274,7 +275,8 @@
 Either of:
 .Bl -tag -width VM_NOSLEEP
 .It Dv VM_SLEEP
-Can sleep until enough resources are available.
+If the allocation cannot be satisfied immediately, sleep until enough
+resources are available.
 .It Dv VM_NOSLEEP
 Don't sleep.
 Immediately return
@@ -297,23 +299,26 @@
 on success,
 .Dv ENOMEM
 on failure.
-.Fa flags
-should be one of:
+.Bl -tag -offset indent -width flags
+.It Fa flags
+Either of:
 .Bl -tag -width VM_NOSLEEP
 .It Dv VM_SLEEP
-Can sleep until enough resources are available.
+If the allocation cannot be satisfied immediately, sleep until enough
+resources are available.
 .It Dv VM_NOSLEEP
 Don't sleep.
 Immediately return
 .Dv ENOMEM
 if there are not enough resources available.
 .El
+.El
 .Pp
 .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 .Fn vmem_xalloc
 allocates a resource from the arena.
 .Pp
-.Bl -tag -width nocross
+.Bl -tag -offset indent -width nocross
 .It Fa vm
 The arena which we allocate from.
 .It Fa size
@@ -333,10 +338,10 @@
 .Fa align
 is zero,
 .Fa phase
-should be zero.
+must be zero.
 Otherwise,
 .Fa phase
-should be smaller than
+must be smaller than
 .Fa align .
 .It Fa nocross
 Request a resource which doesn't cross
@@ -353,7 +358,7 @@
 .It Fa flags
 A bitwise OR of an allocation strategy and a sleep flag.
 .Pp
-The allocation strategy is one of:
+The allocation strategy must be one of:
 .Bl -tag -width VM_INSTANTFIT
 .It Dv VM_BESTFIT
 Prefer space efficiency.
@@ -361,10 +366,11 @@
 Prefer performance.
 .El
 .Pp
-The sleep flag should be one of:
+The sleep flag must be one of:
 .Bl -tag -width VM_NOSLEEP
 .It Dv VM_SLEEP
-Can sleep until enough resources are available.
+If the allocation cannot be satisfied immediately, sleep until enough
+resources are available.
 .It Dv VM_NOSLEEP
 Don't sleep.
 Immediately return
@@ -386,14 +392,14 @@
 .Fn vmem_xalloc
 to the arena.
 .Pp
-.Bl -tag -width addr
+.Bl -tag -offset indent -width addr
 .It Fa vm
 The arena which we free to.
 .It Fa addr
 The resource being freed.
-It must be the one returned by
+It must have been allocated via
 .Fn vmem_xalloc .
-Notably, it must not be the one from
+Notably, it must not have been allocated via
 .Fn vmem_alloc .
 Otherwise, the behaviour is undefined.
 .It Fa size
@@ -408,7 +414,7 @@
 .Fn vmem_alloc
 allocates a resource from the arena.
 .Pp
-.Bl -tag -width flags
+.Bl -tag -offset indent -width flags
 .It Fa vm
 The arena which we allocate from.
 .It Fa size
@@ -416,7 +422,7 @@
 .It Fa flags
 A bitwise OR of an allocation strategy and a sleep flag.
 .Pp
-The allocation strategy is one of:
+The allocation strategy must be one of:
 .Bl -tag -width VM_INSTANTFIT
 .It Dv VM_BESTFIT
 Prefer space efficiency.
@@ -424,10 +430,11 @@
 Prefer performance.
 .El
 .Pp
-The sleep flag should be one of:
+The sleep flag must be one of:
 .Bl -tag -width VM_NOSLEEP
 .It Dv VM_SLEEP
-Can sleep until enough resources are available.
+If the allocation cannot be satisfied immediately, sleep until enough
+resources are available.
 .It Dv VM_NOSLEEP
 Don't sleep.
 Immediately return
@@ -449,14 +456,14 @@
 .Fn vmem_alloc
 to the arena.
 .Pp
-.Bl -tag -width addr
+.Bl -tag -offset indent -width addr
 .It Fa vm
 The arena which we free to.
 .It Fa addr
 The resource being freed.
-It must be the one returned by
+It must have been allocated via
 .Fn vmem_alloc .
-Notably, it must not be the one from
+Notably, it must not have been allocated via
 .Fn vmem_xalloc .
 Otherwise, the behaviour is undefined.
 .It Fa size
@@ -471,10 +478,10 @@
 .Fn vmem_destroy
 destroys a vmem arena.
 .Pp
-.Bl -tag -width vm
+.Bl -tag -offset indent -width vm
 .It Fa vm
 The vmem arena being destroyed.
-The caller should ensure that no one will use it anymore.
+The caller must ensure that no one will use it anymore.
 .El
 .\" ------------------------------------------------------------
 .Sh RETURN VALUES
diff -r 72fbc0d70c14 -r ce04c3aeece6 sys/kern/subr_kmem.c
--- a/sys/kern/subr_kmem.c      Sat Dec 02 10:54:01 2017 +0000
+++ b/sys/kern/subr_kmem.c      Sun Dec 03 10:25:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kmem.c,v 1.60 2014/07/22 07:38:41 maxv Exp $      */
+/*     $NetBSD: subr_kmem.c,v 1.60.2.1 2017/12/03 10:25:02 snj Exp $   */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.60 2014/07/22 07:38:41 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kmem.c,v 1.60.2.1 2017/12/03 10:25:02 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/callback.h>
@@ -373,9 +373,13 @@
 kmem_alloc(size_t size, km_flag_t kmflags)
 {
 
+       void *v;
+
        KASSERTMSG((!cpu_intr_p() && !cpu_softintr_p()),
            "kmem(9) should not be used from the interrupt context");
-       return kmem_intr_alloc(size, kmflags);
+       v = kmem_intr_alloc(size, kmflags);
+       KASSERT(v || (kmflags & KM_NOSLEEP) != 0);
+       return v;
 }
 
 /*
@@ -387,9 +391,13 @@
 kmem_zalloc(size_t size, km_flag_t kmflags)
 {
 
+       void *v;
+
        KASSERTMSG((!cpu_intr_p() && !cpu_softintr_p()),
            "kmem(9) should not be used from the interrupt context");
-       return kmem_intr_zalloc(size, kmflags);
+       v = kmem_intr_zalloc(size, kmflags);
+       KASSERT(v || (kmflags & KM_NOSLEEP) != 0);
+       return v;
 }
 
 /*
diff -r 72fbc0d70c14 -r ce04c3aeece6 sys/kern/subr_vmem.c
--- a/sys/kern/subr_vmem.c      Sat Dec 02 10:54:01 2017 +0000



Home | Main Index | Thread Index | Old Index