forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc4d5cb7
committed
Increase the number of fast-path lock slots
Replace the fixed-size array of fast-path locks with arrays, sized onstartup based on max_locks_per_transaction. This allows using fast-pathlocking for workloads that need more locks.The fast-path locking introduced in 9.2 allowed each backend to acquirea small number (16) of weak relation locks cheaply. If a backend needsto hold more locks, it has to insert them into the shared lock table.This is considerably more expensive, and may be subject to contention(especially on many-core systems).The limit of 16 fast-path locks was always rather low, because we haveto lock all relations - not just tables, but also indexes, views, etc.For planning we need to lock all relations that might be used in theplan, not just those that actually get used in the final plan. So evenwith rather simple queries and schemas, we often need significantly morethan 16 locks.As partitioning gets used more widely, and the number of partitionsincreases, this limit is trivial to hit. Complex queries may easily usehundreds or even thousands of locks. For workloads doing a lot of I/Othis is not noticeable, but for workloads accessing only data in RAM,the access to the shared lock table may be a serious issue.This commit removes the hard-coded limit of the number of fast-pathlocks. Instead, the size of the fast-path arrays is calculated atstartup, and can be set much higher than the original 16-lock limit.The overall fast-path locking protocol remains unchanged.The variable-sized fast-path arrays can no longer be part of PGPROC, butare allocated as a separate chunk of shared memory and then referencesfrom the PGPROC entries.The fast-path slots are organized as a 16-way set associative cache. Youcan imagine it as a hash table of 16-slot "groups". Each relation ismapped to exactly one group using hash(relid), and the group is thenprocessed using linear search, just like the original fast-path cache.With only 16 entries this is cheap, with good locality.Treating this as a simple hash table with open addressing would not beefficient, especially once the hash table gets almost full. The usualremedy is to grow the table, but we can't do that here easily. Theaccess would also be more random, with worse locality.The fast-path arrays are sized using the max_locks_per_transaction GUC.We try to have enough capacity for the number of locks specified in theGUC, using the traditional 2^n formula, with an upper limit of 1024 lockgroups (i.e. 16k locks). The default value of max_locks_per_transactionis 64, which means those instances will have 64 fast-path slots.The main purpose of the max_locks_per_transaction GUC is to size theshared lock table. It is often set to the "average" number of locksneeded by backends, with some backends using significantly more locks.This should not be a major issue, however. Some backens may have toinsert locks into the shared lock table, but there can't be too many ofthem, limiting the contention.The only solution is to increase the GUC, even if the shared lock tablealready has sufficient capacity. That is not free, especially in termsof memory usage (the shared lock table entries are fairly large). Itshould only happen on machines with plenty of memory, though.In the future we may consider a separate GUC for the number of fast-pathslots, but let's try without one first.Reviewed-by: Robert Haas, Jakub WartakDiscussion:https://postgr.es/m/510b887e-c0ce-4a0c-a17a-2c6abb8d9a5c@enterprisedb.com1 parentb524974 commitc4d5cb7
File tree
9 files changed
+212
-27
lines changed- src
- backend
- bootstrap
- postmaster
- storage
- ipc
- lmgr
- tcop
- utils/init
- include
- storage
9 files changed
+212
-27
lines changedLines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
309 | 309 |
| |
310 | 310 |
| |
311 | 311 |
| |
| 312 | + | |
| 313 | + | |
312 | 314 |
| |
313 | 315 |
| |
314 | 316 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
903 | 903 |
| |
904 | 904 |
| |
905 | 905 |
| |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
906 | 911 |
| |
907 | 912 |
| |
908 | 913 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
178 | 178 |
| |
179 | 179 |
| |
180 | 180 |
| |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
181 | 187 |
| |
182 | 188 |
| |
183 | 189 |
| |
|
Lines changed: 104 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
166 | 166 |
| |
167 | 167 |
| |
168 | 168 |
| |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
169 | 174 |
| |
170 |
| - | |
| 175 | + | |
171 | 176 |
| |
172 | 177 |
| |
173 | 178 |
| |
| |||
184 | 189 |
| |
185 | 190 |
| |
186 | 191 |
| |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
187 | 236 |
| |
188 | 237 |
| |
189 | 238 |
| |
190 | 239 |
| |
| 240 | + | |
191 | 241 |
| |
192 |
| - | |
| 242 | + | |
193 | 243 |
| |
194 | 244 |
| |
195 | 245 |
| |
196 | 246 |
| |
197 |
| - | |
| 247 | + | |
198 | 248 |
| |
199 |
| - | |
| 249 | + | |
200 | 250 |
| |
201 |
| - | |
| 251 | + | |
202 | 252 |
| |
203 |
| - | |
| 253 | + | |
204 | 254 |
| |
205 | 255 |
| |
206 | 256 |
| |
| |||
926 | 976 |
| |
927 | 977 |
| |
928 | 978 |
| |
929 |
| - | |
| 979 | + | |
930 | 980 |
| |
931 | 981 |
| |
932 | 982 |
| |
| |||
2065 | 2115 |
| |
2066 | 2116 |
| |
2067 | 2117 |
| |
2068 |
| - | |
| 2118 | + | |
2069 | 2119 |
| |
2070 | 2120 |
| |
2071 | 2121 |
| |
| |||
2633 | 2683 |
| |
2634 | 2684 |
| |
2635 | 2685 |
| |
2636 |
| - | |
| 2686 | + | |
2637 | 2687 |
| |
2638 | 2688 |
| |
| 2689 | + | |
| 2690 | + | |
| 2691 | + | |
2639 | 2692 |
| |
2640 |
| - | |
| 2693 | + | |
2641 | 2694 |
| |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
2642 | 2698 |
| |
2643 | 2699 |
| |
2644 | 2700 |
| |
| |||
2654 | 2710 |
| |
2655 | 2711 |
| |
2656 | 2712 |
| |
2657 |
| - | |
| 2713 | + | |
2658 | 2714 |
| |
2659 | 2715 |
| |
2660 | 2716 |
| |
| |||
2670 | 2726 |
| |
2671 | 2727 |
| |
2672 | 2728 |
| |
2673 |
| - | |
| 2729 | + | |
2674 | 2730 |
| |
2675 | 2731 |
| |
2676 |
| - | |
2677 |
| - | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
2678 | 2737 |
| |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
2679 | 2741 |
| |
2680 | 2742 |
| |
2681 | 2743 |
| |
| |||
2685 | 2747 |
| |
2686 | 2748 |
| |
2687 | 2749 |
| |
2688 |
| - | |
| 2750 | + | |
2689 | 2751 |
| |
2690 | 2752 |
| |
2691 | 2753 |
| |
| |||
2714 | 2776 |
| |
2715 | 2777 |
| |
2716 | 2778 |
| |
2717 |
| - | |
| 2779 | + | |
| 2780 | + | |
2718 | 2781 |
| |
2719 | 2782 |
| |
2720 | 2783 |
| |
| |||
2739 | 2802 |
| |
2740 | 2803 |
| |
2741 | 2804 |
| |
2742 |
| - | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
2743 | 2809 |
| |
2744 | 2810 |
| |
2745 | 2811 |
| |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
2746 | 2815 |
| |
2747 | 2816 |
| |
2748 | 2817 |
| |
| |||
2793 | 2862 |
| |
2794 | 2863 |
| |
2795 | 2864 |
| |
2796 |
| - | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
2797 | 2870 |
| |
2798 | 2871 |
| |
2799 | 2872 |
| |
2800 |
| - | |
| 2873 | + | |
2801 | 2874 |
| |
2802 | 2875 |
| |
2803 | 2876 |
| |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
2804 | 2880 |
| |
2805 | 2881 |
| |
2806 | 2882 |
| |
| |||
2957 | 3033 |
| |
2958 | 3034 |
| |
2959 | 3035 |
| |
2960 |
| - | |
| 3036 | + | |
| 3037 | + | |
2961 | 3038 |
| |
2962 | 3039 |
| |
2963 | 3040 |
| |
| |||
2979 | 3056 |
| |
2980 | 3057 |
| |
2981 | 3058 |
| |
2982 |
| - | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
2983 | 3063 |
| |
2984 | 3064 |
| |
2985 | 3065 |
| |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
2986 | 3069 |
| |
2987 | 3070 |
| |
2988 | 3071 |
| |
|
Lines changed: 46 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
103 | 103 |
| |
104 | 104 |
| |
105 | 105 |
| |
| 106 | + | |
| 107 | + | |
106 | 108 |
| |
107 | 109 |
| |
108 | 110 |
| |
| |||
113 | 115 |
| |
114 | 116 |
| |
115 | 117 |
| |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
116 | 127 |
| |
117 | 128 |
| |
118 | 129 |
| |
| |||
163 | 174 |
| |
164 | 175 |
| |
165 | 176 |
| |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
166 | 183 |
| |
167 | 184 |
| |
168 | 185 |
| |
| |||
211 | 228 |
| |
212 | 229 |
| |
213 | 230 |
| |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
214 | 245 |
| |
215 | 246 |
| |
216 | 247 |
| |
217 | 248 |
| |
218 | 249 |
| |
219 | 250 |
| |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
220 | 263 |
| |
221 | 264 |
| |
222 | 265 |
| |
| |||
278 | 321 |
| |
279 | 322 |
| |
280 | 323 |
| |
| 324 | + | |
| 325 | + | |
| 326 | + | |
281 | 327 |
| |
282 | 328 |
| |
283 | 329 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4190 | 4190 |
| |
4191 | 4191 |
| |
4192 | 4192 |
| |
| 4193 | + | |
| 4194 | + | |
| 4195 | + | |
4193 | 4196 |
| |
4194 | 4197 |
| |
4195 | 4198 |
| |
|
0 commit comments
Comments
(0)