Opening a pseudo-tty (/dev/tty[p-zP-T][0-9a-zA-Z]) causes the kernel to allocate a struct tty for it, as well as ring buffers for tty data. This memory will not get released if the pseudo-tty is closed, for it may be opened again in the future.
On pseudo-ttys, the largest possible ring buffer size is used, which causes 26KB to be allocated (three 8KB rings plus two 1KB quote buffers). On a default OpenBSD install, only /dev/tty[pqr][0-9a-zA-Z] are created. That's 186 ttys. If they were to be opened, this would cause 4836KB of kernel memory to be allocated. And that's exactly what ttyflags(8) does: it will happily open every tty listed in /etc/ttys, and issue a TIOCSFLAGS ioctl to it, then close it. But pseudo-ttys ignore TIOCSFLAGS completely, so there is no point for ttyflags to open them, to begin with. On memory challenged systems, this is a significant waste of memory. I am therefore proposing the following diff, which will cause ttyflags -a to skip pseudo-ttys. Without this diff, after a multiuser boot: kern.malloc.kmemstat.ttys=(inuse = 1128, calls = 1128, memuse = 4982K, limblocks = 0, mapblocks = 0, maxused = 4982K, limit = 78644K, spare = 0, sizes = (512,1024,8192)) With this diff: kern.malloc.kmemstat.ttys=(inuse = 18, calls = 18, memuse = 80K, limblocks = 0, mapblocks = 0, maxused = 80K, limit = 78644K, spare = 0, sizes = (512,1024,8192)) Index: ttyflags.c =================================================================== RCS file: /OpenBSD/src/sbin/ttyflags/ttyflags.c,v retrieving revision 1.13 diff -u -p -r1.13 ttyflags.c --- ttyflags.c 4 Dec 2012 02:27:00 -0000 1.13 +++ ttyflags.c 13 Jan 2019 16:14:59 -0000 @@ -112,9 +112,13 @@ all(int print) int rval; rval = 0; - for (tep = getttyent(); tep != NULL; tep = getttyent()) + for (tep = getttyent(); tep != NULL; tep = getttyent()) { + /* pseudo-tty ignore TIOCSFLAGS, so don't bother */ + if (strcmp(tep->ty_type, "network") == 0) + continue; if (ttyflags(tep, print)) rval = 1; + } return (rval); }