* Allocate a new slab for a keg and inserts it into the partial slab list. * The keg should be unlocked on entry. If the allocation succeeds it will * be locked on return. * * Arguments: * flags Wait flags for the item initialization routine * aflags Wait flags for the slab allocation * * Returns: * The slab that was allocated or NULL if there is no memory and the * caller specified
| 1533 | * caller specified M_NOWAIT. |
| 1534 | */ |
| 1535 | static uma_slab_t |
| 1536 | keg_alloc_slab(uma_keg_t keg, uma_zone_t zone, int domain, int flags, |
| 1537 | int aflags) |
| 1538 | { |
| 1539 | uma_domain_t dom; |
| 1540 | uma_alloc allocf; |
| 1541 | uma_slab_t slab; |
| 1542 | unsigned long size; |
| 1543 | uint8_t *mem; |
| 1544 | uint8_t sflags; |
| 1545 | int i; |
| 1546 | |
| 1547 | KASSERT(domain >= 0 && domain < vm_ndomains, |
| 1548 | ("keg_alloc_slab: domain %d out of range", domain)); |
| 1549 | |
| 1550 | allocf = keg->uk_allocf; |
| 1551 | slab = NULL; |
| 1552 | mem = NULL; |
| 1553 | if (keg->uk_flags & UMA_ZFLAG_OFFPAGE) { |
| 1554 | uma_hash_slab_t hslab; |
| 1555 | hslab = zone_alloc_item(slabzone(keg->uk_ipers), NULL, |
| 1556 | domain, aflags); |
| 1557 | if (hslab == NULL) |
| 1558 | goto fail; |
| 1559 | slab = &hslab->uhs_slab; |
| 1560 | } |
| 1561 | |
| 1562 | /* |
| 1563 | * This reproduces the old vm_zone behavior of zero filling pages the |
| 1564 | * first time they are added to a zone. |
| 1565 | * |
| 1566 | * Malloced items are zeroed in uma_zalloc. |
| 1567 | */ |
| 1568 | |
| 1569 | if ((keg->uk_flags & UMA_ZONE_MALLOC) == 0) |
| 1570 | aflags |= M_ZERO; |
| 1571 | else |
| 1572 | aflags &= ~M_ZERO; |
| 1573 | |
| 1574 | if (keg->uk_flags & UMA_ZONE_NODUMP) |
| 1575 | aflags |= M_NODUMP; |
| 1576 | |
| 1577 | /* zone is passed for legacy reasons. */ |
| 1578 | size = keg->uk_ppera * PAGE_SIZE; |
| 1579 | mem = allocf(zone, size, domain, &sflags, aflags); |
| 1580 | if (mem == NULL) { |
| 1581 | if (keg->uk_flags & UMA_ZFLAG_OFFPAGE) |
| 1582 | zone_free_item(slabzone(keg->uk_ipers), |
| 1583 | slab_tohashslab(slab), NULL, SKIP_NONE); |
| 1584 | goto fail; |
| 1585 | } |
| 1586 | uma_total_inc(size); |
| 1587 | |
| 1588 | /* For HASH zones all pages go to the same uma_domain. */ |
| 1589 | if ((keg->uk_flags & UMA_ZFLAG_HASH) != 0) |
| 1590 | domain = 0; |
| 1591 | |
| 1592 | /* Point the slab into the allocated memory */ |
no test coverage detected