- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit743112a
committed
Adjust memory allocation functions to allow sibling calls
Many modern compilers are able to optimize function calls to functionswhere the parameters of the called function match a leading subset ofthe calling function's parameters. If there are no instructions in thecalling function after the function is called, then the compiler is freeto avoid any stack frame setup and implement the function call as a"jmp" rather than a "call". This is called sibling call optimization.Here we adjust the memory allocation functions in mcxt.c to allow thisoptimization. This requires moving some responsibility into the memorycontext implementations themselves. It's now the responsibility of theMemoryContext to check for malloc failures. This is good as it bothallows the sibling call optimization, but also because most small andmedium allocations won't call malloc and just allocate memory to anexisting block. That can't fail, so checking for NULLs in that caseisn't required.Also, traditionally it's been the responsibility of palloc and the otherallocation functions in mcxt.c to check for invalid allocation sizerequests. Here we also move the responsibility of checking that into theMemoryContext. This isn't to allow the sibling call optimization, butmore because most of our allocators handle large allocations separatelyand we can just add the size check when doing large allocations. We nolonger check this for non-large allocations at all.To make checking the allocation request sizes and ERROR handling easier,add some helper functions to mcxt.c for the allocators to use.Author: Andres FreundReviewed-by: David RowleyDiscussion:https://postgr.es/m/20210719195950.gavgs6ujzmjfaiig@alap3.anarazel.de1 parent17a3f79 commit743112a
File tree
7 files changed
+196
-166
lines changed- src
- backend/utils/mmgr
- include
- nodes
- utils
7 files changed
+196
-166
lines changedLines changed: 7 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
57 | 57 |
| |
58 | 58 |
| |
59 | 59 |
| |
60 |
| - | |
| 60 | + | |
61 | 61 |
| |
62 | 62 |
| |
63 | 63 |
| |
| |||
97 | 97 |
| |
98 | 98 |
| |
99 | 99 |
| |
100 |
| - | |
| 100 | + | |
101 | 101 |
| |
102 | 102 |
| |
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
106 |
| - | |
107 |
| - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
108 | 111 |
| |
109 | 112 |
| |
110 | 113 |
| |
|
Lines changed: 14 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
700 | 700 |
| |
701 | 701 |
| |
702 | 702 |
| |
703 |
| - | |
| 703 | + | |
704 | 704 |
| |
705 | 705 |
| |
706 | 706 |
| |
| |||
717 | 717 |
| |
718 | 718 |
| |
719 | 719 |
| |
| 720 | + | |
| 721 | + | |
| 722 | + | |
720 | 723 |
| |
721 | 724 |
| |
722 | 725 |
| |
| |||
727 | 730 |
| |
728 | 731 |
| |
729 | 732 |
| |
730 |
| - | |
| 733 | + | |
731 | 734 |
| |
732 | 735 |
| |
733 | 736 |
| |
| |||
940 | 943 |
| |
941 | 944 |
| |
942 | 945 |
| |
943 |
| - | |
| 946 | + | |
944 | 947 |
| |
945 | 948 |
| |
946 | 949 |
| |
| |||
1106 | 1109 |
| |
1107 | 1110 |
| |
1108 | 1111 |
| |
1109 |
| - | |
| 1112 | + | |
1110 | 1113 |
| |
1111 | 1114 |
| |
1112 | 1115 |
| |
| |||
1139 | 1142 |
| |
1140 | 1143 |
| |
1141 | 1144 |
| |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1142 | 1148 |
| |
1143 | 1149 |
| |
1144 | 1150 |
| |
| |||
1165 | 1171 |
| |
1166 | 1172 |
| |
1167 | 1173 |
| |
1168 |
| - | |
| 1174 | + | |
1169 | 1175 |
| |
1170 | 1176 |
| |
1171 | 1177 |
| |
| |||
1325 | 1331 |
| |
1326 | 1332 |
| |
1327 | 1333 |
| |
1328 |
| - | |
1329 |
| - | |
| 1334 | + | |
| 1335 | + | |
1330 | 1336 |
| |
1331 | 1337 |
| |
1332 | 1338 |
| |
1333 | 1339 |
| |
1334 | 1340 |
| |
1335 | 1341 |
| |
1336 |
| - | |
| 1342 | + | |
1337 | 1343 |
| |
1338 | 1344 |
| |
1339 | 1345 |
| |
|
Lines changed: 10 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
344 | 344 |
| |
345 | 345 |
| |
346 | 346 |
| |
347 |
| - | |
| 347 | + | |
348 | 348 |
| |
349 | 349 |
| |
350 | 350 |
| |
| |||
367 | 367 |
| |
368 | 368 |
| |
369 | 369 |
| |
| 370 | + | |
| 371 | + | |
| 372 | + | |
370 | 373 |
| |
371 | 374 |
| |
372 |
| - | |
| 375 | + | |
373 | 376 |
| |
374 | 377 |
| |
375 | 378 |
| |
| |||
472 | 475 |
| |
473 | 476 |
| |
474 | 477 |
| |
475 |
| - | |
| 478 | + | |
476 | 479 |
| |
477 | 480 |
| |
478 | 481 |
| |
| |||
737 | 740 |
| |
738 | 741 |
| |
739 | 742 |
| |
740 |
| - | |
| 743 | + | |
741 | 744 |
| |
742 | 745 |
| |
743 | 746 |
| |
| |||
839 | 842 |
| |
840 | 843 |
| |
841 | 844 |
| |
842 |
| - | |
843 |
| - | |
| 845 | + | |
| 846 | + | |
844 | 847 |
| |
845 | 848 |
| |
846 | 849 |
| |
847 | 850 |
| |
848 | 851 |
| |
849 | 852 |
| |
850 |
| - | |
| 853 | + | |
851 | 854 |
| |
852 | 855 |
| |
853 | 856 |
| |
|
0 commit comments
Comments
(0)