madvise(3c) 맨 페이지 - 윈디하나의 솔라나라

개요

섹션
맨 페이지 이름
검색(S)

madvise(3c)

madvise(3C)              Standard C Library Functions              madvise(3C)

NAME
       madvise - provide advice to VM system

SYNOPSIS
       #include <sys/types.h>
       #include <sys/mman.h>

       int madvise(void *addr, size_t len, int advice);

DESCRIPTION
       The  madvise() function advises the kernel that a region of user mapped
       memory in the range [addr, addr + len) will  be  accessed  following  a
       type  of pattern. The kernel uses this information to optimize the pro‐
       cedure for manipulating and maintaining the resources  associated  with
       the specified mapping range.


       Values for advice are defined in <sys/mman.h> as:

         #define MADV_NORMAL           0  /* No further special treatment */
         #define MADV_RANDOM           1  /* Expect random page references */
         #define MADV_SEQUENTIAL       2  /* Expect sequential page references */
         #define MADV_WILLNEED         3  /* Will need these pages */
         #define MADV_DONTNEED         4  /* Don't need these pages */
         #define MADV_FREE             5  /* Contents can be freed */
         #define MADV_ACCESS_DEFAULT   6  /* default access */
         #define MADV_ACCESS_LWP       7  /* next LWP to access heavily */
         #define MADV_ACCESS_MANY      8  /* many processes to access heavily */
         #define MADV_ACCESS_MANY_PSET 9  /* many processes in pset to access */
                                          /* heavily */
         #define MADV_DONTDUMP        10  /* exclude from process core dump */
         #define MADV_DODUMP          11  /* include in process core dump */


       MADV_NORMAL

           This  is  the  default system characteristic where accessing memory
           within the address range causes the system to read  data  from  the
           mapped  file. The kernel reads all data from files into pages which
           are retained for a period of time as a "cache." System pages can be
           a scarce resource, so the kernel steals pages from  other  mappings
           when  needed.  This  is  a likely occurrence, but adversely affects
           system performance only if a large amount of memory is accessed.


       MADV_RANDOM

           Tell the kernel to read in a minimum amount of data from  a  mapped
           file  on  any single particular access. If MADV_NORMAL is in effect
           when an address of a mapped file is accessed, the system  tries  to
           read  in  as much data from the file as reasonable, in anticipation
           of other accesses within a certain locality.


       MADV_SEQUENTIAL

           Tell the system that addresses in this range are likely to  be  ac‐
           cessed only once, so the system will free the resources mapping the
           address range as quickly as possible.


       MADV_WILLNEED

           Tell  the  system that a certain address range is definitely needed
           so the kernel will start reading the specified range  into  memory.
           This  can  benefit  programs wanting to minimize the time needed to
           access memory the first time, as the kernel would need to  read  in
           from the file.


       MADV_DONTNEED

           Tell  the  kernel  that  the  specified  address range is no longer
           needed, so the system starts to free the resources associated  with
           the address range.

           MADV_DONTNEED  and  MADV_FREE  perform  related but distinct opera‐
           tions. MADV_DONTNEED tries to move any data from the specified  ad‐
           dress range out of memory, but it ensures that the contents of that
           range  will  be  recovered when they are next referenced. MADV_FREE
           does not attempt to preserve the contents of the address range.  As
           a  result,  subsequent references to an address range that received
           madvise (MADV_DONTNEED) are likely to be slower than references  to
           a range that received madvise (MADV_FREE).


       MADV_FREE

           Tell the kernel that contents in the specified address range are no
           longer  important  and the range will be overwritten. When there is
           demand for memory, the system will free pages associated  with  the
           specified  address range. In this instance, the next time a page in
           the address range is referenced, it will contain all zeroes. Other‐
           wise, it will  contain  the  data  that  was  there  prior  to  the
           MADV_FREE  call. References made to the address range will not make
           the system read from backing store (swap space) until the  page  is
           modified again.

           This value cannot be used on mappings that have underlying file ob‐
           jects.


       MADV_DONTDUMP

           Exclude  the  specified  address  range  from  the  coredump of the
           process. This is an alias of the memcntl MC_CORE_PRUNE_OUT command.


       MADV_DODUMP

           Include the specified address range in a coredump of  the  process.
           This is an alias of the memcntl MC_CORE_PRUNE_IN command.


       MADV_ACCESS_LWP

           Tell  the  kernel  that the next LWP to touch the specified address
           range will access it most heavily, so the kernel should try to  al‐
           locate  the  memory  and other resources for this range and the LWP
           accordingly.


       MADV_ACCESS_MANY

           Tell the kernel that many processes and/or  LWPs  will  access  the
           specified  address range randomly across the machine, so the kernel
           should try to allocate the memory  and  other  resources  for  this
           range accordingly.


       MADV_ACCESS_DEFAULT

           Reset  the kernel's expectation for how the specified range will be
           accessed to the default.


       MADV_ACCESS_MANY_PSET

           Tell the kernel that many processes and/or LWPs in a processor  set
           will  access  the  specified  address range randomly, so the kernel
           should try to allocate the memory  and  other  resources  for  this
           range accordingly.



       The  madvise()  function  should  be used by applications with specific
       knowledge of their access patterns over a  memory  object,  such  as  a
       mapped file, to increase system performance.


       When  applied  to  shared memory segments created by shmget_osm(2), the
       MADV_ACCESS_LWP, MADV_ACCESS_MANY,  MADV_ACCESS_DEFAULT,  and  MADV_AC‐
       CESS_MANY_PSET  options  affect  whole  granules, and only work through
       non-readonly mappings. The other madvise operations have no  effect  on
       shared memory segments created by shmget_osm(2).

