forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3d47551
committed
Account explicitly for long-lived FDs that are allocated outside fd.c.
The comments in fd.c have long claimed that all file allocations shouldgo through that module, but in reality that's not always practical.fd.c doesn't supply APIs for invoking some FD-producing syscalls likepipe() or epoll_create(); and the APIs it does supply for non-virtualFDs are mostly insistent on releasing those FDs at transaction end;and in some cases the actual open() call is in code that can't be madeto use fd.c, such as libpq.This has led to a situation where, in a modern server, there are likelyto be seven or so long-lived FDs per backend process that are not knownto fd.c. Since NUM_RESERVED_FDS is only 10, that meant we had *very*few spare FDs if max_files_per_process is >= the system ulimit andfd.c had opened all the files it thought it safely could. Thecontrib/postgres_fdw regression test, in particular, could easily bemade to fall over by running it under a restrictive ulimit.To improve matters, invent functions Acquire/Reserve/ReleaseExternalFDthat allow outside callers to tell fd.c that they have or want to allocatea FD that's not directly managed by fd.c. Add calls to track all thefixed FDs in a standard backend session, so that we are honestlyguaranteeing that NUM_RESERVED_FDS FDs remain unused below the EMFILElimit in a backend's idle state. The coding rules for these functions saythat there's no need to call them in code that just allocates one FD overa fairly short interval; we can dip into NUM_RESERVED_FDS for such cases.That means that there aren't all that many places where we need to worry.But postgres_fdw and dblink must use this facility to account forlong-lived FDs consumed by libpq connections. There may be other placeswhere it's worth doing such accounting, too, but this seems like enoughto solve the immediate problem.Internally to fd.c, "external" FDs are limited to max_safe_fds/3 FDs.(Callers can choose to ignore this limit, but of course it's unwiseto do so except for fixed file allocations.) I also reduced the limiton "allocated" files to max_safe_fds/3 FDs (it had been max_safe_fds/2).Conceivably a smarter rule could be used here --- but in practice,on reasonable systems, max_safe_fds should be large enough that thisisn't much of an issue, so KISS for now. To avoid possible regressionin the number of external or allocated files that can be opened,increase FD_MINFREE and the lower limit on max_files_per_process alittle bit; we now insist that the effective "ulimit -n" be at least 64.This seems like pretty clearly a bug fix, but in view of the lack offield complaints, I'll refrain from risking a back-patch.Discussion:https://postgr.es/m/E1izCmM-0005pV-Co@gemulon.postgresql.org1 parent1420617 commit3d47551
File tree
12 files changed
+304
-23
lines changed- contrib
- dblink
- postgres_fdw
- src
- backend
- access/transam
- postmaster
- storage
- file
- ipc
- utils/misc
- include/storage
12 files changed
+304
-23
lines changedLines changed: 53 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
200 | 200 |
| |
201 | 201 |
| |
202 | 202 |
| |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
203 | 222 |
| |
| 223 | + | |
204 | 224 |
| |
205 | 225 |
| |
206 | 226 |
| |
207 | 227 |
| |
208 | 228 |
| |
| 229 | + | |
209 | 230 |
| |
210 | 231 |
| |
211 | 232 |
| |
| |||
282 | 303 |
| |
283 | 304 |
| |
284 | 305 |
| |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
285 | 325 |
| |
286 | 326 |
| |
287 | 327 |
| |
288 | 328 |
| |
289 | 329 |
| |
290 | 330 |
| |
| 331 | + | |
291 | 332 |
| |
292 | 333 |
| |
293 | 334 |
| |
| |||
312 | 353 |
| |
313 | 354 |
| |
314 | 355 |
| |
| 356 | + | |
315 | 357 |
| |
| 358 | + | |
| 359 | + | |
316 | 360 |
| |
317 | 361 |
| |
318 | 362 |
| |
| |||
346 | 390 |
| |
347 | 391 |
| |
348 | 392 |
| |
| 393 | + | |
349 | 394 |
| |
350 | 395 |
| |
351 | 396 |
| |
| |||
780 | 825 |
| |
781 | 826 |
| |
782 | 827 |
| |
| 828 | + | |
783 | 829 |
| |
| 830 | + | |
| 831 | + | |
784 | 832 |
| |
785 | 833 |
| |
786 | 834 |
| |
| |||
1458 | 1506 |
| |
1459 | 1507 |
| |
1460 | 1508 |
| |
| 1509 | + | |
1461 | 1510 |
| |
| 1511 | + | |
| 1512 | + | |
1462 | 1513 |
| |
1463 | 1514 |
| |
1464 | 1515 |
| |
| |||
2563 | 2614 |
| |
2564 | 2615 |
| |
2565 | 2616 |
| |
| 2617 | + | |
2566 | 2618 |
| |
2567 | 2619 |
| |
2568 | 2620 |
| |
| |||
2604 | 2656 |
| |
2605 | 2657 |
| |
2606 | 2658 |
| |
| 2659 | + | |
2607 | 2660 |
| |
2608 | 2661 |
| |
2609 | 2662 |
| |
|
Lines changed: 29 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
| |||
259 | 260 |
| |
260 | 261 |
| |
261 | 262 |
| |
262 |
| - | |
| 263 | + | |
263 | 264 |
| |
264 | 265 |
| |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
265 | 285 |
| |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
266 | 290 |
| |
267 | 291 |
| |
268 | 292 |
| |
| |||
294 | 318 |
| |
295 | 319 |
| |
296 | 320 |
| |
| 321 | + | |
297 | 322 |
| |
| 323 | + | |
| 324 | + | |
298 | 325 |
| |
299 | 326 |
| |
300 | 327 |
| |
| |||
312 | 339 |
| |
313 | 340 |
| |
314 | 341 |
| |
| 342 | + | |
315 | 343 |
| |
316 | 344 |
| |
317 | 345 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
774 | 774 |
| |
775 | 775 |
| |
776 | 776 |
| |
| 777 | + | |
777 | 778 |
| |
778 | 779 |
| |
779 | 780 |
| |
| |||
785 | 786 |
| |
786 | 787 |
| |
787 | 788 |
| |
| 789 | + | |
| 790 | + | |
| 791 | + | |
788 | 792 |
| |
789 | 793 |
| |
790 | 794 |
| |
| |||
2447 | 2451 |
| |
2448 | 2452 |
| |
2449 | 2453 |
| |
| 2454 | + | |
2450 | 2455 |
| |
2451 | 2456 |
| |
2452 | 2457 |
| |
| |||
2455 | 2460 |
| |
2456 | 2461 |
| |
2457 | 2462 |
| |
| 2463 | + | |
2458 | 2464 |
| |
2459 | 2465 |
| |
2460 | 2466 |
| |
| |||
2605 | 2611 |
| |
2606 | 2612 |
| |
2607 | 2613 |
| |
| 2614 | + | |
2608 | 2615 |
| |
2609 | 2616 |
| |
2610 | 2617 |
| |
| |||
3811 | 3818 |
| |
3812 | 3819 |
| |
3813 | 3820 |
| |
| 3821 | + | |
3814 | 3822 |
| |
3815 | 3823 |
| |
3816 | 3824 |
| |
| |||
5224 | 5232 |
| |
5225 | 5233 |
| |
5226 | 5234 |
| |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
5227 | 5240 |
| |
5228 | 5241 |
| |
5229 | 5242 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
602 | 602 |
| |
603 | 603 |
| |
604 | 604 |
| |
| 605 | + | |
| 606 | + | |
| 607 | + | |
605 | 608 |
| |
606 | 609 |
| |
607 | 610 |
| |
|
Lines changed: 31 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2554 | 2554 |
| |
2555 | 2555 |
| |
2556 | 2556 |
| |
| 2557 | + | |
| 2558 | + | |
2557 | 2559 |
| |
2558 | 2560 |
| |
2559 |
| - | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
| 2564 | + | |
2560 | 2565 |
| |
2561 | 2566 |
| |
2562 | 2567 |
| |
| |||
2566 | 2571 |
| |
2567 | 2572 |
| |
2568 | 2573 |
| |
2569 |
| - | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
2570 | 2578 |
| |
2571 | 2579 |
| |
2572 | 2580 |
| |
| |||
4279 | 4287 |
| |
4280 | 4288 |
| |
4281 | 4289 |
| |
| 4290 | + | |
| 4291 | + | |
| 4292 | + | |
4282 | 4293 |
| |
4283 | 4294 |
| |
4284 | 4295 |
| |
| |||
6442 | 6453 |
| |
6443 | 6454 |
| |
6444 | 6455 |
| |
| 6456 | + | |
| 6457 | + | |
| 6458 | + | |
| 6459 | + | |
| 6460 | + | |
| 6461 | + | |
| 6462 | + | |
| 6463 | + | |
| 6464 | + | |
| 6465 | + | |
| 6466 | + | |
| 6467 | + | |
| 6468 | + | |
| 6469 | + | |
6445 | 6470 |
| |
6446 | 6471 |
| |
6447 | 6472 |
| |
| |||
6584 | 6609 |
| |
6585 | 6610 |
| |
6586 | 6611 |
| |
| 6612 | + | |
| 6613 | + | |
| 6614 | + | |
| 6615 | + | |
6587 | 6616 |
| |
6588 | 6617 |
| |
6589 | 6618 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
562 | 562 |
| |
563 | 563 |
| |
564 | 564 |
| |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
565 | 570 |
| |
566 | 571 |
| |
567 | 572 |
| |
|
0 commit comments
Comments
(0)