]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add table of size classes in a comment
authorAustin Clements <austin@google.com>
Sun, 25 Dec 2016 01:03:10 +0000 (17:03 -0800)
committerAustin Clements <austin@google.com>
Sun, 8 Jan 2017 00:01:30 +0000 (00:01 +0000)
Change-Id: I52fae67c9aeceaa23e70f2ef0468745b354f8c75
Reviewed-on: https://go-review.googlesource.com/34932
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/mksizeclasses.go
src/runtime/sizeclasses.go

index 587d3c77a1040602ef0d439675f75d4cf36d5a48..0f897ba8e6998d1042ea8d6b4f61d180789de366 100644 (file)
@@ -54,6 +54,8 @@ func main() {
        fmt.Fprintln(&b, "package runtime")
        classes := makeClasses()
 
+       printComment(&b, classes)
+
        printClasses(&b, classes)
 
        out, err := format.Source(b.Bytes())
@@ -239,6 +241,20 @@ nextk:
        }
 }
 
+func printComment(w io.Writer, classes []class) {
+       fmt.Fprintf(w, "// %-5s  %-9s  %-10s  %-7s  %-11s\n", "class", "bytes/obj", "bytes/span", "objects", "waste bytes")
+       for i, c := range classes {
+               if i == 0 {
+                       continue
+               }
+               spanSize := c.npages * pageSize
+               objects := spanSize / c.size
+               waste := spanSize - c.size*(spanSize/c.size)
+               fmt.Fprintf(w, "// %5d  %9d  %10d  %7d  %11d\n", i, c.size, spanSize, objects, waste)
+       }
+       fmt.Fprintf(w, "\n")
+}
+
 func printClasses(w io.Writer, classes []class) {
        fmt.Fprintln(w, "const (")
        fmt.Fprintf(w, "_MaxSmallSize = %d\n", maxSmallSize)
index ec30d15d36bf7379b566b3028d9eb39b13c229da..e616e95148ca9c14ab703c4be210a64bba2d23b6 100644 (file)
@@ -3,6 +3,74 @@
 
 package runtime
 
+// class  bytes/obj  bytes/span  objects  waste bytes
+//     1          8        8192     1024            0
+//     2         16        8192      512            0
+//     3         32        8192      256            0
+//     4         48        8192      170           32
+//     5         64        8192      128            0
+//     6         80        8192      102           32
+//     7         96        8192       85           32
+//     8        112        8192       73           16
+//     9        128        8192       64            0
+//    10        144        8192       56          128
+//    11        160        8192       51           32
+//    12        176        8192       46           96
+//    13        192        8192       42          128
+//    14        208        8192       39           80
+//    15        224        8192       36          128
+//    16        240        8192       34           32
+//    17        256        8192       32            0
+//    18        288        8192       28          128
+//    19        320        8192       25          192
+//    20        352        8192       23           96
+//    21        384        8192       21          128
+//    22        416        8192       19          288
+//    23        448        8192       18          128
+//    24        480        8192       17           32
+//    25        512        8192       16            0
+//    26        576        8192       14          128
+//    27        640        8192       12          512
+//    28        704        8192       11          448
+//    29        768        8192       10          512
+//    30        896        8192        9          128
+//    31       1024        8192        8            0
+//    32       1152        8192        7          128
+//    33       1280        8192        6          512
+//    34       1408       16384       11          896
+//    35       1536        8192        5          512
+//    36       1792       16384        9          256
+//    37       2048        8192        4            0
+//    38       2304       16384        7          256
+//    39       2688        8192        3          128
+//    40       3072       24576        8            0
+//    41       3200       16384        5          384
+//    42       3456       24576        7          384
+//    43       4096        8192        2            0
+//    44       4864       24576        5          256
+//    45       5376       16384        3          256
+//    46       6144       24576        4            0
+//    47       6528       32768        5          128
+//    48       6784       40960        6          256
+//    49       6912       49152        7          768
+//    50       8192        8192        1            0
+//    51       9472       57344        6          512
+//    52       9728       49152        5          512
+//    53      10240       40960        4            0
+//    54      10880       32768        3          128
+//    55      12288       24576        2            0
+//    56      13568       40960        3          256
+//    57      14336       57344        4            0
+//    58      16384       16384        1            0
+//    59      18432       73728        4            0
+//    60      19072       57344        3          128
+//    61      20480       40960        2            0
+//    62      21760       65536        3          256
+//    63      24576       24576        1            0
+//    64      27264       81920        3          128
+//    65      28672       57344        2            0
+//    66      32768       32768        1            0
+
 const (
        _MaxSmallSize   = 32768
        smallSizeDiv    = 8