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

Function memguard_fudge

freebsd/vm/memguard.c:165–201  ·  view source on GitHub ↗

* Return a fudged value to be used for vm_kmem_size for allocating * the kernel_arena. */

Source from the content-addressed store, hash-verified

163 * the kernel_arena.
164 */
165unsigned long
166memguard_fudge(unsigned long km_size, const struct vm_map *parent_map)
167{
168 u_long mem_pgs, parent_size;
169
170 vm_memguard_divisor = 10;
171 /* CTFLAG_RDTUN doesn't work during the early boot process. */
172 TUNABLE_INT_FETCH("vm.memguard.divisor", &vm_memguard_divisor);
173
174 parent_size = vm_map_max(parent_map) - vm_map_min(parent_map) +
175 PAGE_SIZE;
176 /* Pick a conservative value if provided value sucks. */
177 if ((vm_memguard_divisor <= 0) ||
178 ((parent_size / vm_memguard_divisor) == 0))
179 vm_memguard_divisor = 10;
180 /*
181 * Limit consumption of physical pages to
182 * 1/vm_memguard_divisor of system memory. If the KVA is
183 * smaller than this then the KVA limit comes into play first.
184 * This prevents memguard's page promotions from completely
185 * using up memory, since most malloc(9) calls are sub-page.
186 */
187 mem_pgs = vm_cnt.v_page_count;
188 memguard_physlimit = (mem_pgs / vm_memguard_divisor) * PAGE_SIZE;
189 /*
190 * We want as much KVA as we can take safely. Use at most our
191 * allotted fraction of the parent map's size. Limit this to
192 * twice the physical memory to avoid using too much memory as
193 * pagetable pages (size must be multiple of PAGE_SIZE).
194 */
195 memguard_mapsize = round_page(parent_size / vm_memguard_divisor);
196 if (memguard_mapsize / (2 * PAGE_SIZE) > mem_pgs)
197 memguard_mapsize = mem_pgs * 2 * PAGE_SIZE;
198 if (km_size + memguard_mapsize > parent_size)
199 memguard_mapsize = 0;
200 return (km_size + memguard_mapsize);
201}
202
203/*
204 * Initialize the MemGuard mock allocator. All objects from MemGuard come

Callers 1

kmeminitFunction · 0.85

Calls 2

vm_map_maxFunction · 0.85
vm_map_minFunction · 0.85

Tested by

no test coverage detected