Today's Posts

Discuss NAS, SAN, RAID, Robotic Libraries, backup devices, RAM, DRAM, SCSI, IDE, EIDE topics here.

How does memory mapping work?


Login to Reply

Thread Tools Search this Thread
# 1  
Old 04-26-2011
How does memory mapping work?

I can't find a guide or tutorial that explains it at all. Its there a better search term than Memory Mapping? What's the magic inbetween having the hard drive behave like the memory?
# 2  
Old 04-26-2011
The best 'guide' is man mmap and some experimentation.

The "magic" is virtual memory. If you don't understand that yet, you'll need to. the paging game is a pretty good starter, I think.

How it works, hardware-wise, is the CPU keeps a big table of what addresses are assigned to what processes, and what real memory -- if any -- is assigned to that address. The OS can configure it on the fly. A page can be marked as 'unavailable', meaning, potentially valid but not yet read in or assigned actual memory. If a process accesses it, the CPU signals the OS which freezes that process. It checks and finds that the page isn't marked as 'ready' in the table, and that by its own (separate) records, ought to be a chunk of bigfile.txt. The OS finds an empty page, reads the right chunk into it, marks it belonging to the process, and wakes it up, which tries to read again and this time succeeds with no delay.

IOW, the CPU can mark memory in such a way as to freeze a process when it tries to use it. The OS is told when this happens, so it can do something to the memory, then revive it when ready, making a convincing illusion of the file existing in contiguous memory.

Last edited by Corona688; 04-26-2011 at 01:46 AM..
The Following 2 Users Say Thank You to Corona688 For This Useful Post:
theKbStockpiler (04-26-2011), usha rao (04-26-2011)
# 3  
Old 04-26-2011
Can anyone expand on the info contained in this link?

File Mapping - ????, ????! - CSDN??

Or this link?http://www.ifm-services.com/people/j...orymapping.php

Last edited by theKbStockpiler; 04-26-2011 at 02:37 AM..
# 4  
Old 04-26-2011
One of those refuses to load, and the other is in some odd computing language I've never seen before.

How about this?

To start you off:

char *mem;
int fd=open("filename", O_RDWR|O_CREAT, 0666); // Create the file
ftruncate(fd, getpagesize()); // Extend it to the length of the page size, probably 4K

// Map the file(MAP_SHARED) into memory with read and write permissions, at any available address(i.e. NULL)
mem=mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0L);
if(mem == MAP_FAILED) // Failure doesnot mean null!
        perror("Couldn't mmap");

// Fill file with Z's
memset(mem, 'Z', getpagesize());

The Following User Says Thank You to Corona688 For This Useful Post:
theKbStockpiler (04-26-2011)
# 5  
Old 04-27-2011
Some links I believe that should be shared.

Thank you Corona688 for the replies!

Memory Mapped Files | Vladislav Online


Memory Mapped Files Abdelrahman Al-Ogail's Blog

UNIX Tips - Memory Management
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Mapping Oracle SGA memory into physical files in Solaris. arjun_chauhan UNIX for Advanced & Expert Users 1 11-30-2016 10:12 AM
Discussion at work, would a router work pluging a cable in wan1 and lan1? broli IP Networking 9 07-23-2014 06:32 PM
My script work on Linux but not work in sunos. ooilinlove Shell Programming and Scripting 7 01-30-2013 07:27 AM
[DOUBT] Memory high in idle process on Solaris 10 (Memory Utilization > 90%) edydsuranta Solaris 4 10-01-2012 06:11 PM
Creating unique mapping from multiple mapping gimley Shell Programming and Scripting 5 06-28-2012 02:41 AM
How to find Total and Free Physical Memory and Logical Memory in SOLARIS 9 0ktalmagik Solaris 4 02-03-2009 09:37 AM
lvm_queryvg call does not work properly and results in a sudden memory rise. sandiworld AIX 0 11-15-2007 01:57 AM
C code for implementation of Memory Mapping raviviolet13 Programming 1 09-13-2007 02:56 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM
Shared memory shortage but lots of unused memory cjcamaro UNIX for Advanced & Expert Users 1 10-13-2004 06:10 PM

All times are GMT -4. The time now is 10:04 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
Show Password