All of lore.kernel.org
 help / color / mirror / Atom feed
* 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
* 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
* 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.