👤
Home Man
Search
Today's Posts
Register

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 12: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 01: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:

Code:
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");
        return(1);
}

// 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

Loading…

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 09:12 AM
Discussion at work, would a router work pluging a cable in wan1 and lan1? broli IP Networking 9 07-23-2014 05:32 PM
My script work on Linux but not work in sunos. ooilinlove Shell Programming and Scripting 7 01-30-2013 06:27 AM
[DOUBT] Memory high in idle process on Solaris 10 (Memory Utilization > 90%) edydsuranta Solaris 4 10-01-2012 05:11 PM
Creating unique mapping from multiple mapping gimley Shell Programming and Scripting 5 06-28-2012 01:41 AM
restrcit physical memory with zone.max-locked-memory fugitive Solaris 1 10-28-2009 01:37 PM
How to find Total and Free Physical Memory and Logical Memory in SOLARIS 9 0ktalmagik Solaris 4 02-03-2009 08:37 AM
lvm_queryvg call does not work properly and results in a sudden memory rise. sandiworld AIX 0 11-15-2007 12:57 AM
C code for implementation of Memory Mapping raviviolet13 Programming 1 09-13-2007 01:56 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 09:52 PM


All times are GMT -4. The time now is 09:36 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password