forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit0e48038
committed
Make more effort to put a sentinel at the end of allocated memory
Traditionally, in MEMORY_CONTEXT_CHECKING builds, we only ever marked asentinel byte just beyond the requested size if there happened to beenough space on the chunk to do so. For Slab and Generation contexttypes, we only rounded the size of the chunk up to the next maxalignboundary, so it was often not that likely that those would ever have spacefor the sentinel given that the majority of allocation requests are goingto be for sizes which are maxaligned. For AllocSet, it was a littledifferent as smaller allocations are rounded up to the next power-of-2value rather than the next maxalign boundary, so we're a bit more likelyto have space for the sentinel byte, especially when we get away from tinysized allocations such as 8 or 16 bytes.Here we make more of an effort to allow space so that there is enough roomfor the sentinel byte in more cases. This makes it more likely that we'lldetect when buggy code accidentally writes beyond the end of any of itsmemory allocations.Each of the 3 MemoryContext types has been changed as follows:The Slab allocator will now always set a sentinel byte. Both the currentusages of this MemoryContext type happen to use chunk sizes which were onthe maxalign boundary, so these never used sentinel bytes previously.For the Generation allocator, we now always ensure there's enough space inthe allocation for a sentinel byte.For AllocSet, this commit makes an adjustment for allocation sizes whichare greater than allocChunkLimit. We now ensure there is always space fora sentinel byte. We don't alter the sentinel behavior for request sizes<= allocChunkLimit. Making way for the sentinel byte for power-of-2request sizes would require doubling up to the next power of 2. Someanalysis done on the request sizes made during installcheck shows that afairly large portion of allocation requests are for power-of-2 sizes. Theamount of additional memory for the sentinel there seems prohibitive, sowe do nothing for those here.Author: David RowleyDiscussion:https://postgr.es/m/3478405.1661824539@sss.pgh.pa.us1 parentf98d074 commit0e48038
3 files changed
+74
-47
lines changedLines changed: 29 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
705 | 705 |
| |
706 | 706 |
| |
707 | 707 |
| |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
708 | 712 |
| |
| 713 | + | |
| 714 | + | |
709 | 715 |
| |
710 | 716 |
| |
711 | 717 |
| |
| |||
724 | 730 |
| |
725 | 731 |
| |
726 | 732 |
| |
727 |
| - | |
728 |
| - | |
| 733 | + | |
| 734 | + | |
729 | 735 |
| |
730 | 736 |
| |
731 | 737 |
| |
| |||
766 | 772 |
| |
767 | 773 |
| |
768 | 774 |
| |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
769 | 781 |
| |
770 | 782 |
| |
771 | 783 |
| |
| |||
992 | 1004 |
| |
993 | 1005 |
| |
994 | 1006 |
| |
995 |
| - | |
996 |
| - | |
997 |
| - | |
998 |
| - | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
999 | 1011 |
| |
1000 | 1012 |
| |
1001 | 1013 |
| |
| |||
1098 | 1110 |
| |
1099 | 1111 |
| |
1100 | 1112 |
| |
1101 |
| - | |
1102 |
| - | |
1103 |
| - | |
1104 |
| - | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
1105 | 1117 |
| |
1106 | 1118 |
| |
1107 | 1119 |
| |
| |||
1111 | 1123 |
| |
1112 | 1124 |
| |
1113 | 1125 |
| |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1114 | 1130 |
| |
| 1131 | + | |
1115 | 1132 |
| |
1116 | 1133 |
| |
1117 | 1134 |
| |
| |||
1162 | 1179 |
| |
1163 | 1180 |
| |
1164 | 1181 |
| |
1165 |
| - | |
1166 |
| - | |
| 1182 | + | |
| 1183 | + | |
1167 | 1184 |
| |
1168 | 1185 |
| |
1169 | 1186 |
| |
|
Lines changed: 25 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
342 | 342 |
| |
343 | 343 |
| |
344 | 344 |
| |
345 |
| - | |
346 |
| - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
347 | 355 |
| |
348 | 356 |
| |
349 | 357 |
| |
| |||
373 | 381 |
| |
374 | 382 |
| |
375 | 383 |
| |
376 |
| - | |
377 |
| - | |
| 384 | + | |
| 385 | + | |
378 | 386 |
| |
379 | 387 |
| |
380 | 388 |
| |
| |||
491 | 499 |
| |
492 | 500 |
| |
493 | 501 |
| |
494 |
| - | |
495 |
| - | |
| 502 | + | |
| 503 | + | |
496 | 504 |
| |
497 | 505 |
| |
498 | 506 |
| |
| |||
634 | 642 |
| |
635 | 643 |
| |
636 | 644 |
| |
637 |
| - | |
638 |
| - | |
639 |
| - | |
640 |
| - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
641 | 649 |
| |
642 | 650 |
| |
643 | 651 |
| |
| |||
727 | 735 |
| |
728 | 736 |
| |
729 | 737 |
| |
730 |
| - | |
731 |
| - | |
732 |
| - | |
733 |
| - | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
734 | 742 |
| |
735 | 743 |
| |
736 | 744 |
| |
| |||
769 | 777 |
| |
770 | 778 |
| |
771 | 779 |
| |
772 |
| - | |
773 |
| - | |
| 780 | + | |
774 | 781 |
| |
775 | 782 |
| |
776 | 783 |
| |
| |||
1034 | 1041 |
| |
1035 | 1042 |
| |
1036 | 1043 |
| |
1037 |
| - | |
1038 |
| - | |
| 1044 | + | |
| 1045 | + | |
1039 | 1046 |
| |
1040 | 1047 |
| |
1041 | 1048 |
| |
|
Lines changed: 20 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
145 | 145 |
| |
146 | 146 |
| |
147 | 147 |
| |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
148 | 152 |
| |
| 153 | + | |
149 | 154 |
| |
150 | 155 |
| |
151 | 156 |
| |
| |||
420 | 425 |
| |
421 | 426 |
| |
422 | 427 |
| |
423 |
| - | |
424 |
| - | |
425 |
| - | |
426 |
| - | |
427 |
| - | |
428 |
| - | |
429 |
| - | |
430 |
| - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
431 | 434 |
| |
432 | 435 |
| |
433 | 436 |
| |
| |||
454 | 457 |
| |
455 | 458 |
| |
456 | 459 |
| |
457 |
| - | |
458 |
| - | |
459 |
| - | |
460 |
| - | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
461 | 464 |
| |
462 | 465 |
| |
463 | 466 |
| |
| |||
744 | 747 |
| |
745 | 748 |
| |
746 | 749 |
| |
747 |
| - | |
748 |
| - | |
749 |
| - | |
750 |
| - | |
751 |
| - | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
752 | 755 |
| |
753 | 756 |
| |
754 | 757 |
| |
|
0 commit comments
Comments
(0)