mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tiago Vignatti <vignatti@c3sl.ufpr.br>
To: linux-kernel@vger.kernel.org
Subject: mlock() is working?
Date: Fri, 10 Aug 2007 00:41:47 -0300	[thread overview]
Message-ID: <46BBDE7B.7060908@c3sl.ufpr.br> (raw)

Hi guys,

I'm trying to lock some piece of the code in memory using mlock(). I did 
a simple program to test it and to certify I using my own simple page 
fault notifier [0]. The program is below.

-- cut --

#include <stdio.h>
#include <sys/mman.h>

#define SIZE 10000

int mlock_all = 0;

int
f(void)
{
     int c[SIZE];
     int i;

     if (mlock_all) {
         if (!mlockall(MCL_CURRENT))
             fprintf(stderr, "mlockall'ed succefully\n");
         else
             perror("mlockall");
     }
     else {
         if (!mlock(&c[0], SIZE))
             fprintf(stderr, "mlock'ed succefully\n");
         else
             perror("mlock");
     }

     fprintf(stderr, "start: 0x%x, end: 0x%x\n", &c[0], &c[SIZE]);

     for (i = 0; i < SIZE; i++)
         c[i] = i;

}
int
main(int argc, char **argv)
{
     if (argv[1])
         mlock_all = 1;

     while(1) {
         f();
         sleep (15);
     }

     return 0;
}

-- cut --


So, if I use mlockall() I always obtained the desired result, i.e., I 
lock the 'c[SIZE]'. But when I switch to mlock() it never works and my 
page fault notifier prints all pages concerning 'c[SIZE]'. Am I missing 
something? Is it possible to lock the automatic variables?

My Linux is 2.6.22.2.

my regards

[0] http://lkml.org/lkml/2007/7/27/11
     http://lkml.org/lkml/2007/7/27/8

-- 
Tiago Vignatti
C3SL - Centro de Computação Científica e Software Livre
www.c3sl.ufpr.br

                 reply	other threads:[~2007-08-10  3:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=46BBDE7B.7060908@c3sl.ufpr.br \
    --to=vignatti@c3sl.ufpr.br \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®