| 643 | } |
| 644 | |
| 645 | static struct namecache * |
| 646 | cache_alloc(int len, bool ts) |
| 647 | { |
| 648 | u_long lnumcache; |
| 649 | |
| 650 | /* |
| 651 | * Avoid blowout in namecache entries. |
| 652 | * |
| 653 | * Bugs: |
| 654 | * 1. filesystems may end up trying to add an already existing entry |
| 655 | * (for example this can happen after a cache miss during concurrent |
| 656 | * lookup), in which case we will call cache_neg_evict despite not |
| 657 | * adding anything. |
| 658 | * 2. the routine may fail to free anything and no provisions are made |
| 659 | * to make it try harder (see the inside for failure modes) |
| 660 | * 3. it only ever looks at negative entries. |
| 661 | */ |
| 662 | lnumcache = atomic_fetchadd_long(&numcache, 1) + 1; |
| 663 | if (cache_neg_evict_cond(lnumcache)) { |
| 664 | lnumcache = atomic_load_long(&numcache); |
| 665 | } |
| 666 | if (__predict_false(lnumcache >= ncsize)) { |
| 667 | atomic_subtract_long(&numcache, 1); |
| 668 | counter_u64_add(numdrops, 1); |
| 669 | return (NULL); |
| 670 | } |
| 671 | return (cache_alloc_uma(len, ts)); |
| 672 | } |
| 673 | |
| 674 | static void |
| 675 | cache_free(struct namecache *ncp) |
no test coverage detected