Page MenuHomeFreeBSD

Enable vm object coalescing when OBJ_ONEMAPPING is set
ClosedPublic

Authored by alc on Jul 29 2018, 7:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 12, 5:21 PM
Unknown Object (File)
Jan 30 2024, 9:35 AM
Unknown Object (File)
Jan 15 2024, 4:50 PM
Unknown Object (File)
Jan 6 2024, 2:03 PM
Unknown Object (File)
Dec 20 2023, 1:24 AM
Unknown Object (File)
Dec 10 2023, 1:11 AM
Unknown Object (File)
Nov 22 2023, 6:09 AM
Unknown Object (File)
Oct 19 2023, 7:15 AM
Subscribers

Details

Summary

Enable vm object coalescing when OBJ_ONEMAPPING is set, relying on the vm map layer not to create overlapping mappings to the vm object.

This change eliminates the fragmentation among the contiguous vm map entries at the end of P196.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Kostik, what is going on in the #if 0'ed code a little later in vm_object_coalesce()? That block of code is going to be heavily exercised with this change.

Here is an example of something other than clang. There is one object underlying the address range [0x800b2d000, 0x801148000), and no uncoalesced, virtually contiguous map entries in that range. I don't have an explanation for the lack of coalescing in the earlier entries.

86823           0x200000           0x228000 r--   24  192  21   7 CN-- vn /usr/bin/make
86823           0x228000           0x2cd000 r-x  149  192  21   7 CN-- vn /usr/bin/make
86823           0x2cd000           0x2d2000 rw-    5    0   1   0 C--- vn /usr/bin/make
86823           0x2d2000           0x4f0000 rw-   15   15   1   0 ---- df 
86823        0x8002cd000        0x8002ce000 r--    1    1  62   0 ---- dv 
86823        0x8002ce000        0x800332000 rw-   89   89   1   0 ---- df 
86823        0x800332000        0x800333000 rw-    1    1   1   0 ---- df 
86823        0x800333000        0x80033c000 rw-    9    9   1   0 ---- df 
86823        0x80033c000        0x800340000 rw-    4    4   1   0 ---- df 
86823        0x800340000        0x800353000 rw-   13   13   1   0 ---- df 
86823        0x800353000        0x80035a000 rw-    7    7   1   0 ---- df 
86823        0x80035a000        0x80036c000 rw-   17   17   1   0 ---- df 
86823        0x80036e000        0x800372000 rw-    4    4   1   0 ---- df 
86823        0x800372000        0x80038c000 rw-   24   24   1   0 ---- df 
86823        0x80038c000        0x8003d1000 rw-   64   64   1   0 ---- df 
86823        0x8003d1000        0x8003d5000 rw-    4    4   1   0 ---- df 
86823        0x8003d5000        0x800400000 rw-   43   43   1   0 ---- df 
86823        0x800400000        0x800ad8000 rw-  259  259   1   0 ---- df 
86823        0x800ad8000        0x800b2a000 rw-   82   82   1   0 ---- df 
86823        0x800b2d000        0x800c5e000 rw-  305 1104  49   0 ---- df 
86823        0x800c64000        0x800c65000 rw-    1 1104  49   0 ---- df 
86823        0x800c67000        0x800d84000 rw-  285 1104  49   0 ---- df 
86823        0x800d8a000        0x800da0000 rw-   21 1104  49   0 ---- df 
86823        0x800da1000        0x800dc8000 rw-   39 1104  49   0 ---- df 
86823        0x800dcb000        0x800de1000 rw-   22 1104  49   0 ---- df 
86823        0x800de6000        0x800def000 rw-    9 1104  49   0 ---- df 
86823        0x800df5000        0x800dfc000 rw-    7 1104  49   0 ---- df 
86823        0x800e02000        0x800e03000 rw-    1 1104  49   0 ---- df 
86823        0x800e09000        0x800e0a000 rw-    1 1104  49   0 ---- df 
86823        0x800e10000        0x800e17000 rw-    7 1104  49   0 ---- df 
86823        0x800e1d000        0x800e23000 rw-    6 1104  49   0 ---- df 
86823        0x800e24000        0x800e28000 rw-    4 1104  49   0 ---- df 
86823        0x800e2e000        0x800e46000 rw-   24 1104  49   0 ---- df 
86823        0x800e49000        0x800e52000 rw-    9 1104  49   0 ---- df 
86823        0x800e5a000        0x800e83000 rw-   41 1104  49   0 ---- df 
86823        0x800e89000        0x800e9b000 rw-   18 1104  49   0 ---- df 
86823        0x800e9d000        0x800ea3000 rw-    6 1104  49   0 ---- df 
86823        0x800ea7000        0x800ead000 rw-    6 1104  49   0 ---- df 
86823        0x800eb5000        0x800ec5000 rw-   16 1104  49   0 ---- df 
86823        0x800ece000        0x800ecf000 rw-    1 1104  49   0 ---- df 
86823        0x800ed5000        0x800ef6000 rw-   33 1104  49   0 ---- df 
86823        0x800ef7000        0x800efe000 rw-    7 1104  49   0 ---- df 
86823        0x800f01000        0x800f09000 rw-    8 1104  49   0 ---- df 
86823        0x800f10000        0x800f1a000 rw-   10 1104  49   0 ---- df 
86823        0x800f1c000        0x800f21000 rw-    5 1104  49   0 ---- df 
86823        0x800f27000        0x800f2b000 rw-    4 1104  49   0 ---- df 
86823        0x800f34000        0x800f3b000 rw-    7 1104  49   0 ---- df 
86823        0x800f44000        0x800f54000 rw-   13 1104  49   0 ---- df 
86823        0x800f5a000        0x800fb1000 rw-   49 1104  49   0 ---- df 
86823        0x800fb2000        0x800fb8000 rw-    6 1104  49   0 ---- df 
86823        0x800fbb000        0x800fc1000 rw-    6 1104  49   0 ---- df 
86823        0x800fca000        0x800fd3000 rw-    9 1104  49   0 ---- df 
86823        0x800fd4000        0x800fdd000 rw-    9 1104  49   0 ---- df 
86823        0x800ff8000        0x800ffe000 rw-    5 1104  49   0 ---- df 
86823        0x800fff000        0x801005000 rw-    6 1104  49   0 ---- df 
86823        0x801009000        0x80100f000 rw-    6 1104  49   0 ---- df 
86823        0x801020000        0x801029000 rw-    9 1104  49   0 ---- df 
86823        0x80102c000        0x801032000 rw-    6 1104  49   0 ---- df 
86823        0x801033000        0x801039000 rw-    6 1104  49   0 ---- df 
86823        0x801043000        0x80104c000 rw-    9 1104  49   0 ---- df 
86823        0x80107d000        0x801086000 rw-    9 1104  49   0 ---- df 
86823        0x801088000        0x801091000 rw-    9 1104  49   0 ---- df 
86823        0x801096000        0x80109c000 rw-    6 1104  49   0 ---- df 
86823        0x8010ae000        0x8010b9000 rw-   11 1104  49   0 ---- df 
86823        0x8010c3000        0x8010cc000 rw-    9 1104  49   0 ---- df 
86823        0x8010d5000        0x8010db000 rw-    6 1104  49   0 ---- df 
86823        0x8010e7000        0x8010ed000 rw-    6 1104  49   0 ---- df 
86823        0x801142000        0x801148000 rw-    6 1104  49   0 ---- df 
86823     0x7fffdffff000     0x7ffffffdf000 ---    0    0   0   0 ---- -- 
86823     0x7ffffffdf000     0x7ffffffff000 rw-    4    4   1   0 ---D df 
86823     0x7ffffffff000     0x800000000000 r-x    1    1  63   0 ---- ph

