Possible memory leak in the kernel (contigmalloc)

Bennett, Ciunas ciunas.bennett at intel.com
Wed Oct 24 16:29:07 UTC 2018


I have encountered an issue with a kernel application that I have written, the issue might be caused by a memory leak in the kernel.
The application allocates  and deallocates contiguous memory using contigmalloc() and contigfree().
The application will fail after a period of time because there is not enough free contiguous memory left.
There could be an issue with the freeing of memory when using the contigfree() function.

I have attached a simplified version of the application.
The resulting kernel module just allocates contiguous memory and then frees the memory using contigfree();
This allocation is done in a loop and the attached  src code triggers the issue.

After a period of time when running the application multiple times, the kernel reports
that there is no available memory and fails with allocation.

I can see that the amount of free memory is decreasing in correlation to how many

times I run the application by using DDB and printing out freepages using "show freepages"

I run the application in a loop using a shell script where I kldload then kldunload multiple times (script runs up to 1000000)

The application can take 20 to over 60 minutes to trigger the issue and run out of memory but can take longer also.

I am running the application on ->
FreeBSD on 11.2
VM with 2 Gb of ram.
Allocating one cpu core.
Running on an Intel(R) Xeon(R) CPU E5-2658 v2 @ 2.40GH using Ubuntu 16.04 host.

I have attached the test kernel application and a Makefile.

Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263

This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: k_memory_contig.c
URL: <http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20181024/f8b8155b/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 67 bytes
Desc: Makefile
URL: <http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20181024/f8b8155b/attachment.obj>

More information about the freebsd-stable mailing list