RETURN VALUES
       Upon  successful completion, madvise() returns 0; otherwise, it returns
       −1 and sets errno to indicate the error.

ERRORS
       EAGAIN    Some or all mappings in the address range [addr, addr +  len)
                 are locked for I/O.


       EACCES    A  MADV_ACCESS_* operation targets a range [addr, addr + len)
                 which  includes  a   shmget_osm(2)   created   segment   with
                 SHM_RDONLY.


       EBUSY     Some  or all of the addresses in the range [addr, addr + len)
                 are locked and MS_SYNC with the MS_INVALIDATE option is spec‐
                 ified.


       EFAULT    Some or all of the addresses in the specified range could not
                 be read into memory from the underlying object when  perform‐
                 ing  MADV_WILLNEED. The madvise() function could return prior
                 to this condition being detected, in which  case  errno  will
                 not be set to EFAULT.


       EINVAL    The  addr  argument is not a multiple of the page size as re‐
                 turned by sysconf(3C), the length of  the  specified  address
                 range is equal to 0, or the advice argument was invalid.

                 The  range  described  by addr and len span part of a segment
                 created by  shmget_osm(2),  and  the  spanned  range  is  not
                 aligned to that segment's granule size.


       EIO       An  I/O  error  occurred while reading from or writing to the
                 file system.


       ENOMEM    Addresses in the range [addr, addr +  len)  are  outside  the
                 valid  range  for  the address space of a process, or specify
                 one or more pages that are not mapped.


       ESTALE    Stale NFS file handle.


ATTRIBUTES
       See attributes(7) for descriptions of the following attributes:

       tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) ATTRIBUTE  TYPEAT‐
       TRIBUTE  VALUE _ Interface StabilityCommitted _ MT-LevelMT-Safe _ Stan‐
       dardSee below.



       The madvise() function is not specified by the POSIX and  X/Open  stan‐
       dards.  Instead  these standards have defined posix_madvise(3C) to pro‐
       vide a standardized version of this functionality.

SEE ALSO
       madv.so.1(1),    pmadvise(1),    meminfo(2),    memcntl(2),    mmap(2),
       shmget_osm(2), posix_madvise(3C), sysconf(3C), attributes(7)

HISTORY
       The madvise() function has been included in all Sun and Oracle releases
       of Solaris.


       Definitions  for  the  following advice values are available in Solaris
       starting with the listed release:

       tab() box; cw(3.67i) |cw(1.83i) lw(3.67i)  |lw(1.83i)  ADVICERELEASE  _
       MADV_DODUMP,  MADV_DONTDUMP11.4.12  _  MADV_ACCESS_MANY_PSET11.0.0 _ T{
       MADV_ACCESS_DEFAULT, MADV_ACCESS_LWP, MADV_ACCESS_MANY T}9  12/02  (Up‐
       date  2)  _  MADV_FREE8 _ T{ MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL,
       MADV_WILLNEED, MADV_DONTNEED T}1.0


Oracle Solaris 11.4               27 Aug 2025                      madvise(3C)
맨 페이지 내용의 저작권은 맨 페이지 작성자에게 있습니다.
RSS ATOM XHTML 5 CSS3