Skip to contentSkip to conversation

Why don't we make mmap MAP_SHARED with /dev/zero possible?

DISCUSSION fxzhang 3 participants 4 messages Oct 26, 1999 Memory management

lore
Share & tools
lore

fxzhang

author
#0 lore raw

and find this:
/usr/src/linux/drivers/char/mem.c
static int mmap_zero(struct file * file, struct vm_area_struct * vma)

{
        if (vma->vm_flags & VM_SHARED)
                return -EINVAL;

I don't understand why people don't implement it.Yes,in the source,I find something like "the shared case is complex",Could someone tell me what's the difficulty?As it is a driver,I think it should not be too much to concern.At least I know in Solaris this works.
I want to implement it but know I am not competent now,I am just beginning digging it:).

Is there any good way to share memory between process at page granularity?That is,I can
share individual pages between them? Threads maybe a subtitue,but there are many things that I don't want to share.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#1 lore raw
Quoted 6 lines · fxzhang

and find this:
/usr/src/linux/drivers/char/mem.c static int mmap_zero(struct file *

file, struct vm_area_struct * vma) {
        if (vma->vm_flags & VM_SHARED)
                return -EINVAL;
Quoted 6 lines

I don't understand why people don't implement it.Yes,in the source,I find something like "the shared case is complex",Could someone tell me what's the difficulty?As it is a driver,I think it should not be too much to concern.At least I know in Solaris this works.
I want to implement it but know I am not competent now,I am just
beginning digging it:).

Yes I would like to see it also, but at least in 2.0 days it was really difficult/impossible.

Quoted 3 lines

Is there any good way to share memory between process at page
granularity?That is,I can share individual pages between them? Threads maybe a subtitue,but there are many things that I don't want to share.

Using SYSV shm with key IPC_PRIVATE gives you the same behaviour.

Greetings
Christoph
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#2 lore raw

Hi,

Quoted 2 lines · Christoph Rohland

Yes I would like to see it also, but at least in 2.0 days it was really difficult/impossible.

In 2.2 it is much easier --- I did most of the required work when making swap cache sharing persistant. Then the 2.2 codefreeze hit...

The first remaining problem is initialisation of demand-zero pages for shared vmas. You have to be able to ensure that when one process faults in a shared page for the first time, all other processes pick up the correct new page.

There are several ways you could do this. The SysV-shm mechanism would work, but it would be harder to garbage-collect all of the resources used by a page which is no longer shared. Normal demand-zero page instantiation would work provided that it was performed atomically over all the vmas concerned, which would require careful locking on 2.3 for SMP.

The only fly in the ointment is that 2.3's new bigmem code doesn't observe the swap cache rules so carefully, and shared pages can become separated. We'd have to make the swap cache capable of working properly on high memory pages.

The other thing still needing done is to make the swap cache work properly for writable pages --- there are still various places in the VM where we assume mapped swap cache pages are readonly.

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/

#3 lore raw
In reply to fxzhang

Hi,

Quoted 9 lines · fxzhang

static int mmap_zero(struct file * file, struct vm_area_struct * vma)

{
        if (vma->vm_flags & VM_SHARED)
                return -EINVAL;

I don't understand why people don't implement it.Yes,in the source,I find something like "the shared case is complex",Could someone tell me what's the difficulty?As it is a driver,I think it should not be too much to concern.

It is not a driver issue --- it is core to the VM. The VM cannot handle shared writable anonymous pages. We're not talking about mmap pages in this special case: we are talking about normal anonymous data pages.

Quoted 4 lines

Is there any good way to share memory between process at page
granularity?That is,I can share individual pages between them? Threads maybe a subtitue,but there are many things that I don't want to share.

SysV shared memory. "man shmget; man shmop; man shmctl"

--Stephen
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/