LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "long.wanglong" <long.wanglong@huawei.com>
To: <hannes@cmpxchg.org>, <shijie8@gmail.com>,
	<torvalds@linux-foundation.org>, <mhocko@suse.cz>,
	<azurit@pobox.sk>, <hugh.dickins@tiscali.co.uk>,
	<rientjes@google.com>, <kosaki.motohiro@jp.fujitsu.com>,
	<long.wanglong@huawei.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	<peifeiyue@huawei.com>
Subject: does the semantics of MAP_LOCKED is equal to mlock() function?
Date: Mon, 19 Jan 2015 14:17:43 +0800	[thread overview]
Message-ID: <54BCA187.6070601@huawei.com> (raw)

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


             reply	other threads:[~2015-01-19  6:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19  6:17 long.wanglong [this message]
2015-01-19  9:46 ` Michal Hocko
2015-01-19 11:01   ` Michal Hocko
2015-01-20  3:23     ` long.wanglong
2015-01-20 12:58       ` Michal Hocko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54BCA187.6070601@huawei.com \
    --to=long.wanglong@huawei.com \
    --cc=azurit@pobox.sk \
    --cc=hannes@cmpxchg.org \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=peifeiyue@huawei.com \
    --cc=rientjes@google.com \
    --cc=shijie8@gmail.com \
    --cc=torvalds@linux-foundation.org \
    --subject='Re: does the semantics of MAP_LOCKED is equal to mlock() function?' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).