niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Unix internals
mmap question
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
dinakar.dhurjati@gmail.co
*nix forums beginner


Joined: 02 Dec 2005
Posts: 4

PostPosted: Fri Dec 02, 2005 8:10 pm    Post subject: mmap question Reply with quote

[I posted this on unix.solaris as well, but thought people here might
know]
Hello,

I have a question on using mmap on Solaris. Any help is appreciated.

Is there a way to map multiple virtual pages to the same physical page
with in a process?

I need this capability for a research project of mine. I know how to do
this in Linux, courtesy http://lkml.org/lkml/2004/1/10/226 , but it
uses mremap, which is not
available on Solaris. Does there exist anything similar on Solaris and
other unices?

I do know how to get the same effect by mmapping an existing file at
the same offset multiple times, but I really don't want to have any
backing store for the mmap. I want to be able to do MAP_ANON and
then have it also map to a different virutal page. Any pointers?

Thanks
Dinakar
Back to top
Frank Cusack
*nix forums Guru Wannabe


Joined: 02 Mar 2005
Posts: 215

PostPosted: Fri Dec 02, 2005 9:52 pm    Post subject: Re: mmap question Reply with quote

On 2 Dec 2005 12:10:57 -0800 dinakar.dhurjati@gmail.com wrote:
Quote:
I do know how to get the same effect by mmapping an existing file at
the same offset multiple times, but I really don't want to have any
backing store for the mmap.

How about mapping /dev/zero?
-frank
Back to top
dinakar.dhurjati@gmail.co
*nix forums beginner


Joined: 02 Dec 2005
Posts: 4

PostPosted: Fri Dec 02, 2005 10:27 pm    Post subject: Re: mmap question Reply with quote

Tried it but it returns two differnt physical pages even when I use the
same offset in the file.

e.g. the following program returns 6 and 5 (while I want 6 and 6 ).
---------------------------------------code--------------------------------------------
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
main() {
unsigned PageSize = sysconf(_SC_PAGESIZE);
int sd;
void *pa2, *pa3, *pa;
sd = open("/dev/zero",O_CREAT|O_RDWR);
pa = mmap(0, PageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sd, 0);
*(char *)pa = 5;
pa3 = mmap(0, PageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sd, 0);
*(char *)pa3 = 6;
printf("%d \n",*(char *)pa3);
printf("%d \n",*(char *)pa);
}
--------------------------------------------------------------------------------------------
Thanks
Dinakar
Back to top
Frank Cusack
*nix forums Guru Wannabe


Joined: 02 Mar 2005
Posts: 215

PostPosted: Tue Dec 06, 2005 1:08 am    Post subject: Re: mmap question Reply with quote

Probably because of MAP_PRIVATE?

On 2 Dec 2005 14:27:16 -0800 dinakar.dhurjati@gmail.com wrote:
Quote:
Tried it but it returns two differnt physical pages even when I use the
same offset in the file.

e.g. the following program returns 6 and 5 (while I want 6 and 6 ).
---------------------------------------code--------------------------------------------
#include <sys/mman.h
#include <sys/types.h
#include <sys/stat.h
#include <fcntl.h
#include <unistd.h
#include <sys/ipc.h
#include <sys/shm.h
main() {
unsigned PageSize = sysconf(_SC_PAGESIZE);
int sd;
void *pa2, *pa3, *pa;
sd = open("/dev/zero",O_CREAT|O_RDWR);
pa = mmap(0, PageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sd, 0);
*(char *)pa = 5;
pa3 = mmap(0, PageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE, sd, 0);
*(char *)pa3 = 6;
printf("%d \n",*(char *)pa3);
printf("%d \n",*(char *)pa);
}
--------------------------------------------------------------------------------------------
Thanks
Dinakar
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Tue Dec 02, 2008 7:09 pm | All times are GMT
navigation Forum index » Programming » Unix internals
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts Linux2.6 mmap problem, pls help me seven_007 python 1 Sat Sep 30, 2006 3:10 am
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am

Bad Credit Mortgages | Loans | Credit Cards | Free mobile phone's stuffs | Mortgage Calculator
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1978s ][ Queries: 16 (0.1236s) ][ GZIP on - Debug on ]