lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <54BCA187.6070601@huawei.com>
Date:	Mon, 19 Jan 2015 14:17:43 +0800
From:	"long.wanglong" <long.wanglong@...wei.com>
To:	<hannes@...xchg.org>, <shijie8@...il.com>,
	<torvalds@...ux-foundation.org>, <mhocko@...e.cz>,
	<azurit@...ox.sk>, <hugh.dickins@...cali.co.uk>,
	<rientjes@...gle.com>, <kosaki.motohiro@...fujitsu.com>,
	<long.wanglong@...wei.com>
CC:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	<peifeiyue@...wei.com>
Subject: does the semantics of MAP_LOCKED is equal to mlock() function?

Hi all:

In the latest kernel, i set the memory limit (4096) in a test cgroup. and add the test task.
the test code code is:

testcase 1: mmap with MAP_LOCKED flag(memsize = 8192)

185                 p = mmap(NULL, memsize, PROT_WRITE | PROT_READ,
186                          MAP_PRIVATE | MAP_ANONYMOUS | MAP_LOCKED, 0, 0);
187                 if (p == MAP_FAILED)
188                         err(1, "mmap(lock) failed");
					
expect: invoke OOM killer.
result: not invoke OOM killer.


testcase 2: mmap without MAP_LOCKED flag and the call mlock (memsize = 8192)

185                 p = mmap(NULL, memsize, PROT_WRITE | PROT_READ,
186                          MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
187                 if (p == MAP_FAILED)
188                         err(1, "mmap(lock) failed");
189
190                 if (mlock(p, memsize) == -1)
191                         err(1, "mlock failed")

expect: invoke OOM killer.
result: invoke OOM killer.

in the Linux Programmer's Manual:

MAP_LOCKED (since Linux 2.5.37)
		Lock the pages of the mapped region into memory in the manner
		of mlock(2).  This flag is ignored in older kernels.
	
and
       mlock() locks pages in the address range starting at addr and
       continuing for len bytes.  All pages that contain a part of the
       specified address range are guaranteed to be resident in RAM when the
       call returns successfully; the pages are guaranteed to stay in RAM
       until later unlocked.
	
According to the description in the manual, the two testcases are equivalent.

why the first testcase does not invoke OOM killer?
does the mmap with MAP_LOCKED flag will not immediately allocate physical memory?


Best Regards
Wang Long

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