The #if 0 block tries to optimize the swap accounting by reducing the charged amount by the number of pages that definitely are not mapped. I suspect it was #if 0'd because it is really not easy to detect the correct amount to subtract. Which means that the block can be deleted.

This revision is now accepted and ready to land.Jul 29 2018, 8:35 PM

Here is an example based on clang. So far, all of the anonymous memory slivers between file mappings are showing a reference count on the vm object of one, so coalescing is happening there too.

46347           0x200000          0x1577000 r-- 2159 10360   6   2 CNS- vn /usr/bin/cpp
46347          0x1577000          0x3ff3000 r-x 8172 10360   6   2 CNS- vn /usr/bin/cpp
46347          0x3ff3000          0x4000000 rw-   13    0   1   0 C--- vn /usr/bin/cpp
46347          0x4000000          0x4282000 rw-  106  106   1   0 ---- df 
46347        0x803ff3000        0x803ff4000 r--    1    1  40   0 ---- dv 
46347        0x803ff4000        0x804000000 rw-   12   12   1   0 ---- df 
46347        0x804000000        0x804800000 rw- 1051 1051   1   0 ---- df 
46347        0x804800000        0x804f0d000 r-- 1805 1816   1   0 CNS- vn /local/HEAD/src/contrib/sqlite3/sqlite3.c
46347        0x804f0d000        0x804f15000 r--    8    8   1   0 CN-- vn /local/obj/local/HEAD/src/amd64.amd64/obj-lib32/tmp/usr/include/sys/cdefs.h
46347        0x804f15000        0x8051fc000 rw-  724  724   1   0 ---- df 
46347        0x8051fc000        0x805201000 r--    5    5   1   0 CN-- vn /local/obj/local/HEAD/src/amd64.amd64/obj-lib32/tmp/usr/include/stdio.h
46347        0x805201000        0x805552000 rw-  847  847   1   0 ---- df 
46347        0x805552000        0x805557000 r--    5    5   1   0 CN-- vn /local/obj/local/HEAD/src/amd64.amd64/obj-lib32/tmp/usr/include/unistd.h
46347        0x805557000        0x8097da000 rw- 16940 48825  46   0 --S- df 
46347        0x8097db000        0x80995c000 rw-  385 48825  46   0 ---- df 
46347        0x809978000        0x80a666000 rw- 3309 48825  46   0 --S- df 
46347        0x80a667000        0x80a6c5000 rw-   94 48825  46   0 ---- df 
46347        0x80a6c7000        0x80a6ff000 rw-   56 48825  46   0 ---- df 
46347        0x80a700000        0x80a717000 rw-   23 48825  46   0 ---- df 
46347        0x80a718000        0x80a72b000 rw-   19 48825  46   0 ---- df 
46347        0x80a740000        0x80aa67000 rw-  807 48825  46   0 --S- df 
46347        0x80aa68000        0x80aa8a000 rw-   34 48825  46   0 ---- df 
46347        0x80aa8b000        0x80aaac000 rw-   33 48825  46   0 ---- df 
46347        0x80aaad000        0x80aaaf000 rw-    2 48825  46   0 ---- df 
46347        0x80aab0000        0x80ab29000 rw-  121 48825  46   0 ---- df 
46347        0x80ab2a000        0x80ab44000 rw-   26 48825  46   0 ---- df 
46347        0x80ab45000        0x80ab6b000 rw-   38 48825  46   0 ---- df 
46347        0x80ab6d000        0x80ab74000 rw-    7 48825  46   0 ---- df 
46347        0x80ab8a000        0x80abb6000 rw-   44 48825  46   0 ---- df 
46347        0x80abb8000        0x80abbe000 rw-    6 48825  46   0 ---- df 
46347        0x80abbf000        0x80ac6f000 rw-  176 48825  46   0 ---- df 
46347        0x80ac71000        0x80ae30000 rw-  447 48825  46   0 ---- df 
46347        0x80ae32000        0x80ae44000 rw-   18 48825  46   0 ---- df 
46347        0x80ae46000        0x80c8eb000 rw- 6821 48825  46   0 --S- df 
46347        0x80c8ee000        0x80d497000 rw- 2984 48825  46   0 --S- df 
46347        0x80d498000        0x80d49e000 rw-    6 48825  46   0 ---- df 
46347        0x80d49f000        0x80d963000 rw- 1220 48825  46   0 --S- df 
46347        0x80d964000        0x80dd63000 rw- 1018 48825  46   0 --S- df 
46347        0x80dd64000        0x80dfac000 rw-  579 48825  46   0 ---- df 
46347        0x80dfad000        0x80dfdb000 rw-   46 48825  46   0 ---- df 
46347        0x80dfdc000        0x80e00d000 rw-   49 48825  46   0 ---- df 
46347        0x80e00f000        0x80e027000 rw-   24 48825  46   0 ---- df 
46347        0x80e028000        0x80e029000 rw-    1 48825  46   0 ---- df 
46347        0x80e02a000        0x80e02b000 rw-    1 48825  46   0 ---- df 
46347        0x80e02c000        0x80f024000 rw- 4087 48825  46   0 --S- df 
46347        0x80f026000        0x80f032000 rw-   12 48825  46   0 ---- df 
46347        0x80f034000        0x80f036000 rw-    2 48825  46   0 ---- df 
46347        0x80f037000        0x80f526000 rw- 1263 48825  46   0 --S- df 
46347        0x80f527000        0x80f528000 rw-    1 48825  46   0 ---- df 
46347        0x80f52d000        0x80f664000 rw-  310 48825  46   0 ---- df 
46347        0x80f666000        0x80f85c000 rw-  498 48825  46   0 ---- df 
46347        0x80f87d000        0x80fbbe000 rw-  829 48825  46   0 ---- df 
46347        0x80fbc1000        0x80fbc3000 rw-    2 48825  46   0 ---- df 
46347        0x80fbc5000        0x80fbcd000 rw-    8 48825  46   0 ---- df 
46347        0x80fbcf000        0x80fbe7000 rw-   24 48825  46   0 ---- df 
46347        0x80fbec000        0x80fc4e000 rw-   98 48825  46   0 ---- df 
46347        0x80fc4f000        0x80ffb8000 rw-  873 48825  46   0 ---- df 
46347        0x80ffba000        0x81090b000 rw- 2382 48825  46   0 --S- df 
46347        0x81090c000        0x8115a0000 rw- 3102 48825  46   0 ---- df 
46347     0x7fffdfffe000     0x7fffdffff000 ---    0    0   0   0 ---- -- 
46347     0x7fffdffff000     0x7ffffffdf000 ---    0    0   0   0 ---- -- 
46347     0x7ffffffdf000     0x7ffffffff000 rw-   27   27   1   0 ---D df 
46347     0x7ffffffff000     0x800000000000 r-x    1    1  41   0 ---- ph

