MCPcopy Create free account
hub / github.com/F-Stack/f-stack / keg_alloc_slab

Function keg_alloc_slab

freebsd/vm/uma_core.c:1535–1644  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

1533 * caller specified M_NOWAIT.
1534 */
1535static uma_slab_t
1536keg_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 */

Callers 2

keg_fetch_slabFunction · 0.85
uma_preallocFunction · 0.85

Calls 9

zone_alloc_itemFunction · 0.85
slabzoneFunction · 0.85
zone_free_itemFunction · 0.85
slab_dbg_bitsFunction · 0.85
keg_free_slabFunction · 0.85
slab_tohashslabFunction · 0.70
uma_total_incFunction · 0.70
vsetzoneslabFunction · 0.70
slab_itemFunction · 0.70

Tested by

no test coverage detected