Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/stdlib Switch from floating point to fixed point in...



details:   https://anonhg.NetBSD.org/src/rev/31b8bc11fb35
branches:  trunk
changeset: 762743:31b8bc11fb35
user:      njoly <njoly%NetBSD.org@localhost>
date:      Sat Feb 26 23:27:49 2011 +0000

description:
Switch from floating point to fixed point integer for run sizes maths.
>From FreeBSD (part of revision 1.154).

diffstat:

 lib/libc/stdlib/jemalloc.c |  39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diffs (84 lines):

diff -r 707d8532f783 -r 31b8bc11fb35 lib/libc/stdlib/jemalloc.c
--- a/lib/libc/stdlib/jemalloc.c        Sat Feb 26 23:24:09 2011 +0000
+++ b/lib/libc/stdlib/jemalloc.c        Sat Feb 26 23:27:49 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: jemalloc.c,v 1.21 2010/03/04 22:48:31 enami Exp $      */
+/*     $NetBSD: jemalloc.c,v 1.22 2011/02/26 23:27:49 njoly Exp $      */
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans <jasone%FreeBSD.org@localhost>.
@@ -118,7 +118,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.21 2010/03/04 22:48:31 enami Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.22 2011/02/26 23:27:49 njoly Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -319,20 +319,25 @@
 #define        SMALL_MAX_DEFAULT       (1 << SMALL_MAX_2POW_DEFAULT)
 
 /*
- * Maximum desired run header overhead.  Runs are sized as small as possible
- * such that this setting is still honored, without violating other constraints.
- * The goal is to make runs as small as possible without exceeding a per run
- * external fragmentation threshold.
+ * RUN_MAX_OVRHD indicates maximum desired run header overhead.  Runs are sized
+ * as small as possible such that this setting is still honored, without
+ * violating other constraints.  The goal is to make runs as small as possible
+ * without exceeding a per run external fragmentation threshold.
+ *
+ * We use binary fixed point math for overhead computations, where the binary
+ * point is implicitly RUN_BFP bits to the left.
  *
- * Note that it is possible to set this low enough that it cannot be honored
- * for some/all object sizes, since there is one bit of header overhead per
- * object (plus a constant).  In such cases, this constraint is relaxed.
+ * Note that it is possible to set RUN_MAX_OVRHD low enough that it cannot be
+ * honored for some/all object sizes, since there is one bit of header overhead
+ * per object (plus a constant).  This constraint is relaxed (ignored) for runs
+ * that are so small that the per-region overhead is greater than:
  *
- * RUN_MAX_OVRHD_RELAX specifies the maximum number of bits per region of
- * overhead for which RUN_MAX_OVRHD is relaxed.
+ *   (RUN_MAX_OVRHD / (reg_size << (3+RUN_BFP))
  */
-#define RUN_MAX_OVRHD          0.015
-#define RUN_MAX_OVRHD_RELAX    1.5
+#define RUN_BFP                        12
+/*                              \/   Implicit binary fixed point. */
+#define RUN_MAX_OVRHD          0x0000003dU
+#define RUN_MAX_OVRHD_RELAX    0x00001800U
 
 /* Put a cap on small object run size.  This overrides RUN_MAX_OVRHD. */
 #define RUN_MAX_SMALL_2POW     15
@@ -2143,7 +2148,6 @@
        size_t try_run_size, good_run_size;
        unsigned good_nregs, good_mask_nelms, good_reg0_offset;
        unsigned try_nregs, try_mask_nelms, try_reg0_offset;
-       float max_ovrhd = RUN_MAX_OVRHD;
 
        assert(min_run_size >= pagesize);
        assert(min_run_size <= arena_maxclass);
@@ -2161,7 +2165,7 @@
         */
        try_run_size = min_run_size;
        try_nregs = (unsigned)(((try_run_size - sizeof(arena_run_t)) /
-           bin->reg_size) + 1); /* Counter-act the first line of the loop. */
+           bin->reg_size) + 1); /* Counter-act try_nregs-- in loop. */
        do {
                try_nregs--;
                try_mask_nelms = (try_nregs >> (SIZEOF_INT_2POW + 3)) +
@@ -2195,9 +2199,8 @@
                } while (sizeof(arena_run_t) + (sizeof(unsigned) *
                    (try_mask_nelms - 1)) > try_reg0_offset);
        } while (try_run_size <= arena_maxclass && try_run_size <= RUN_MAX_SMALL
-           && max_ovrhd > RUN_MAX_OVRHD_RELAX / ((float)(bin->reg_size << 3))
-           && ((float)(try_reg0_offset)) / ((float)(try_run_size)) >
-           max_ovrhd);
+           && RUN_MAX_OVRHD * (bin->reg_size << 3) > RUN_MAX_OVRHD_RELAX
+           && (try_reg0_offset << RUN_BFP) > RUN_MAX_OVRHD * try_run_size);
 
        assert(sizeof(arena_run_t) + (sizeof(unsigned) * (good_mask_nelms - 1))
            <= good_reg0_offset);



Home | Main Index | Thread Index | Old Index