Lines Matching full:bt

177 #define	BT_ISSPAN_P(bt)	((bt)->bt_type <= BT_TYPE_SPAN_STATIC)
179 #define BT_END(bt) ((bt)->bt_start + (bt)->bt_size - 1)
249 bt_isbusy(bt_t *bt)
251 return (bt->bt_type == BT_TYPE_BUSY);
255 bt_isfree(bt_t *bt)
257 return (bt->bt_type == BT_TYPE_FREE);
268 bt_t *bt;
287 bt = uma_zalloc(vmem_bt_zone,
289 if (bt == NULL) {
291 bt = uma_zalloc(vmem_bt_zone, flags);
293 if (bt == NULL)
296 LIST_INSERT_HEAD(&vm->vm_freetags, bt, bt_freelist);
320 bt_t *bt;
323 bt = LIST_FIRST(&vm->vm_freetags);
324 MPASS(bt != NULL);
325 LIST_REMOVE(bt, bt_freelist);
328 return bt;
339 bt_t *bt;
344 bt = LIST_FIRST(&vm->vm_freetags);
345 LIST_REMOVE(bt, bt_freelist);
347 LIST_INSERT_HEAD(&freetags, bt, bt_freelist);
350 while ((bt = LIST_FIRST(&freetags)) != NULL) {
351 LIST_REMOVE(bt, bt_freelist);
352 uma_zfree(vmem_bt_zone, bt);
357 bt_free(vmem_t *vm, bt_t *bt)
361 MPASS(LIST_FIRST(&vm->vm_freetags) != bt);
362 LIST_INSERT_HEAD(&vm->vm_freetags, bt, bt_freelist);
456 bt_t *bt;
460 LIST_FOREACH(bt, list, bt_hashlist) {
461 if (bt->bt_start == addr) {
466 return bt;
470 bt_rembusy(vmem_t *vm, bt_t *bt)
475 vm->vm_inuse -= bt->bt_size;
477 LIST_REMOVE(bt, bt_hashlist);
481 bt_insbusy(vmem_t *vm, bt_t *bt)
486 MPASS(bt->bt_type == BT_TYPE_BUSY);
488 list = bt_hashhead(vm, bt->bt_start);
489 LIST_INSERT_HEAD(list, bt, bt_hashlist);
491 vm->vm_inuse += bt->bt_size;
497 bt_remseg(vmem_t *vm, bt_t *bt)
500 MPASS(bt->bt_type != BT_TYPE_CURSOR);
501 TAILQ_REMOVE(&vm->vm_seglist, bt, bt_seglist);
502 bt_free(vm, bt);
506 bt_insseg(vmem_t *vm, bt_t *bt, bt_t *prev)
509 TAILQ_INSERT_AFTER(&vm->vm_seglist, prev, bt, bt_seglist);
513 bt_insseg_tail(vmem_t *vm, bt_t *bt)
516 TAILQ_INSERT_TAIL(&vm->vm_seglist, bt, bt_seglist);
520 bt_remfree(vmem_t *vm __unused, bt_t *bt)
523 MPASS(bt->bt_type == BT_TYPE_FREE);
525 LIST_REMOVE(bt, bt_freelist);
529 bt_insfree(vmem_t *vm, bt_t *bt)
533 list = bt_freehead_tofree(vm, bt->bt_size);
534 LIST_INSERT_HEAD(list, bt, bt_freelist);
728 bt_t *bt;
753 while ((bt = LIST_FIRST(&oldhashlist[i])) != NULL) {
754 bt_rembusy(vm, bt);
755 bt_insbusy(vm, bt);
875 bt_t *bt;
889 while ((bt = TAILQ_FIRST(&vm->vm_seglist)) != NULL)
890 bt_remseg(vm, bt);
936 * vmem_fit: check if a bt can satisfy the given restrictions.
942 vmem_fit(const bt_t *bt, vmem_size_t size, vmem_size_t align,
950 MPASS(bt->bt_size >= size); /* caller's responsibility */
957 start = bt->bt_start;
961 end = BT_END(bt);
968 if (start < bt->bt_start)
979 MPASS(bt->bt_start <= start);
980 MPASS(BT_END(bt) - start >= size - 1);
992 vmem_clip(vmem_t *vm, bt_t *bt, vmem_addr_t start, vmem_size_t size)
998 MPASS(bt->bt_type == BT_TYPE_FREE);
999 MPASS(bt->bt_size >= size);
1000 bt_remfree(vm, bt);
1001 if (bt->bt_start != start) {
1004 btprev->bt_start = bt->bt_start;
1005 btprev->bt_size = start - bt->bt_start;
1006 bt->bt_start = start;
1007 bt->bt_size -= btprev->bt_size;
1010 TAILQ_PREV(bt, vmem_seglist, bt_seglist));
1012 MPASS(bt->bt_start == start);
1013 if (bt->bt_size != size && bt->bt_size - size > vm->vm_quantum_mask) {
1017 btnew->bt_start = bt->bt_start;
1019 bt->bt_start = bt->bt_start + size;
1020 bt->bt_size -= size;
1021 bt_insfree(vm, bt);
1023 TAILQ_PREV(bt, vmem_seglist, bt_seglist));
1025 bt = btnew;
1027 bt->bt_type = BT_TYPE_BUSY;
1028 bt_insbusy(vm, bt);
1030 MPASS(bt->bt_size >= size);
1075 vmem_try_release(vmem_t *vm, struct vmem_btag *bt, const bool remfree)
1079 MPASS(bt->bt_type == BT_TYPE_FREE);
1084 prev = TAILQ_PREV(bt, vmem_seglist, bt_seglist);
1088 if (prev->bt_type == BT_TYPE_SPAN && prev->bt_size == bt->bt_size) {
1092 MPASS(prev->bt_start == bt->bt_start);
1096 bt_remfree(vm, bt);
1097 bt_remseg(vm, bt);
1113 struct vmem_btag *bt, *cursor, *next, *prev;
1130 for (cursor = &vm->vm_cursor, bt = TAILQ_NEXT(cursor, bt_seglist);
1131 bt != cursor; bt = TAILQ_NEXT(bt, bt_seglist)) {
1132 if (bt == NULL)
1133 bt = TAILQ_FIRST(&vm->vm_seglist);
1134 if (bt->bt_type == BT_TYPE_FREE && bt->bt_size >= size &&
1135 (error = vmem_fit(bt, size, align, phase, nocross,
1137 vmem_clip(vm, bt, *addrp, size);
1163 bt = prev;
1173 for (; bt != NULL && bt->bt_start < *addrp + size;
1174 bt = TAILQ_NEXT(bt, bt_seglist))
1176 if (bt != NULL)
1177 TAILQ_INSERT_BEFORE(bt, cursor, bt_seglist);
1360 bt_t *bt;
1416 LIST_FOREACH(bt, list, bt_freelist) {
1417 if (bt->bt_size >= size) {
1418 error = vmem_fit(bt, size, align, phase,
1421 vmem_clip(vm, bt, *addrp, size);
1478 bt_t *bt;
1484 bt = bt_lookupbusy(vm, addr);
1485 MPASS(bt != NULL);
1486 MPASS(bt->bt_start == addr);
1487 MPASS(bt->bt_size == vmem_roundup_size(vm, size) ||
1488 bt->bt_size - vmem_roundup_size(vm, size) <= vm->vm_quantum_mask);
1489 MPASS(bt->bt_type == BT_TYPE_BUSY);
1490 bt_rembusy(vm, bt);
1491 bt->bt_type = BT_TYPE_FREE;
1494 t = TAILQ_NEXT(bt, bt_seglist);
1496 MPASS(BT_END(bt) < t->bt_start); /* YYY */
1497 bt->bt_size += t->bt_size;
1501 t = TAILQ_PREV(bt, vmem_seglist, bt_seglist);
1503 MPASS(BT_END(t) < bt->bt_start); /* YYY */
1504 bt->bt_size += t->bt_size;
1505 bt->bt_start = t->bt_start;
1510 if (!vmem_try_release(vm, bt, false)) {
1511 bt_insfree(vm, bt);
1597 bt_dump(const bt_t *bt, int (*pr)(const char *, ...))
1601 bt, (intmax_t)bt->bt_start, (intmax_t)bt->bt_size,
1602 bt->bt_type, bt_type_string(bt->bt_type));
1608 const bt_t *bt;
1612 TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
1613 bt_dump(bt, pr);
1624 LIST_FOREACH(bt, fl, bt_freelist) {
1625 bt_dump(bt, pr);
1638 bt_t *bt;
1640 TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
1641 if (BT_ISSPAN_P(bt)) {
1644 if (bt->bt_start <= addr && addr <= BT_END(bt)) {
1645 return bt;
1658 bt_t *bt;
1660 bt = vmem_whatis_lookup(vm, addr);
1661 if (bt == NULL) {
1665 (void *)addr, (void *)bt->bt_start,
1666 (vmem_size_t)(addr - bt->bt_start), vm->vm_name,
1667 (bt->bt_type == BT_TYPE_BUSY) ? "allocated" : "free");
1711 const bt_t *bt;
1733 TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
1734 ord = SIZE2ORDER(bt->bt_size >> vm->vm_quantum_shift);
1735 if (bt->bt_type == BT_TYPE_BUSY) {
1737 us[ord] += bt->bt_size;
1738 } else if (bt->bt_type == BT_TYPE_FREE) {
1740 fs[ord] += bt->bt_size;
1769 const bt_t *bt, *bt2;
1773 TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
1774 if (bt->bt_start > BT_END(bt)) {
1776 bt_dump(bt, vmem_printf);
1780 TAILQ_FOREACH(bt, &vm->vm_seglist, bt_seglist) {
1781 if (bt->bt_type == BT_TYPE_CURSOR) {
1782 if (bt->bt_start != 0 || bt->bt_size != 0) {
1789 if (bt == bt2) {
1795 if (BT_ISSPAN_P(bt) != BT_ISSPAN_P(bt2)) {
1798 if (bt->bt_start <= BT_END(bt2) &&
1799 bt2->bt_start <= BT_END(bt)) {
1801 bt_dump(bt, vmem_printf);