Repository navigation
Commit 522c01c
committed
mem: run the pkg-arena swap-in after free_route_lists(), not before
The previous commit (e0c63d2f45) gave each forked child its own
independent HG_MALLOC pkg reservation instead of COW-inheriting the
parent's, but placed the swap-in too early: internal_fork_child_setup()
(the default post-fork handler) runs free_route_lists() afterwards for
process types that do not need the parsed script, pkg_free()ing route
AST nodes that were allocated by the PARENT before fork. Those pointers
only make sense against the ORIGINAL (COW-inherited) arena.
With mem_block already swapped to the fresh arena by that point,
free_route_lists() ended up pkg_free()ing pointers from the old arena
through the new arena's bookkeeping - a cross-arena mismatch that
corrupts the new arena's free-list at best. In practice it surfaced as
a clean SIGBUS instead: cell_set_next() writes directly through the
freed pointer, which lands in the old, still-COW arena; if the hugetlb
pool is low by the time that page-fault happens (as it will be, once
enough earlier siblings have each taken their own 16-32MB reservation),
the kernel has nothing left to back the COW copy and the process dies
mid-startup. Reproduced live on .244 (49 of 53 processes got tier-1
MAP_HUGETLB, the pool ran dry for the last 4, and the process
immediately after - TCP main - crashed inside free_route_lists() via
this exact path: internal_fork -> internal_fork_child_setup ->
free_route_lists -> free_action_list -> free_expr -> hg_cell_free ->
cell_set_next SIGBUS).
Fix: move the pkg-arena swap-in to after the post-fork handler chain
runs, so free_route_lists() still operates against the still-correct
original arena and completes its cleanup there before it is abandoned.
Nothing between the old and new call sites (process-table bookkeeping,
seed_child) touches pkg memory, and the only other handler in that
chain (the profiler's post-fork hook) doesn't either - verified by
reading pt.c's _fork_handlers list directly rather than assuming.
Verified: standalone incremental rebuild (make opensips) compiles and
links clean with no warnings.1 parent ec9f829 commit 522c01c
1 file changed
Lines changed: 50 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
683 | 648 | | |
684 | 649 | | |
685 | 650 | | |
| |||
715 | 680 | | |
716 | 681 | | |
717 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
718 | 733 | | |
719 | 734 | | |
720 | 735 | | |
| |||
0 commit comments