Mark, I was just looking at P191 again, and I am interested to see how this patch affects the procstat -v output for firefox without any malloc.conf settings.

Peter, could you please test this patch?

In D16501#350241, @alc wrote:

Mark, I was just looking at P191 again, and I am interested to see how this patch affects the procstat -v output for firefox without any malloc.conf settings.

Sure, I'll kick off a build now.

Here's output after letting firefox run for a few minutes with about 10 tabs open: https://reviews.freebsd.org/P197

Here's output after letting firefox run for a few minutes with about 10 tabs open: https://reviews.freebsd.org/P197

... and here's one after firefox has been running for the better part of a day: https://reviews.freebsd.org/P199

Here's output after letting firefox run for a few minutes with about 10 tabs open: https://reviews.freebsd.org/P197

... and here's one after firefox has been running for the better part of a day: https://reviews.freebsd.org/P199

It seems to help with map entries that were created after the last fork, e.g., lines 15773 to 15967. But, once an entry is flagged _COW, coalescing stops.

For buildworld this change results in a slight reduction in vm map entry and object allocations and a slight increase in promotions.

3 back-to-back buildworlds, before the change:

18554.595u 1055.118s 57:21.38 569.8%    52915+3524k 52596+82964io 15367pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147159,     831, 3597056,   0,   0
MAP ENTRY:              120,      0,     817,    3935,10210917,   0,   0
vm.pmap.pde.promotions: 61901
vm.pmap.pde.p_failures: 8522
vm.pmap.pde.mappings: 186484
vm.pmap.pde.demotions: 4116
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 251824K,    163

