Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Oct 2018 14:06:17 +0000
From:      "Bennett, Ciunas" <ciunas.bennett@intel.com>
To:        "freebsd-current@freebsd.org" <freebsd-current@freebsd.org>
Cc:        "Bennett, Ciunas" <ciunas.bennett@intel.com>
Subject:   contigmalloc uses up all free  memory.
Message-ID:  <770FD3608C9E864796AB46CB37B561B1BDFCD284@IRSMSX101.ger.corp.intel.com>

next in thread | raw e-mail | index | archive | help
--_005_770FD3608C9E864796AB46CB37B561B1BDFCD284IRSMSX101gercor_
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable

Hello,

I have encountered an issue with a kernel application that I have written,
the application allocates  and deallocates contiguous memory using contigma=
lloc() and contigfree().
The application will fail after a period of time because there is not enoug=
h free contiguous memory left.
There could be an issue with the freeing of memory when using the contigfre=
e() 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 i=
ssue.

After a period of time when running the application multiple times, the ker=
nel 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 ho=
w 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 k=
ldunload 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 12.0-ALPHA9 also tested 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 h=
ost.

I have attached the test kernel application and a Makefile.

Thanks,
Ciunas.
--------------------------------------------------------------
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 s=
ole
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.

--_005_770FD3608C9E864796AB46CB37B561B1BDFCD284IRSMSX101gercor_
Content-Type: text/plain; name="k_memory_contig.c"
Content-Description: k_memory_contig.c
Content-Disposition: attachment; filename="k_memory_contig.c"; size=1866;
	creation-date="Wed, 17 Oct 2018 13:33:35 GMT";
	modification-date="Wed, 17 Oct 2018 13:33:35 GMT"
Content-Transfer-Encoding: base64

I2luY2x1ZGUgPHN5cy9wYXJhbS5oPgojaW5jbHVkZSA8c3lzL2NvbmYuaD4KI2luY2x1ZGUgPHN5
cy9rZXJuZWwuaD4KI2luY2x1ZGUgPHN5cy9tYWxsb2MuaD4KI2luY2x1ZGUgPHN5cy9tb2R1bGUu
aD4KI2luY2x1ZGUgPHN5cy9zeXN0bS5oPgoKI2RlZmluZSBERVZfTUVNICJ0ZXN0X21lbSIKCk1B
TExPQ19ERUNMQVJFKFRFU1RfTUVNKTsKTUFMTE9DX0RFRklORShURVNUX01FTSwgInRlc3RfbWVt
IiwgInRlc3RfbWVtIGRyaXZlciIpOwoKLyogVGVzdCBhcHBsaWNhdGlvbiB0byBhbGxvY2F0ZSBj
b250aWd1b3VzIG1lbW9yeSB0aGVuIGZyZWUgaXQgKi8Kc3RhdGljIGludCB0ZXN0X2FwcGxpY2F0
aW9uKCkKewogICAgaW50IGkgPSAwOwogICAgaW50IGFycmF5WzEwXSA9IHsyMDk3MTUyLCAxMDI0
LCAyMTAxMjQ4LCAxMDI0LCAyMDk3MTUyLCAyMTAxMjQ4LAogICAgICAgICAgICAgICAgICAgICAy
MTAxMjQ4LCAyMDk3MTUyLCAyMTAxMjQ4LCAxMDI0fTsKICAgIGludCBhcnJheTFbMTBdID0gezEw
MjQsIDIxMDEyNDgsIDIwOTcxNTIsIDIxMDEyNDgsIDIxMDEyNDgsIDIwOTcxNTIsCiAgICAgICAg
ICAgICAgICAgICAgICAxMDI0LCAyMTAxMjQ4LCAxMDI0LCAyMDk3MTUyfTsKICAgIHZvaWQgKm1l
bV9ibG9ja3NbMTBdOwoKICAgIGZvciAoaSA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VudXNlZCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGludCB0eXBlLAogICAgICAg
ICAgICAgICAgICAgICAgICAgICAgdm9pZCAqZGF0YSBfX3VudXNlZCkKewoKICAgIHN3aXRjaCAo
dHlwZSkKICAgIHsKICAgICAgICBjYXNlIE1PRF9MT0FEOgogICAgICAgICAgICB0ZXN0X2FwcGxp
Y2F0aW9uKCk7CiAgICAgICAgICAgIHJldHVybiAoMCk7CiAgICAgICAgY2FzZSBNT0RfVU5MT0FE
OgogICAgICAgICAgICByZXR1cm4gKDApOwogICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJl
dHVybiAoRU9QTk9UU1VQUCk7CiAgICB9Cn0KCkRFVl9NT0RVTEUodGVzdF9tZW0sIG1lbV9tb2Rl
dmVudCwgTlVMTCk7Ck1PRFVMRV9WRVJTSU9OKHRlc3RfbWVtLCAxKTsK

--_005_770FD3608C9E864796AB46CB37B561B1BDFCD284IRSMSX101gercor_
Content-Type: application/octet-stream; name="Makefile"
Content-Description: Makefile
Content-Disposition: attachment; filename="Makefile"; size=67;
	creation-date="Wed, 17 Oct 2018 13:33:25 GMT";
	modification-date="Wed, 17 Oct 2018 13:33:04 GMT"
Content-Transfer-Encoding: base64

S01PRD0Ja19tZW1vcnlfYXBwClNSQ1M9CWtfbWVtb3J5X2NvbnRpZy5jCgouaW5jbHVkZSA8YnNk
Lmttb2QubWs+Cg==

--_005_770FD3608C9E864796AB46CB37B561B1BDFCD284IRSMSX101gercor_--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?770FD3608C9E864796AB46CB37B561B1BDFCD284>