2021-02-02 05:30:46 +00:00
|
|
|
.\" Copyright (C) 2021 Suren Baghdasaryan <surenb@google.com>
|
|
|
|
.\" and Copyright (C) 2021 Minchan Kim <minchan@kernel.org>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
|
|
.\" permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
|
|
.\" have taken the same level of care in the production of this manual,
|
|
|
|
.\" which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
|
|
|
.\" Commit ecb8ac8b1f146915aa6b96449b66dd48984caacc
|
|
|
|
.\"
|
|
|
|
.TH PROCESS_MADVISE 2 2021-01-12 "Linux" "Linux Programmer's Manual"
|
|
|
|
.SH NAME
|
|
|
|
process_madvise \- give advice about use of memory to a process
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <sys/uio.h>
|
|
|
|
.PP
|
2021-02-02 10:11:39 +00:00
|
|
|
.BI "ssize_t process_madvise(int " pidfd ", const struct iovec *" iovec ,
|
process_madvise.2: SYNOPSIS: Fix prototype parameter type
The type of vlen is 'size_t', and not 'unsigned int'. Fix it.
......
$ grep_syscall process_madvise
mm/madvise.c:1161:
SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
size_t, vlen, int, behavior, unsigned int, flags)
include/linux/syscalls.h:887:
asmlinkage long sys_process_madvise(int pidfd, const struct iovec __user *vec,
size_t vlen, int behavior, unsigned int flags);
function grep_syscall()
{
if ! [ -v 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
return ${EX_USAGE};
fi
find * -type f \
|grep '\.c$' \
|sort -V \
|xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1},.*?\)" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
find * -type f \
|grep '\.[ch]$' \
|sort -V \
|xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
}
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2021-02-11 17:44:57 +00:00
|
|
|
.BI " size_t " vlen ", int " advice ,
|
2021-02-02 10:11:39 +00:00
|
|
|
.BI " unsigned int " flags ");"
|
2021-02-02 05:30:46 +00:00
|
|
|
.fi
|
2021-02-11 17:44:55 +00:00
|
|
|
.PP
|
|
|
|
.IR Note :
|
|
|
|
There is no glibc wrapper for this system call; see NOTES.
|
|
|
|
.\" FIXME: See <https://sourceware.org/bugzilla/show_bug.cgi?id=27380>
|
2021-02-02 05:30:46 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
|
|
|
.BR process_madvise()
|
|
|
|
system call is used to give advice or directions to the kernel about the
|
2021-02-02 10:11:39 +00:00
|
|
|
address ranges of another process or of the calling process.
|
|
|
|
It provides the advice for the address ranges described by
|
2021-02-02 05:30:46 +00:00
|
|
|
.I iovec
|
|
|
|
and
|
|
|
|
.IR vlen .
|
|
|
|
The goal of such advice is to improve system or application performance.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I pidfd
|
|
|
|
argument is a PID file descriptor (see
|
|
|
|
.BR pidfd_open (2))
|
|
|
|
that specifies the process to which the advice is to be applied.
|
|
|
|
.PP
|
|
|
|
The pointer
|
|
|
|
.I iovec
|
|
|
|
points to an array of
|
|
|
|
.I iovec
|
|
|
|
structures, defined in
|
|
|
|
.IR <sys/uio.h>
|
|
|
|
as:
|
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.EX
|
|
|
|
struct iovec {
|
|
|
|
void *iov_base; /* Starting address */
|
2021-02-02 10:11:39 +00:00
|
|
|
size_t iov_len; /* Length of region */
|
2021-02-02 05:30:46 +00:00
|
|
|
};
|
|
|
|
.EE
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I iovec
|
|
|
|
structure describes address ranges beginning at
|
|
|
|
.I iov_base
|
|
|
|
address and with the size of
|
|
|
|
.I iov_len
|
|
|
|
bytes.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I vlen
|
2021-02-02 10:11:39 +00:00
|
|
|
specifies the number of elements in the
|
2021-02-02 05:30:46 +00:00
|
|
|
.I iovec
|
|
|
|
structure.
|
2021-02-02 10:38:46 +00:00
|
|
|
This value must be less than or equal to
|
|
|
|
.BR IOV_MAX
|
|
|
|
(defined in
|
|
|
|
.I <limits.h>
|
|
|
|
or accessible via the call
|
|
|
|
.IR sysconf(_SC_IOV_MAX) ).
|
2021-02-02 05:30:46 +00:00
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I advice
|
2021-02-13 21:40:11 +00:00
|
|
|
argument is one of the following values:
|
|
|
|
.TP
|
|
|
|
.BR MADV_COLD
|
|
|
|
See
|
|
|
|
.BR madvise (2).
|
|
|
|
.TP
|
|
|
|
.BR MADV_PAGEOUT
|
|
|
|
See
|
|
|
|
.BR madvise (2).
|
2021-02-02 05:30:46 +00:00
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I flags
|
|
|
|
argument is reserved for future use; currently, this argument must be
|
|
|
|
specified as 0.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I vlen
|
|
|
|
and
|
|
|
|
.I iovec
|
2021-02-13 21:54:00 +00:00
|
|
|
arguments are checked before applying any advice.
|
2021-02-13 21:48:37 +00:00
|
|
|
If
|
2021-02-02 05:30:46 +00:00
|
|
|
.I vlen
|
|
|
|
is too big, or
|
|
|
|
.I iovec
|
|
|
|
is invalid,
|
2021-02-02 10:11:39 +00:00
|
|
|
then an error will be returned immediately and no advice will be applied.
|
2021-02-02 05:30:46 +00:00
|
|
|
.PP
|
2021-02-13 21:54:00 +00:00
|
|
|
The advice might be applied to only a part of
|
2021-02-02 05:30:46 +00:00
|
|
|
.I iovec
|
|
|
|
if one of its elements points to an invalid memory region in the
|
|
|
|
remote process.
|
|
|
|
No further elements will be processed beyond that point.
|
2021-02-13 20:10:04 +00:00
|
|
|
(See the discussion regarding partial advice in RETURN VALUE.)
|
2021-02-02 05:30:46 +00:00
|
|
|
.PP
|
2021-02-13 21:54:00 +00:00
|
|
|
Permission to apply advice to another process is governed by a
|
2021-02-02 05:30:46 +00:00
|
|
|
ptrace access mode
|
|
|
|
.B PTRACE_MODE_READ_REALCREDS
|
|
|
|
check (see
|
|
|
|
.BR ptrace (2));
|
2021-02-02 10:11:39 +00:00
|
|
|
in addition,
|
2021-02-13 21:54:00 +00:00
|
|
|
because of the performance implications of applying the advice,
|
2021-02-02 10:11:39 +00:00
|
|
|
the caller must have the
|
2021-02-02 05:30:46 +00:00
|
|
|
.B CAP_SYS_ADMIN
|
2021-02-02 10:11:39 +00:00
|
|
|
capability.
|
2021-02-02 05:30:46 +00:00
|
|
|
.SH RETURN VALUE
|
2021-02-02 10:11:39 +00:00
|
|
|
On success,
|
|
|
|
.BR process_madvise ()
|
|
|
|
returns the number of bytes advised.
|
2021-02-02 05:30:46 +00:00
|
|
|
This return value may be less than the total number of requested bytes,
|
2021-02-02 10:11:39 +00:00
|
|
|
if an error occurred after some
|
|
|
|
.I iovec
|
|
|
|
elements were already processed.
|
2021-02-02 05:30:46 +00:00
|
|
|
The caller should check the return value to determine whether a partial
|
|
|
|
advice occurred.
|
|
|
|
.PP
|
|
|
|
On error, \-1 is returned and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
.I pidfd
|
|
|
|
is not a valid PID file descriptor.
|
|
|
|
.TP
|
|
|
|
.B EFAULT
|
|
|
|
The memory described by
|
|
|
|
.I iovec
|
|
|
|
is outside the accessible address space of the process referred to by
|
|
|
|
.IR pidfd .
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I flags
|
|
|
|
is not 0.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
The sum of the
|
|
|
|
.I iov_len
|
|
|
|
values of
|
|
|
|
.I iovec
|
|
|
|
overflows a
|
|
|
|
.I ssize_t
|
|
|
|
value.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
.I vlen
|
|
|
|
is too large.
|
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
|
|
|
Could not allocate memory for internal copies of the
|
|
|
|
.I iovec
|
|
|
|
structures.
|
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
The caller does not have permission to access the address space of the process
|
|
|
|
.IR pidfd .
|
|
|
|
.TP
|
|
|
|
.B ESRCH
|
|
|
|
The target process does not exist (i.e., it has terminated and been waited on).
|
|
|
|
.SH VERSIONS
|
|
|
|
This system call first appeared in Linux 5.10.
|
|
|
|
.\" commit ecb8ac8b1f146915aa6b96449b66dd48984caacc
|
|
|
|
Support for this system call is optional,
|
|
|
|
depending on the setting of the
|
|
|
|
.B CONFIG_ADVISE_SYSCALLS
|
|
|
|
configuration option.
|
2021-02-11 17:44:55 +00:00
|
|
|
.SH NOTES
|
|
|
|
Glibc does not provide a wrapper for this system call; call it using
|
|
|
|
.BR syscall (2).
|
2021-02-02 05:30:46 +00:00
|
|
|
.SH SEE ALSO
|
|
|
|
.BR madvise (2),
|
2021-02-02 10:11:39 +00:00
|
|
|
.BR pidfd_open (2),
|
2021-02-02 05:30:46 +00:00
|
|
|
.BR process_vm_readv (2),
|
|
|
|
.BR process_vm_write (2)
|