[foreign-jextract] RFR: MemorySegmentPool + Allocator [v9]

Radoslaw Smogura github.com+7535718+rsmogura at openjdk.java.net
Thu Apr 22 23:05:42 UTC 2021


On Thu, 22 Apr 2021 22:42:09 GMT, Radoslaw Smogura <github.com+7535718+rsmogura at openjdk.org> wrote:

>> (Preview)
>> 
>> The MemorySegmentPool is a pool maintaining memory segments, optionally can expose allocator which can be bound to other scope, and which will return allocated segments back to pool.
>> 
>> However the best results has been achieved by using getSegmentEntry & putSegmentEntry methods.
>> 
>> The pool is intended to be used by long running applications (i.e. like global shared pool), where fast allocation and de-allocation of segments is critical (was designed during implementation of I/O subsystem with Panama, as a pool for temporary buffers between system I/O methods and Java byte arrays from InputStreams).
>> 
>> The pool uses hand-made SpinLockQueue as the Deque from JDK offers too much functionality and overhead.
>
> Radoslaw Smogura has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Prevent double adding element to queue
>   
>   Dealt with slow write issue - had to create segment with aligned size, not
>   a bit shift.
>   
>   ForceInline allocatorForScope and allocate method - this is outcome
>   from performance tests, and probable scalarization of segment.
>   
>   Some changes to inlining / no inlining.

New set of benchmarks


Benchmark                                      (allocations)  Mode  Cnt         Score       Error  Units
AllocatorsForLongRun.arena                                 1  avgt   10      8578.213 ?   119.631  ns/op
AllocatorsForLongRun.arena                                16  avgt   10    190038.468 ?  1879.850  ns/op
AllocatorsForLongRun.arena                               200  avgt   10  12738712.433 ? 92041.354  ns/op
AllocatorsForLongRun.malloc_free                           1  avgt   10        43.774 ?     0.668  ns/op
AllocatorsForLongRun.malloc_free                          16  avgt   10      2639.027 ?   433.626  ns/op
AllocatorsForLongRun.malloc_free                         200  avgt   10     26356.097 ?   191.074  ns/op
AllocatorsForLongRun.pool_allocator                        1  avgt   10        30.470 ?     0.062  ns/op
AllocatorsForLongRun.pool_allocator                       16  avgt   10       323.179 ?     0.611  ns/op
AllocatorsForLongRun.pool_allocator                      200  avgt   10      3884.727 ?    10.954  ns/op
AllocatorsForLongRun.pool_allocator_exhausted              1  avgt   10        80.138 ?     1.547  ns/op
AllocatorsForLongRun.pool_allocator_exhausted             16  avgt   10      3453.099 ?   696.754  ns/op
AllocatorsForLongRun.pool_allocator_exhausted            200  avgt   10     31563.155 ?   153.992  ns/op
AllocatorsForLongRun.pool_direct                           1  avgt   10        18.316 ?     0.092  ns/op
AllocatorsForLongRun.pool_direct                          16  avgt   10       261.271 ?     3.951  ns/op
AllocatorsForLongRun.pool_direct                         200  avgt   10      3397.057 ?    35.783  ns/op

With write

Benchmark                                      (allocations)  Mode  Cnt         Score        Error  Units
AllocatorsForLongRun.arena                                 1  avgt   10     12101.342 ?   2231.185  ns/op
AllocatorsForLongRun.arena                                16  avgt   10    243313.864 ?   5256.439  ns/op
AllocatorsForLongRun.arena                               200  avgt   10  13135973.454 ?  37170.906  ns/op
AllocatorsForLongRun.malloc_free                           1  avgt   10      1571.583 ?     22.135  ns/op
AllocatorsForLongRun.malloc_free                          16  avgt   10     65492.794 ?  22068.908  ns/op
AllocatorsForLongRun.malloc_free                         200  avgt   10   6800966.660 ?  39904.879  ns/op
AllocatorsForLongRun.pool_allocator                        1  avgt   10      1420.386 ?      5.112  ns/op
AllocatorsForLongRun.pool_allocator                       16  avgt   10     29433.570 ?    160.868  ns/op
AllocatorsForLongRun.pool_allocator                      200  avgt   10    640035.597 ?  38522.118  ns/op
AllocatorsForLongRun.pool_allocator_exhausted              1  avgt   10      1526.161 ?     18.930  ns/op
AllocatorsForLongRun.pool_allocator_exhausted             16  avgt   10    397319.239 ?   6746.863  ns/op
AllocatorsForLongRun.pool_allocator_exhausted            200  avgt   10  10774953.962 ? 761368.809  ns/op
AllocatorsForLongRun.pool_direct                           1  avgt   10      2242.986 ?     15.156  ns/op
AllocatorsForLongRun.pool_direct                          16  avgt   10     46143.779 ?    442.033  ns/op
AllocatorsForLongRun.pool_direct                         200  avgt   10    831948.538 ?   6819.482  ns/op

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/509


More information about the panama-dev mailing list