[OpenSIPS-Devel] [OpenSIPS/opensips] 380344: HP_MALLOC: Dramatically reduce memory fragmentation

Liviu Chircu noreply at github.com
Mon Apr 27 15:25:51 EST 2020


  Branch: refs/heads/2.4
  Home:   https://github.com/OpenSIPS/opensips
  Commit: 3803441bba9e8cd4b0348c7e3c0ff0cd39fc98ba
      https://github.com/OpenSIPS/opensips/commit/3803441bba9e8cd4b0348c7e3c0ff0cd39fc98ba
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-04-27 (Mon, 27 Apr 2020)

  Changed paths:
    M mem/common.h
    M mem/hp_malloc.c
    M mem/hp_malloc.h
    M mem/hp_malloc_stats.c
    M mem/hp_malloc_stats.h
    M statistics.c

  Log Message:
  -----------
  HP_MALLOC:  Dramatically reduce memory fragmentation

For HP_MALLOC to offer optimal parallel allocation performance, it
needs the memory to be fragmented: the more available chunks, the better
its performance.  However, there needs to be some coalescing as well,
otherwise variable-length allocations past the 10K range will
quickly deplete (fragment) even SHM pools of 10+ GB.

This patch adds the following heuristics to HP_MALLOC and HP_MALLOC_DBG:

    * shm_malloc(): only split a fragment if the resulting chunk is at
      least MIN_SPLIT_SIZE bytes (default 256 for PKG, 4096 for SHM)
    * shm_free(): try to coalesce the next fragment (enough to fix all
      fragmentation issues)


  Commit: 1531f56611e6979d3514f179dbb44ff9171cf0ae
      https://github.com/OpenSIPS/opensips/commit/1531f56611e6979d3514f179dbb44ff9171cf0ae
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-04-27 (Mon, 27 Apr 2020)

  Changed paths:
    M mem/hp_malloc.c
    M mem/hp_malloc_stats.c
    M mem/hp_malloc_stats.h

  Log Message:
  -----------
  HP_MALLOC: Fix computation of PKG stats


  Commit: 25eec9f5fa32909044b38b9d84f29661f0864499
      https://github.com/OpenSIPS/opensips/commit/25eec9f5fa32909044b38b9d84f29661f0864499
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-04-27 (Mon, 27 Apr 2020)

  Changed paths:
    M mem/hp_malloc.c

  Log Message:
  -----------
  HP_MALLOC: Add "re-scanning" logic

Given that HP_MALLOC has fine-grained locking, if the big fragment
shifts down from hash bucket N to bucket N-1 due to another
process performing the allocation, we may actually "lose" it during
our own scan, since bucket N-1 was empty and we're now waiting
for bucket N to unlock.  When it does unlock, it will also be empty.

As a solution: retry the scan up to N times, as long as it's feasible!


  Commit: 4b8ad9689c6b7b153590545053426da15418cbc0
      https://github.com/OpenSIPS/opensips/commit/4b8ad9689c6b7b153590545053426da15418cbc0
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-04-27 (Mon, 27 Apr 2020)

  Changed paths:
    M mem/hp_malloc.c

  Log Message:
  -----------
  HP_MALLOC: Aggregate SHM statistic updates

It is better to update the stats with a diff of the
attached/detached/split/merged fragment changes.  Updating the stats in
a "step by step" manner has the side-effect of creating temporarily
bogus values. (i.e. negative "used" and/or "real_used")


  Commit: 6e2f1d2e2d5d5aa0fe58fc5ba424b85d0512f829
      https://github.com/OpenSIPS/opensips/commit/6e2f1d2e2d5d5aa0fe58fc5ba424b85d0512f829
  Author: Liviu Chircu <liviu at opensips.org>
  Date:   2020-04-27 (Mon, 27 Apr 2020)

  Changed paths:
    M mem/hp_malloc.c
    A mem/test/test_hp_malloc.c
    A mem/test/test_hp_malloc.h
    M pt.c
    M test/unit_tests.c

  Log Message:
  -----------
  Core: Add an HP_MALLOC stress testing suite

Fixes #2089


Compare: https://github.com/OpenSIPS/opensips/compare/ee2912bad428...6e2f1d2e2d5d



More information about the Devel mailing list