Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/sys/mlock.2
Show All 22 Lines | |||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" @(#)mlock.2 8.2 (Berkeley) 12/11/93 | .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93 | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd March 20, 2018 | .Dd April 8, 2019 | ||||
.Dt MLOCK 2 | .Dt MLOCK 2 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm mlock , | .Nm mlock , | ||||
.Nm munlock | .Nm munlock | ||||
.Nd lock (unlock) physical pages in memory | .Nd lock (unlock) physical pages in memory | ||||
.Sh LIBRARY | .Sh LIBRARY | ||||
.Lb libc | .Lb libc | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
The amount of memory that a single process can | The amount of memory that a single process can | ||||
.Fn mlock | .Fn mlock | ||||
is limited by both the per-process | is limited by both the per-process | ||||
.Dv RLIMIT_MEMLOCK | .Dv RLIMIT_MEMLOCK | ||||
resource limit and the | resource limit and the | ||||
system-wide | system-wide | ||||
.Dq wired pages | .Dq wired pages | ||||
limit | limit | ||||
.Va vm.max_wired . | .Va vm.max_user_wired . | ||||
.Va vm.max_wired | .Va vm.max_user_wired | ||||
applies to the system as a whole, so the amount available to a single | applies to the system as a whole, so the amount available to a single | ||||
process at any given time is the difference between | process at any given time is the difference between | ||||
.Va vm.max_wired | .Va vm.max_user_wired | ||||
and | and | ||||
.Va vm.stats.vm.v_wire_count . | .Va vm.stats.vm.v_user_wire_count . | ||||
.Pp | .Pp | ||||
If | If | ||||
.Va security.bsd.unprivileged_mlock | .Va security.bsd.unprivileged_mlock | ||||
is set to 0 these calls are only available to the super-user. | is set to 0 these calls are only available to the super-user. | ||||
.Sh RETURN VALUES | .Sh RETURN VALUES | ||||
.Rv -std | .Rv -std | ||||
.Pp | .Pp | ||||
If the call succeeds, all pages in the range become locked (unlocked); | If the call succeeds, all pages in the range become locked (unlocked); | ||||
otherwise the locked status of all pages in the range remains unchanged. | otherwise the locked status of all pages in the range remains unchanged. | ||||
.Sh ERRORS | .Sh ERRORS | ||||
The | The | ||||
.Fn mlock | .Fn mlock | ||||
system call | system call | ||||
will fail if: | will fail if: | ||||
.Bl -tag -width Er | .Bl -tag -width Er | ||||
.It Bq Er EPERM | .It Bq Er EPERM | ||||
.Va security.bsd.unprivileged_mlock | .Va security.bsd.unprivileged_mlock | ||||
is set to 0 and the caller is not the super-user. | is set to 0 and the caller is not the super-user. | ||||
.It Bq Er EINVAL | .It Bq Er EINVAL | ||||
The address range given wraps around zero. | The address range given wraps around zero. | ||||
.It Bq Er EAGAIN | |||||
Locking the indicated range would exceed the system limit for locked memory. | |||||
.It Bq Er ENOMEM | .It Bq Er ENOMEM | ||||
Some portion of the indicated address range is not allocated. | Some portion of the indicated address range is not allocated. | ||||
There was an error faulting/mapping a page. | There was an error faulting/mapping a page. | ||||
Locking the indicated range would exceed the per-process limit for locked | Locking the indicated range would exceed the per-process or system-wide limits | ||||
memory. | for locked memory. | ||||
.El | .El | ||||
The | The | ||||
.Fn munlock | .Fn munlock | ||||
system call | system call | ||||
will fail if: | will fail if: | ||||
.Bl -tag -width Er | .Bl -tag -width Er | ||||
.It Bq Er EPERM | .It Bq Er EPERM | ||||
.Va security.bsd.unprivileged_mlock | .Va security.bsd.unprivileged_mlock | ||||
Show All 24 Lines | |||||
and | and | ||||
.Fn munlock | .Fn munlock | ||||
system calls first appeared in | system calls first appeared in | ||||
.Bx 4.4 . | .Bx 4.4 . | ||||
.Sh BUGS | .Sh BUGS | ||||
Allocating too much wired memory can lead to a memory-allocation deadlock | Allocating too much wired memory can lead to a memory-allocation deadlock | ||||
which requires a reboot to recover from. | which requires a reboot to recover from. | ||||
.Pp | .Pp | ||||
The per-process resource limit is a limit on the amount of virtual | The per-process and system-wide resource limits of locked memory apply | ||||
memory locked, while the system-wide limit is for the number of locked | to the amount of virtual memory locked, not the amount of locked physical | ||||
physical pages. | pages. | ||||
Hence a process with two distinct locked mappings of the same physical page | Hence two distinct locked mappings of the same physical page counts as | ||||
counts as 2 pages against the per-process limit and as only a single page | 2 pages aginst the system limit, and also against the per-process limit | ||||
in the system limit. | if both mappings belong to the same physical map. | ||||
.Pp | .Pp | ||||
The per-process resource limit is not currently supported. | The per-process resource limit is not currently supported. |