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

Function vmem_try_fetch

freebsd/kern/subr_vmem.c:1037–1076  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1035}
1036
1037static int
1038vmem_try_fetch(vmem_t *vm, const vmem_size_t size, vmem_size_t align, int flags)
1039{
1040 vmem_size_t avail;
1041
1042 VMEM_ASSERT_LOCKED(vm);
1043
1044 /*
1045 * XXX it is possible to fail to meet xalloc constraints with the
1046 * imported region. It is up to the user to specify the
1047 * import quantum such that it can satisfy any allocation.
1048 */
1049 if (vmem_import(vm, size, align, flags) == 0)
1050 return (1);
1051
1052 /*
1053 * Try to free some space from the quantum cache or reclaim
1054 * functions if available.
1055 */
1056 if (vm->vm_qcache_max != 0 || vm->vm_reclaimfn != NULL) {
1057 avail = vm->vm_size - vm->vm_inuse;
1058 bt_save(vm);
1059 VMEM_UNLOCK(vm);
1060 if (vm->vm_qcache_max != 0)
1061 qc_drain(vm);
1062 if (vm->vm_reclaimfn != NULL)
1063 vm->vm_reclaimfn(vm, flags);
1064 VMEM_LOCK(vm);
1065 bt_restore(vm);
1066 /* If we were successful retry even NOWAIT. */
1067 if (vm->vm_size - vm->vm_inuse > avail)
1068 return (1);
1069 }
1070 if ((flags & M_NOWAIT) != 0)
1071 return (0);
1072 bt_save(vm);
1073 VMEM_CONDVAR_WAIT(vm);
1074 bt_restore(vm);
1075 return (1);
1076}
1077
1078static int
1079vmem_try_release(vmem_t *vm, struct vmem_btag *bt, const bool remfree)

Callers 2

vmem_xalloc_nextfitFunction · 0.85
vmem_xallocFunction · 0.85

Calls 4

vmem_importFunction · 0.85
bt_saveFunction · 0.85
qc_drainFunction · 0.85
bt_restoreFunction · 0.85

Tested by

no test coverage detected