Why still no mmap ( MAP_ANON | MAP_SHARED ) allowed 2.2.14+?

From: Mike S. (mikes1987@yahoo.com)
Date: Sat Jun 24 2000 - 06:14:06 EST


 Hi folks,

Could somebody tell me what the status is on getting mmap to work
with both MAP_ANON and MAP_SHARED at the same time? This doesn't seem
to work even on my recent 2.2-14 kernel (and a reading of mmap.c
confirmed this). Every other major UNIX supports this, why not our
beloved Tux?
It seems to me that this is THE way to have a parent share large
amounts
of data with several children that just need to read/search through it.
The Linux System V shared memory implementation is relatively generous
with a shmmax of about 33MB, you can crank it up to 135MB or so - if I
read shm.h correctly, but that is THE limit for i386's.

  What about folks that need share say 300MB or so, like from a
large database query result, that many children search through for
their particular subsets? Speed is of extreme importance - no disk
I/O - all accesses via RAM. Linux should have an easy, quick, and
high performance way of doing this. I think POSIX shared memory
via shm_open is in the works, but I think that is filesystem (tmpfs)
based and is better for "unrelated" processes as they can grab on via
the file "name".

 Thanks in advance for any insights or advice,

 Mike Shell

PS:
Below are posts I found from 1997 where this subject was mentioned.
What bothers me is the last line "all the pieces are there, just
some glue code is required."

begin reposts:
*************
first post:
http://uwsg.ucs.indiana.edu/hypermail/linux/kernel/9709.2/0350.html

Andrew Pollard (andrewp@autosim.demon.co.uk)
Fri, 19 Sep 1997 12:27:38 +0100

Hello,

I wonder if anyone can tell me whether Linux (2.0.31pre9 and 2.1.55)
should handle mmap with MAP_ANON|MAP_SHARED as an argument?

The source in mm/mmap.c has a check (if -1 as a file handle is given):

if ((flags & MAP_TYPE) != MAP_PRIVATE)
return -EINVAL;

thus, it disallows MAP_ANON|MAP_SHARED.

Is this the correct behaviour?

I wanted to use an anonymous mmap with MAP_SHARED to share memory
between a parent and a child process. The copy of "Advanced
Programming in the UNIX Environment - W. Richard Stevens" says that
(from 4.3BSD) that you can do

mmap(0, SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0)

to do this.

It also mentions that you can mmap in /dev/zero with MAP_SHARED to do
it under SVR4 type machines (eg solaris2)

In this respect is Linux BSD based or SVR4 based?

Neither seem to work under linux-2.0.31pre9.

Any ideas?

Andrew.

--
 Andrew Pollard, Auto Simulations Ltd. UK.  | work: andrewp@autosim.com
 2 Milbanke Court, Milbanke Way, Bracknell  | home:
andrew@odie.demon.co.uk
Tel:+44(0)1344 426486 Fax:+44(0)1344 426615 |
http://www.odie.demon.co.uk

******** second post: http://uwsg.ucs.indiana.edu/hypermail/linux/kernel/9709.2/0363.html

Peter Belsanti (pbelsant@algorithmics.com) Fri, 19 Sep 1997 10:44:04 -0400

Messages sorted by: [ date ][ thread ][ subject ][ author ] Next message: David Woodhouse: "Re: And in today's snapshot..." Previous message: Thomas Koenig: "p10.gz in ~linux/testing ?" Maybe in reply to: Andrew Pollard: "mmap & MAP_ANON/MAP_PRIVATE/MAP_SHARED" Next in thread: Gerd Knorr: "Re: mmap & MAP_ANON/MAP_PRIVATE/MAP_SHARED" Reply: Gerd Knorr: "Re: mmap & MAP_ANON/MAP_PRIVATE/MAP_SHARED"

Andrew Pollard wrote: > > Hello, > > I wonder if anyone can tell me whether Linux (2.0.31pre9 and 2.1.55) > should handle mmap with MAP_ANON|MAP_SHARED as an argument?

I'm interested in the EXACT SAME THING!! This beats the pants out of shmget() since anonymous memory gets cleaned up automatically after coring! (I know, apps are NOT supposed to core dump, but this isn't a perfect world and some ayaadmin's don't both checking servr conditions regularily!)

My old posting was:

> We have a piece of code that looks something like this: > > int *mapped; > > if ((mapped = (int*)mmap((caddr_t)0, 1024, > PROT_READ | PROT_WRITE, > MAP_SHARED | MAP_ANONYMOUS, > -1, 0)) == -1) { > perror("mmap"); > exit(2); > } > > This ALWAYS fails and returns 0xffffff no matter what I try! I've > tried in all kernels up to 2.0.31-pre7. From the man pages, mmap() > should be able to accept MAP_ANONYMOUS but this just doesn't work. > Has anyone got this type of mmap() call to work in their code? Is > this feature supported in mmap()? Am I crazy? HELP!!!!!!

The response I got:

> Date: Thu, 28 Aug 1997 11:57:09 +0000 ( ) > From: Benjamin C R LaHaise <blah@dot.superaje.com> > > This isn't implemented yet and won't be for 2.0.... Hopefully it will > be for 2.2, but don't expect it too soon.

...and...

> Date: Thu, 28 Aug 1997 07:59:34 -0400 (EDT) > From: Jim Nance <jlnance@avanticorp.com> > > This used NOT to work. I have not heard about any changes. You can > make something that looks like it work with: > > fd=open("/tmp/myfile", O_RDWR|O_CREAT); > unlink("/tmp/myfile"); > ftruncate(fd, size); > ptr=mmap(0,???,MAP_SHARED,fd,??); > close(fd); > > Jim

I too wait with baited breath for this feature to be put in!

NOTE: 1. If you are intereested in making your code portable, you should know that different platforms implement this feature in different ways. Some use the "-1" for a file descriptor, others mmap() /dev/zero for their memory. ALL O/S I've played with have this feature EXCEPT FOR LINUX! This includes SunOS, Solaris, AIX, OSF/1 and HPUX.

2. Linux already has MAP_ANONYMOUS as long as there is a file descriptor, and MAP_SHARED as long as you don't declare MAP_ANONYMOUS, just not both! (All the pieces are there, just some glue code is required.)

*************** ***************

__________________________________________________ Do You Yahoo!? Get Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jun 26 2000 - 21:00:04 EST