vm.reserv.fullpop: 117
vm.reserv.freed: 1241278
vm.reserv.broken: 0
18537.790u 1063.647s 57:22.78 569.3%    52915+3524k 5319+84217io 0pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147162,     948, 7132650,   0,   0
MAP ENTRY:              120,      0,     817,    3935,20333265,   0,   0
vm.pmap.pde.promotions: 123596
vm.pmap.pde.p_failures: 16968
vm.pmap.pde.mappings: 373015
vm.pmap.pde.demotions: 8164
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 251636K,    163

vm.reserv.fullpop: 117
vm.reserv.freed: 2477736
vm.reserv.broken: 0
18537.343u 1060.111s 57:22.28 569.3%    52927+3525k 5011+85398io 0pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147162,    1863,10668645,   0,   0
MAP ENTRY:              120,      0,     817,    4958,30457013,   0,   0
vm.pmap.pde.promotions: 185249
vm.pmap.pde.p_failures: 25811
vm.pmap.pde.mappings: 559557
vm.pmap.pde.demotions: 12278
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 251612K,    163

vm.reserv.fullpop: 117
vm.reserv.freed: 3714182
vm.reserv.broken: 0

3 back-to-back buildworlds, after the change:

18558.546u 1061.929s 57:24.27 569.6%    52923+3525k 52427+83259io 15368pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147124,     746, 3437259,   0,   0
MAP ENTRY:              120,      0,     792,    3729,10157398,   0,   0
vm.pmap.pde.promotions: 63300
vm.pmap.pde.p_failures: 8789
vm.pmap.pde.mappings: 186504
vm.pmap.pde.demotions: 4850
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 271956K,    174

