* shared memory
@ 2001-08-28 17:17 Tom Appermont
2001-08-29 3:37 ` Ralf Baechle
0 siblings, 1 reply; 11+ messages in thread
From: Tom Appermont @ 2001-08-28 17:17 UTC (permalink / raw)
To: linux-mips
[-- Attachment #1: Type: text/plain, Size: 910 bytes --]
Howdy,
Attached are two files (shmm.c and test.c). The first is a simple
implementation of a kernel module that allocates RAM for sharing
memory with a user space application. The second file implements
a simple test to verify that the shared buffer behaves as
expected, by writing something in shared memory and requesting
the module to check if what was written by the application is
also visible in kernel space.
While this works as expected on PC, it does not at all work as
expected on my mips platform (R5231): What is written in user
space is not immediately visible in kernel space. This is with
very recent kernel sources (2.4.8) but the same problem exists
with an older (2.4.5) kernel.
There have been a few mails about mmap() problems in the last
couple of months, but with very little interesting response. Is
this a known problem or am I stupidly overlooking something?
Greetz,
Tom
[-- Attachment #2: shmm.c --]
[-- Type: text/plain, Size: 2581 bytes --]
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/malloc.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <asm/system.h>
#include <asm/atomic.h>
#include <asm/uaccess.h>
static int major;
static volatile int* shb;
static unsigned int order;
static ssize_t
shmm_write(struct file* file, char* buffer, size_t length, loff_t *offset)
{
int i;
copy_from_user(&i, buffer, sizeof(int));
if (i != *shb) {
printk("counter = %d, *shb = %d\n", i, *shb);
}
return sizeof(int);
}
static inline pgprot_t pgprot_noncached(pgprot_t _prot)
{
#ifdef CONFIG_MIPS
unsigned long prot = pgprot_val(_prot);
prot = (prot & ~_CACHE_MASK) | _CACHE_UNCACHED;
return __pgprot(prot);
#endif
}
static struct page *
shmm_vm_nopage(struct vm_area_struct *vma,
unsigned long address,
int write_access)
{
unsigned long physical;
unsigned long offset;
struct page* pageptr;
if (address > vma->vm_end) return NOPAGE_SIGBUS;
offset = address - vma->vm_start;
physical = (unsigned long)shb + offset;
pageptr = virt_to_page(physical);
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
atomic_inc(&pageptr->count);
return pageptr;
}
struct vm_operations_struct shmm_vm_ops = {
nopage: shmm_vm_nopage
};
static int
shmm_mmap(struct file *file, struct vm_area_struct *vma)
{
unsigned long vsize = vma->vm_end - vma->vm_start;
unsigned long npages = vsize / PAGE_SIZE;
order = 0;
while ((1 << order) < npages) order++;
npages = 1 << order;
printk("npages requested = %d, order = %d\n", npages, order);
shb = (int*)__get_dma_pages(GFP_KERNEL, order);
if (0 == shb) {
return -ENOMEM;
}
memset(shb,0,npages * PAGE_SIZE);
vma->vm_ops = &shmm_vm_ops;
vma->vm_flags |= VM_LOCKED | VM_SHM;
return 0;
}
static struct file_operations shmm_fops = {
write: shmm_write,
mmap: shmm_mmap
};
static int shmm_init(void)
{
/* Dynamically allocate major number.
* cat /proc/devices to get number in userland.
*/
major = register_chrdev(0, "shmm", &shmm_fops);
if (major < 0) {
printk("register_chrdev() failed.\n");
return major;
}
return 0;
}
static void shmm_cleanup(void)
{
unregister_chrdev(major,"shmm");
}
module_init(shmm_init);
module_exit(shmm_cleanup);
[-- Attachment #3: test.c --]
[-- Type: text/plain, Size: 721 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
int main(void)
{
int shmm;
volatile int counter = 0;
volatile int* address;
shmm = open("/dev/shmm", O_RDWR);
if (shmm < 0) {
printf("File not found\n");
return 1;
}
address = mmap(0, getpagesize(), PROT_WRITE | PROT_READ,
MAP_PRIVATE , shmm, 0);
if (address == (void *)-1) {
printf(stderr,"mmap(): %s\n",strerror(errno));
exit(1);
}
while(1) {
*address = counter;
write(shmm, &counter, sizeof(counter));
counter++;
}
munmap((void*)address,getpagesize());
close(shmm);
}
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: shared memory
2001-08-28 17:17 shared memory Tom Appermont
@ 2001-08-29 3:37 ` Ralf Baechle
0 siblings, 0 replies; 11+ messages in thread
From: Ralf Baechle @ 2001-08-29 3:37 UTC (permalink / raw)
To: Tom Appermont; +Cc: linux-mips
On Tue, Aug 28, 2001 at 07:17:25PM +0200, Tom Appermont wrote:
> While this works as expected on PC, it does not at all work as
> expected on my mips platform (R5231): What is written in user
> space is not immediately visible in kernel space. This is with
> very recent kernel sources (2.4.8) but the same problem exists
> with an older (2.4.5) kernel.
>
> There have been a few mails about mmap() problems in the last
> couple of months, but with very little interesting response. Is
> this a known problem or am I stupidly overlooking something?
This is a different problem - and it's one caused by your code. You're
missing the necessary cache flushes in the kernel code. Using
_CACHE_UNCACHED is slow and breaks SMP.
Ralf
^ permalink raw reply [flat|nested] 11+ messages in thread
* shared memory
@ 2001-11-20 3:57 Lee Chin
0 siblings, 0 replies; 11+ messages in thread
From: Lee Chin @ 2001-11-20 3:57 UTC (permalink / raw)
To: linux-kernel
Hi,
How do you allocate shared memory in the 2.4 kernel
now? I added the line to fstab.. but how do I create
the /dev directory?
Thanks
Lee
__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1
^ permalink raw reply [flat|nested] 11+ messages in thread
* Shared memory
@ 2005-03-10 20:39 Bloch, Jack
0 siblings, 0 replies; 11+ messages in thread
From: Bloch, Jack @ 2005-03-10 20:39 UTC (permalink / raw)
To: linux-kernel
Under a 2.4 Kernel, a maximum of 2GB shared memory was allowed to be
attached to by each process. Is this still the same under a 2.6 Kernel? Is
this configurable? Please CC me on any responses.
Thank's in advance
Jack
^ permalink raw reply [flat|nested] 11+ messages in thread
* shared memory
@ 2007-12-16 19:51 Rafael Sisto
2007-12-16 19:57 ` Luciano Rocha
0 siblings, 1 reply; 11+ messages in thread
From: Rafael Sisto @ 2007-12-16 19:51 UTC (permalink / raw)
To: Linux kernel
Hi, Im working on a project working on linux kernel 2.6.17
I have to share memory on user level... I have to build something like
a server process that "exports" a portion of his virtual memory, and
other client process may ask the kernel for that memory and use it (as
its own).
I managed to build a structure on the kernel. The server process calls
a system-call and tells the kernel which pointer and size to share. Im
saving that data (virtual memory pointer and size) and the pid in the
structure.
After that, the client process calls another system call to get the
shared memory. My idea is to create a new vma_struct in the client
process pointing to the server shared memory.. The problem is I can't
see how to make a vma_struct to point directly to the server's
memory...
Can anybody help me with this issue? Any comment or suggestion would
be gratefuly accepted!
greetings from Uruguay!
Rafael Sisto
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: shared memory
2007-12-16 19:51 shared memory Rafael Sisto
@ 2007-12-16 19:57 ` Luciano Rocha
2007-12-16 20:01 ` Rafael Sisto
0 siblings, 1 reply; 11+ messages in thread
From: Luciano Rocha @ 2007-12-16 19:57 UTC (permalink / raw)
To: Rafael Sisto; +Cc: Linux kernel
[-- Attachment #1: Type: text/plain, Size: 647 bytes --]
On Sun, Dec 16, 2007 at 04:51:39PM -0300, Rafael Sisto wrote:
> Hi, Im working on a project working on linux kernel 2.6.17
> I have to share memory on user level... I have to build something like
> a server process that "exports" a portion of his virtual memory, and
> other client process may ask the kernel for that memory and use it (as
> its own).
> I managed to build a structure on the kernel.
Why? Aren't SysV IPC or Posix IPC enough?
See "man shm_open", for the new Posix version, and "man shmget" for the
old SysV IPC version.
--
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: shared memory
2007-12-16 19:57 ` Luciano Rocha
@ 2007-12-16 20:01 ` Rafael Sisto
2007-12-16 22:30 ` Luciano Rocha
0 siblings, 1 reply; 11+ messages in thread
From: Rafael Sisto @ 2007-12-16 20:01 UTC (permalink / raw)
To: Luciano Rocha, Rafael Sisto, Linux kernel
Thank you for the quick answer, but It's a college project, and I must
share user level memory. I also must build my own system calls...
But I can look what is already done and make something similar. Do you
think shmget would do? Does it share user level memory?
greetings!
Rafael Sisto
On Dec 16, 2007 4:57 PM, Luciano Rocha <luciano@eurotux.com> wrote:
> On Sun, Dec 16, 2007 at 04:51:39PM -0300, Rafael Sisto wrote:
> > Hi, Im working on a project working on linux kernel 2.6.17
> > I have to share memory on user level... I have to build something like
> > a server process that "exports" a portion of his virtual memory, and
> > other client process may ask the kernel for that memory and use it (as
> > its own).
> > I managed to build a structure on the kernel.
>
> Why? Aren't SysV IPC or Posix IPC enough?
>
> See "man shm_open", for the new Posix version, and "man shmget" for the
> old SysV IPC version.
>
> --
> Luciano Rocha <luciano@eurotux.com>
> Eurotux Informática, S.A. <http://www.eurotux.com/>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: shared memory
2007-12-16 20:01 ` Rafael Sisto
@ 2007-12-16 22:30 ` Luciano Rocha
2007-12-16 23:52 ` Rafael Sisto
0 siblings, 1 reply; 11+ messages in thread
From: Luciano Rocha @ 2007-12-16 22:30 UTC (permalink / raw)
To: Rafael Sisto; +Cc: Linux kernel
[-- Attachment #1: Type: text/plain, Size: 689 bytes --]
On Sun, Dec 16, 2007 at 05:01:17PM -0300, Rafael Sisto wrote:
> Thank you for the quick answer, but It's a college project, and I must
> share user level memory. I also must build my own system calls...
> But I can look what is already done and make something similar. Do you
> think shmget would do? Does it share user level memory?
Yes. They both do, but the Posix one is based on a ramfs or tmpfs on
/dev/shm and shared mmaps. I think analyzing the SysV version will be
better for your needs.
shmget: create the memory region
shmat: attach the memory region to this process.
--
Luciano Rocha <luciano@eurotux.com>
Eurotux Informática, S.A. <http://www.eurotux.com/>
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: shared memory
2007-12-16 22:30 ` Luciano Rocha
@ 2007-12-16 23:52 ` Rafael Sisto
0 siblings, 0 replies; 11+ messages in thread
From: Rafael Sisto @ 2007-12-16 23:52 UTC (permalink / raw)
To: Luciano Rocha, Rafael Sisto, Linux kernel
thanks a lot!!
On Dec 16, 2007 7:30 PM, Luciano Rocha <luciano@eurotux.com> wrote:
> On Sun, Dec 16, 2007 at 05:01:17PM -0300, Rafael Sisto wrote:
> > Thank you for the quick answer, but It's a college project, and I must
> > share user level memory. I also must build my own system calls...
> > But I can look what is already done and make something similar. Do you
> > think shmget would do? Does it share user level memory?
>
> Yes. They both do, but the Posix one is based on a ramfs or tmpfs on
> /dev/shm and shared mmaps. I think analyzing the SysV version will be
> better for your needs.
>
> shmget: create the memory region
> shmat: attach the memory region to this process.
>
> --
>
> Luciano Rocha <luciano@eurotux.com>
> Eurotux Informática, S.A. <http://www.eurotux.com/>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* shared memory
@ 2010-06-22 7:40 ratheesh k
0 siblings, 0 replies; 11+ messages in thread
From: ratheesh k @ 2010-06-22 7:40 UTC (permalink / raw)
To: linux-rt-users, linux-newbie
Shared memory space will created in userspace or kernel space . ? {
iPC mechanism }
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 11+ messages in thread* shared memory
@ 2011-06-06 16:59 haider abbas
0 siblings, 0 replies; 11+ messages in thread
From: haider abbas @ 2011-06-06 16:59 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
I have installed ubuntu 10.04 on a lenovo desktop.
I need to increase shared memory permanently to run some program.
I add
kernel.shmall = 4294967296
kernel.shmmax = 4294967296
in /etc/sysctl.conf
but when I run the command sysctl -a|grep shmmax it shows
root@haider-desktop:~# sysctl -a|grep shmmax
kernel.shmmax = 0
error: "Invalid argument" reading key "fs.binfmt_misc.register"
error: permission denied on key 'net.ipv4.route.flush'
error: permission denied on key 'net.ipv6.route.flush'
root@haider-desktop:~#
I again run the command /etc/sysctl.conf -w
then it shows
root@haider-desktop:~# /etc/sysctl.conf -w
bash: /etc/sysctl.conf: Permission denied
root@haider-desktop:~#
Then I try echo 4294967296 >> /proc/sys/kernel/shmmax
but no changes took place.
Then I use some trick, I make a dummy file and when I copied or
move to /proc/sys/kernel then it shows.
No such file or directory
root@haider-desktop:~#
however I am the running these command by root
I dont understand what is going on what is the actual problem
with regards
Dr. Haider Abbas
Manav Rachna College of Engineering
Faridabad, India
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-06-06 16:59 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-08-28 17:17 shared memory Tom Appermont
2001-08-29 3:37 ` Ralf Baechle
-- strict thread matches above, loose matches on Subject: below --
2001-11-20 3:57 Lee Chin
2005-03-10 20:39 Shared memory Bloch, Jack
2007-12-16 19:51 shared memory Rafael Sisto
2007-12-16 19:57 ` Luciano Rocha
2007-12-16 20:01 ` Rafael Sisto
2007-12-16 22:30 ` Luciano Rocha
2007-12-16 23:52 ` Rafael Sisto
2010-06-22 7:40 ratheesh k
2011-06-06 16:59 haider abbas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.