mlock() - Unix, Linux System Call

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor
Unix - What is Shell?
Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions
Unix - Quoting Mechanisms
Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help
Unix - Regular Expressions
Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps
Unix - Useful Commands
Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix Useful Resources
Computer Glossary
Who is Who
Copyright © 2014 by tutorialspoint
#include <sys/mman.h> 

int mlock(const void *addr, size_t len);

int munlock(const void *addr, size_t len);

int mlockall(int flags);

int munlockall(void);


int mlock(const void *addr, size_t len);


int munlock(const void *addr, size_t len);


int mlockall(int flags);


int munlockall(void);


munlock() unlocks pages in the address range starting at
addr and continuing for
len bytes.
After this call, all pages that contain a part of the specified
memory range can be moved to external swap space again by the kernel.


The
flags argument is constructed as the bitwise OR of one or more of the
following constants:


munlockall() unlocks all pages mapped into the address space of the
calling process.


Real-time processes that are using
mlockall() to prevent delays on page faults should reserve enough
locked stack pages before entering the time-critical section,
so that no page fault can be caused by function calls.
This can be achieved by calling a function that allocates a
sufficiently large automatic variable (an array) and writes to the
memory occupied by this array in order to touch these stack pages.
This way, enough pages will be mapped for the stack and can be
locked into RAM. The dummy writes ensure that not even copy-on-write
page faults can occur in the critical section.


Memory locks are not inherited by a child created via
fork(2)
and are automatically removed (unlocked) during an
execve(2)
or when the process terminates.


The memory lock on an address range is automatically removed
if the address range is unmapped via
munmap(2).


Memory locks do not stack, i.e., pages which have been locked several times
by calls to
mlock() or
mlockall() will be unlocked by a single call to
munlock() for the corresponding range or by
munlockall(). Pages which are mapped to several locations or by several processes stay
locked into RAM as long as they are locked at least at one location or by
at least one process.


Since Linux 2.6.9, no limits are placed on the amount of memory
that a privileged process can lock and the
RLIMIT_MEMLOCK soft resource limit instead defines a limit on how much memory an
unprivileged process may lock.


Since kernel 2.6.9, if a privileged process calls
mlockall(MCL_FUTURE) and later drops privileges (loses the
CAP_IPC_LOCK capability by, for example,
setting its effective UID to a non-zero value),
then subsequent memory allocations (e.g.,
mmap(2),
brk(2))
will fail if the
RLIMIT_MEMLOCK resource limit is encountered.


On POSIX systems on which
mlockall() and
munlockall() are available,
_POSIX_MEMLOCK is defined in <unistd.h> to a value greater than 0. (See also
sysconf(3).)

mmap (2)
mmap (2)
shmctl (2)
shmctl (2)
setrlimit (2)
setrlimit (2)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page