* GetAccessStrategy -- create a BufferAccessStrategy object * * The object is allocated in the current memory context. */
| 545 | * The object is allocated in the current memory context. |
| 546 | */ |
| 547 | BufferAccessStrategy |
| 548 | GetAccessStrategy(BufferAccessStrategyType btype) |
| 549 | { |
| 550 | BufferAccessStrategy strategy; |
| 551 | int ring_size; |
| 552 | |
| 553 | /* |
| 554 | * Select ring size to use. See buffer/README for rationales. |
| 555 | * |
| 556 | * Note: if you change the ring size for BAS_BULKREAD, see also |
| 557 | * SYNC_SCAN_REPORT_INTERVAL in access/heap/syncscan.c. |
| 558 | */ |
| 559 | switch (btype) |
| 560 | { |
| 561 | case BAS_NORMAL: |
| 562 | /* if someone asks for NORMAL, just give 'em a "default" object */ |
| 563 | return NULL; |
| 564 | |
| 565 | case BAS_BULKREAD: |
| 566 | ring_size = 256 * 1024 / BLCKSZ; |
| 567 | break; |
| 568 | case BAS_BULKWRITE: |
| 569 | ring_size = 16 * 1024 * 1024 / BLCKSZ; |
| 570 | break; |
| 571 | case BAS_VACUUM: |
| 572 | ring_size = 256 * 1024 / BLCKSZ; |
| 573 | break; |
| 574 | |
| 575 | default: |
| 576 | elog(ERROR, "unrecognized buffer access strategy: %d", |
| 577 | (int) btype); |
| 578 | return NULL; /* keep compiler quiet */ |
| 579 | } |
| 580 | |
| 581 | /* Make sure ring isn't an undue fraction of shared buffers */ |
| 582 | ring_size = Min(NBuffers / 8, ring_size); |
| 583 | |
| 584 | /* Allocate the object and initialize all elements to zeroes */ |
| 585 | strategy = (BufferAccessStrategy) |
| 586 | palloc0(offsetof(BufferAccessStrategyData, buffers) + |
| 587 | ring_size * sizeof(Buffer)); |
| 588 | |
| 589 | /* Set fields that don't start out zero */ |
| 590 | strategy->btype = btype; |
| 591 | strategy->ring_size = ring_size; |
| 592 | |
| 593 | return strategy; |
| 594 | } |
| 595 | |
| 596 | /* |
| 597 | * FreeAccessStrategy -- release a BufferAccessStrategy object |
no test coverage detected