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

Function keg_layout

freebsd/vm/uma_core.c:2087–2241  ·  view source on GitHub ↗

* Determine the format of a uma keg. This determines where the slab header * will be placed (inline or offpage) and calculates ipers, rsize, and ppera. * * Arguments * keg The zone we should initialize * * Returns * Nothing */

Source from the content-addressed store, hash-verified

2085 * Nothing
2086 */
2087static void
2088keg_layout(uma_keg_t keg)
2089{
2090 struct keg_layout_result kl = {}, kl_tmp;
2091 u_int fmts[2];
2092 u_int alignsize;
2093 u_int nfmt;
2094 u_int pages;
2095 u_int rsize;
2096 u_int slabsize;
2097 u_int i, j;
2098
2099 KASSERT((keg->uk_flags & UMA_ZONE_PCPU) == 0 ||
2100 (keg->uk_size <= UMA_PCPU_ALLOC_SIZE &&
2101 (keg->uk_flags & UMA_ZONE_CACHESPREAD) == 0),
2102 ("%s: cannot configure for PCPU: keg=%s, size=%u, flags=0x%b",
2103 __func__, keg->uk_name, keg->uk_size, keg->uk_flags,
2104 PRINT_UMA_ZFLAGS));
2105 KASSERT((keg->uk_flags & (UMA_ZFLAG_INTERNAL | UMA_ZONE_VM)) == 0 ||
2106 (keg->uk_flags & (UMA_ZONE_NOTOUCH | UMA_ZONE_PCPU)) == 0,
2107 ("%s: incompatible flags 0x%b", __func__, keg->uk_flags,
2108 PRINT_UMA_ZFLAGS));
2109
2110 alignsize = keg->uk_align + 1;
2111
2112 /*
2113 * Calculate the size of each allocation (rsize) according to
2114 * alignment. If the requested size is smaller than we have
2115 * allocation bits for we round it up.
2116 */
2117 rsize = MAX(keg->uk_size, UMA_SMALLEST_UNIT);
2118 rsize = roundup2(rsize, alignsize);
2119
2120 if ((keg->uk_flags & UMA_ZONE_CACHESPREAD) != 0) {
2121 /*
2122 * We want one item to start on every align boundary in a page.
2123 * To do this we will span pages. We will also extend the item
2124 * by the size of align if it is an even multiple of align.
2125 * Otherwise, it would fall on the same boundary every time.
2126 */
2127 if ((rsize & alignsize) == 0)
2128 rsize += alignsize;
2129 slabsize = rsize * (PAGE_SIZE / alignsize);
2130 slabsize = MIN(slabsize, rsize * SLAB_MAX_SETSIZE);
2131 slabsize = MIN(slabsize, UMA_CACHESPREAD_MAX_SIZE);
2132 slabsize = round_page(slabsize);
2133 } else {
2134 /*
2135 * Start with a slab size of as many pages as it takes to
2136 * represent a single item. We will try to fit as many
2137 * additional items into the slab as possible.
2138 */
2139 slabsize = round_page(keg->uk_size);
2140 }
2141
2142 /* Build a list of all of the available formats for this keg. */
2143 nfmt = 0;
2144

Callers 1

keg_ctorFunction · 0.85

Calls 1

keg_layout_oneFunction · 0.85

Tested by

no test coverage detected