We have a memory leak in the kernel of about 500 bytes per cycle if we open and close a lpuart on the Colibri VF50 board.
Our hardware has also additional uarts on a expansion board connected with SPI (SC16IS752 chip based).
We don’t have the effect for the uarts on the expansion board.
Here is my test code :
int main()
{
const char path[] = "/dev/ttyLP2";
int i;
int fd;
int status;
for (i = 0; i < 10000; ++i) {
if (i % 100 == 0)
printf("%d\n", i);
fd = open(path, O_RDWR | O_NOCTTY | O_NDELAY | O_EXCL);
if (fd == -1) {
printf("cannot open %s\n", path);
return 1;
}
status = close(fd);
if (status != 0)
printf("error on close : %s\n", strerror(errno));
}
return 0;
}
# uname -a
Linux EGV50 4.4.88 #5 PREEMPT Wed Jan 10 14:30:22 CET 2018 armv7l GNU/Linux
# cat /proc/meminfo
MemTotal: 120808 kB
MemFree: 84196 kB
MemAvailable: 99676 kB
Buffers: 0 kB
Cached: 17880 kB
SwapCached: 0 kB
Active: 13856 kB
Inactive: 9416 kB
Active(anon): 5432 kB
Inactive(anon): 420 kB
Active(file): 8424 kB
Inactive(file): 8996 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 5420 kB
Mapped: 11664 kB
Shmem: 456 kB
Slab: 8324 kB
SReclaimable: 2548 kB
SUnreclaim: 5776 kB
KernelStack: 496 kB
PageTables: 400 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 60404 kB
Committed_AS: 117080 kB
VmallocTotal: 1957888 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 16384 kB
CmaFree: 16008 kB
# ./Test
0
100
200
300
400
500
...
9300
9400
9500
9600
9700
9800
9900
# cat /proc/meminfo
MemTotal: 120808 kB
MemFree: 77952 kB
MemAvailable: 93444 kB
Buffers: 0 kB
Cached: 17888 kB
SwapCached: 0 kB
Active: 13932 kB
Inactive: 9352 kB
Active(anon): 5432 kB
Inactive(anon): 420 kB
Active(file): 8500 kB
Inactive(file): 8932 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 5420 kB
Mapped: 11672 kB
Shmem: 456 kB
Slab: 13408 kB
SReclaimable: 2552 kB
SUnreclaim: 10856 kB
KernelStack: 480 kB
PageTables: 400 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 60404 kB
Committed_AS: 117080 kB
VmallocTotal: 1957888 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
CmaTotal: 16384 kB
CmaFree: 16008 kB
My program open and close the device /dev/ttyLP2 10’000 time and then exits.
After it, MemAvailable has lost 6232 kB (99676 → 93444), and SUnreclaim is 5080 kB bigger.
If i’m not wrong, SUnreclaim are memory blocs allocated with something like kmalloc and not freed.
Best regards,
Patrick Gerber