Linux mremap features

On Linux, the mremap function is used to reassign memory that has been mapped using mmap. please help me clarify the following:

  • If the mremap function failed, what is the status of the old mapped memory?
  • If the mremap function failed, is there a need to call the munmap function?
  • If the mremap function succeeds, is there any previous data in the reassigned memory?
+2
source share
1 answer

mremap tries to increase the selection in place, but returns to distributing the new region if it cannot increase the size of the current region.

mremap () extends (or shrinks) the existing memory mapping, potentially moving it at the same time (controlled by the flags argument and the available virtual address space). src

  • If mremap fails, the old memory is just fine (like realloc).

  • If mremap fails, there is nothing munmap (from this call, at least). See paragraph 1.

  • If mremap succeeds and needs to move, the old memory is copied to the new one (and the old munmap is for you). If mremap is able to increase the size in place, the memory does not move and a new location is not created.

+1
source

Source: https://habr.com/ru/post/1259207/


All Articles