vm.reserv.fullpop: 118
vm.reserv.freed: 1242022
vm.reserv.broken: 0
18553.218u 1066.927s 56:58.45 573.9%    52930+3525k 5208+84047io 0pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147135,    1710, 6810454,   0,   0
MAP ENTRY:              120,      0,     792,    3861,20221295,   0,   0
vm.pmap.pde.promotions: 126438
vm.pmap.pde.p_failures: 17561
vm.pmap.pde.mappings: 373047
vm.pmap.pde.demotions: 9619
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 273852K,    175

vm.reserv.fullpop: 118
vm.reserv.freed: 2478131
vm.reserv.broken: 0
18544.411u 1066.360s 57:24.15 569.3%    52930+3525k 5036+84653io 0pf+0w
ITEM                   SIZE  LIMIT     USED     FREE      REQ FAIL SLEEP
VM OBJECT:              256,      0,  147135,    1950,10183838,   0,   0
MAP ENTRY:              120,      0,     792,    4983,30282861,   0,   0
vm.pmap.pde.promotions: 189575
vm.pmap.pde.p_failures: 26726
vm.pmap.pde.mappings: 559590
vm.pmap.pde.demotions: 14531
vm.reserv.reclaimed: 0
vm.reserv.partpopq: 
DOMAIN    LEVEL     SIZE  NUMBER

     0,      -1, 273852K,    175

vm.reserv.fullpop: 118
vm.reserv.freed: 3714250
vm.reserv.broken: 0
In D16501#350245, @alc wrote:

Peter, could you please test this patch?

I ran all of the stress2 tests on amd64 and also did a brief test on i386.
No problems seen.

This revision was automatically updated to reflect the committed changes.

It occurred to me that this issue (of non-coalescing) also happened to the JVM, so I tried the SPECjvm2008 compiler workload. Below is a comparison of the average number of map entries in use by the JVM prior to and after this change. Specifically, I sample the number of map entries in use every 7 seconds, and compute the average over 164 samples.

x /home/alc/pre.log
+ /home/alc/post.log
    N           Min           Max        Median           Avg        Stddev
x 164           196           576           491     495.67683     61.479303
+ 164           189           471           404     401.81098     37.751621
Difference at 95.0% confidence
        -93.8659 +/- 11.0418
        -18.9369% +/- 1.93047%
        (Student's t, pooled s = 51.0142)