Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel crash on working with big memory chunk #3

Open
mihalicyn opened this issue May 7, 2017 · 3 comments
Open

Kernel crash on working with big memory chunk #3

mihalicyn opened this issue May 7, 2017 · 3 comments
Assignees
Labels

Comments

@mihalicyn
Copy link
Owner

Consider the following code (write.lua):

local start = os.clock();

local f = io.open("/root/dev/write.lua", 'r')
local s = f:read('all')
f:close()

os.remove("/root/dev/out.txt");
local fout = io.open("/root/dev/out.txt", 'w+')
fout:write(s)
fout:close()

print("os.clock(): " .. (os.clock() - start) .. " seconds")

If we run that in user space - all is fine!
If we run that in kernel space we got copy of write.lua (content is code in listing).
If we try big file for example syssrc.tgz (~50MiB) we got freeze, try bigger (~150MiB) and got kernel crash (fatal page fault). Problem is in read_all function.

@mihalicyn mihalicyn added the bug label May 7, 2017
@mihalicyn mihalicyn self-assigned this May 7, 2017
@mihalicyn
Copy link
Owner Author

After researching of problem internals I realized, that we have a problem with memory allocation (and we have no ENOMEM error and so on).

Consider the following code:

print("Strings test...")

string1 = "Hello, World!\n"
string = ""

count = 50000000

string = string1:rep(count)

print(string:len())
assert(string:len() == count * string1:len())

print("DONE")

NetBSD netbsd 7.1 NetBSD 7.1 (GENERIC.201703111743Z) i386

@mihalicyn mihalicyn changed the title Kernel crash on reading big file Kernel crash on working with big memory chunk May 9, 2017
@mihalicyn
Copy link
Owner Author

mihalicyn commented May 11, 2017

PR/52225 created and fixed
http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=52225

@mihalicyn
Copy link
Owner Author

mihalicyn commented Jul 26, 2017

PR/52225 solves problem for case when lua_alloc called in interruption handler context. In general case we can got kernel freeze:

		km_flag_t sleep = cpu_intr_p() || cpu_softintr_p() ?
			KM_NOSLEEP : KM_SLEEP;
//...

alloc_header_t *nhdr = kmem_intr_alloc(alloc_size, sleep);

For example. In my VirtualBox VM I have 1 GiB of RAM, and I trying to alloc ~300MiB and got freeze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant