<div dir="ltr"><div><div>maybe someone here can help me figure out how to map a big (really big) work area and lock it in memory.<br><br></div>I wrote a little test program to try this out, and it fails. As a regular user, perror() tells me some "resource is temporarily unavailable". As root, it says it "cannot allocate memory". I'm only asking for 1 byte. What's the problem? BTW it also fails if it asks for a mibibyte (1<<20).<br>
<br></div>Here's the whole program<br><br>/**<br> * @file<br> * <pre>"Find out the limits on locked memory"<br> * Last Modified: Mon Aug 18 07:31:01 PDT 2014</pre><br> * @author Kevin O'Gorman<br>
*/<br><br>#define _GNU_SOURCE /* enable some of the mmap flags */<br>#include <unistd.h><br>#include <stdlib.h><br>#include <stdio.h><br>#include <string.h><br>#include <sys/mman.h><br><br>int<br>
main(int argc, char *argv[])<br>{<br> void *where;<br> size_t length = 1;<br><br> where = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_LOCKED | MAP_POPULATE, -1, 0);<br> if (where != MAP_FAILED) {<br>
printf("Mapped at %p\n", where);<br> } else {<br> perror("Mapping failed");<br> }<br> <br> return EXIT_SUCCESS;<br>}<br><br clear="all"><div><div><div><br>-- <br><div dir="ltr">Kevin O'Gorman<br>
<br>programmer, n. an organism that transmutes caffeine into software.<br><span style="line-height:normal;font-variant:normal;font-size:10pt;font-style:normal;font-weight:normal"><span style="line-height:normal;font-variant:normal;font-size:10pt;font-style:normal;font-weight:normal"></span></span><table cellpadding="0" cellspacing="0" border="0" width="448">
<tbody><tr><td width="25"><img src="cid:XVHDKDFDBURW.IMAGE_60.gif" height="21" width="25"></td>
<td width="423"><span style="font-family:Verdana,Geneva,sans-serif;color:rgb(0,153,0);margin-left:5px;font-size:10px">Please consider the environment before printing this email.</span></td></tr></tbody></table><br></div>
</div></div></div></div>