Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
What is an MMAP system Call? Does this avoid any overhead to the system ? Will this be possible in no-MMU system ? please provide your inputs,i am confused....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2007
    Posts
    2

    Post MMAP usage


    What is an MMAP system Call? Does this avoid any overhead to the system ?
    Will this be possible in no-MMU system ?

    please provide your inputs,i am confused.

  2. #2
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    30

    mmap

    The mmap interface is normally used to map a file into memory so that then you can read and/or write the data in the file by accessing memory - no need for file I/O directly. This uses paging interrupts. When you access a page for the first time, it cases a page fault and it reads in that page from your file. If you intend to access the whole file, it may make more sense to read it into memory rather than use mmap. You gain with mmap if you may make sparse accesses into the data. Another advantage of mmap is that multiple processes can share the same data when they all map the same file into their address space. This is similar to shared memory in that respect.

    One other use of mmap is to obtain memory (kind of a substitute for malloc) in which you open and map the special file /dev/zeros.

    I hope this helps.

  3. #3
    Just Joined!
    Join Date
    Sep 2008
    Posts
    8
    Quote Originally Posted by kanagarajan View Post
    What is an MMAP system Call? Does this avoid any overhead to the system ?
    Will this be possible in no-MMU system ?

    please provide your inputs,i am confused.
    Im not clear about the first parameter (void * address) of mmap.What does it means that address gives a preferred starting address for the mapping.Does it means that mmap map thr region to the location pointed by address?And what is use of flag MAP_FIXED?

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Sep 2008
    Posts
    8
    Suppose I have a file just.txt with containts ABCDEFGH and I mmaped it.mmap gives me a pointer that point to starting of this file just.txt i.e. to A.Should I use that pointer as pointer to array of character or not ? If yes then what happen if Im modifying the file by incrementing that pointer by 2 and it pointing to C,I want to store the changes to file.I have used munmap but it not changes the file,because next time when I mmap the same file it reads from A nto from C.
    Another is what happen if I provide a void pointer as first argument to mmap instead of NULL?

  6. #5
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    30

    Questions on use of mmap()

    The first parameter to mmap is a pointer you provide. If it is zero/NULL, mmap gets its own area of memory to use and you gain access to this memory sort of like using malloc() except it comes already filled in with the data from your file (or all zeros if you map the file /dev/zero). If you get your own storage (say via malloc() ), you can use that and mmap will try to map your file there - just be aware that memory maps must start on full page boundaries and will extend to a full page boundary. I think on Linux pages are always 4096 (4K) bytes, but on Solaris you can find 8192 (8K) page sizes. If mmap cannot fit your mapped data into the memory area your pointer points to, it disregards it and finds its own free area within the process address space that is large enough to hold all the data being mapped.

    If mmap() obtains the chunk of memory for you, it is freed when you munmap it and you will get a memory fault if you try to access it after it is unmapped. If you provided the memory for the mapping, it is still available for you to use after you munmap it.

    I hope this helps.

  7. #6
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    30
    My memory is failing me. Don't pass in an address that you obtained via malloc (unless you have also freed it). I believe the address you pass into the mmap() function should be for an address that is not already in use within your processes' address space. Note that this is a recommended address for mmap to use unless you also specify MAP_FIXED in the flag parameter. In my experience, I have only specified a non-NULL pointer for the addr (first) parameter when I have previously gotten that address from mmap() and have subsequentily unmapped that region. If you have some other means of knowing your specified address and full range is not in use, then you may be able to get mmap to use that address. If you specify an address to use and also MAP_FIXED, it may fail if there is not sufficient space before running into some block of memory already in use within your process address space. For 32-bit processes you need to be careful when trying to map large files - there may not be a sufficiently large contiguous unused block of address space in which to map the file.

    Brion

  8. #7
    Just Joined!
    Join Date
    Sep 2008
    Posts
    8
    Thanks bkeller for your va;uable help related to mmu.It really works.

  9. #8
    Just Joined!
    Join Date
    Sep 2008
    Posts
    8
    Quote Originally Posted by chetan.c.thorat View Post
    Thanks bkeller for your va;uable help related to mmu.It really works.
    What is the use of the function sysconf();.What is the meaning of parameter _SC_PAGE_SIZE in it

  10. #9
    Just Joined!
    Join Date
    Jun 2008
    Location
    North East U.S.
    Posts
    30
    The sysconf() function is used to see values for certain system configuration variables. For most systems, including linux, you can get the page size by calling getpagesize(). I used sysconf() to get page size only for HPUX because that system did not support the getpagesize() function (this was early 1990's). Note that memory mapping is always in integer multiples of page size.

  11. #10
    Just Joined!
    Join Date
    Sep 2008
    Posts
    8
    Quote Originally Posted by bkeller View Post
    The sysconf() function is used to see values for certain system configuration variables. For most systems, including linux, you can get the page size by calling getpagesize(). I used sysconf() to get page size only for HPUX because that system did not support the getpagesize() function (this was early 1990's). Note that memory mapping is always in integer multiples of page size.
    Im using msync() to flushes changes made in the file to the disk,but Im getting something wrong.First parameter of msync is the starting address from where we want to update ,second is length of that segment, third is flag.Now suppose I put a string say "abc" to this atarting address,only 'a' is going to update or written to disk.Why is so?

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •