Skip to contentSkip to conversation

ENXIO error with large shared memory

Xenomai-help Henry Bausley 2 participants 9 messages Mar 16, 2009 – Aug 13, 2009

lore
Share & tools
lore
#1 lore raw
In reply to Henry Bausley
Quoted 8 lines · Henry Bausley

I am trying to map a large shared memory buffer and cannot seem to map 32M. I get the error code ENXIO back from the posix skin mmap.

The code works for
ftruncate(prgshmfd, 16777216);
pPrgShm = mmap(NULL, 16777216, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);
but fails if I have
ftruncate(prgshmfd, 16777216*2);

What if you checked the return value of ftruncate here ?

Quoted 2 lines
  pPrgShm = mmap(NULL, 16777216*2, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);
Signature · 1 line
					    Gilles.
#0 lore raw

I am trying to map a large shared memory buffer and cannot seem to map 32M. I get the error code ENXIO back from the posix skin mmap.

The code works for
ftruncate(prgshmfd, 16777216);
pPrgShm = mmap(NULL, 16777216, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);
but fails if I have
ftruncate(prgshmfd, 16777216*2);
pPrgShm = mmap(NULL, 16777216*2, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);

The condition failing is mmap in xenomai/skins/posix/shm.c.

if (!shm->addr || off + len > shm->size)

        {

err = ENXIO;
up(&shm->maplock);
goto err_free_map;
}

For 16M
len = 0x1000000 and shm->size = 0x1000000

For 32M
len = 0x2000000 and shm->size = 0x1FFF000

Is there something I didn't configure correctly that is limiting my size?

I am currently using 2.4.6 Xenomai, I-pipe 2.2-07 with kernel 2.6.26-denx on a 1Ghz PowerPC 460EX with 2G RAM

**********************************************************
Outbound scan for Spam or Virus by Barracuda at Delta Tau
**********************************************************

#2 lore raw

ftruncate returns 0
----- Original Message -----
From: Henry Bausley
To: [email protected]
Sent: Monday, March 16, 2009 3:08 PM
Subject: [Xenomai-help] ENXIO error with large shared memory

I am trying to map a large shared memory buffer and cannot seem to map 32M. I get the error code ENXIO back from the posix skin mmap.

  The code works for
    ftruncate(prgshmfd, 16777216);
    pPrgShm = mmap(NULL, 16777216, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);
  but fails if I have
    ftruncate(prgshmfd, 16777216*2);
    pPrgShm = mmap(NULL, 16777216*2, PROT_READ | PROT_WRITE, MAP_SHARED, prgshmfd, 0);

The condition failing is mmap in xenomai/skins/posix/shm.c.

   if (!shm->addr || off + len > shm->size) 
          {
     err = ENXIO;
     up(&shm->maplock);
     goto err_free_map;
   }

For 16M
len = 0x1000000 and shm->size = 0x1000000

For 32M
len = 0x2000000 and shm->size = 0x1FFF000

Is there something I didn't configure correctly that is limiting my size?

I am currently using 2.4.6 Xenomai, I-pipe 2.2-07 with kernel 2.6.26-denx on a 1Ghz PowerPC 460EX with 2G RAM

------------------------------------------------------------------------------

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

**********************************************************
Outbound scan for Spam or Virus by Barracuda at Delta Tau
**********************************************************

#3 lore raw
Quoted 1 line · Henry Bausley

ftruncate returns 0

Ok. I think I understood what the problem is, I will try to send a patch tonight.

Signature · 1 line
                                                 Gilles.
#4 lore raw
Quoted 6 lines · Gilles Chanteperdrix
Quoted 1 line · Henry Bausley

ftruncate returns 0

Ok. I think I understood what the problem is, I will try to send a patch tonight.

The following not very subtil patch seems to fix the issue:

nucleus/heap.h (working copy) renamed from nucleus/heap.h (revision 4692) +5 -1
Index: include/nucleus/heap.h
===================================================================
@@ -156,6 +156,7 @@
 
 static inline size_t xnheap_rounded_size(size_t hsize, size_t psize)
 {
+       size_t rounded_size;
        /*
         * Account for the minimum heap size (i.e. 2 * page size) plus
         * overhead so that the actual heap space is large enough to
@@ -167,7 +168,10 @@
        if (hsize < 2 * psize)
                hsize = 2 * psize;
        hsize += xnheap_overhead(hsize, psize);
-       return xnheap_align(hsize, psize);
+       rounded_size = xnheap_align(hsize, psize);
+       while (rounded_size - xnheap_overhead(rounded_size, psize) < hsize)
+               rounded_size += psize;
+       return rounded_size;
 }
 
 #ifdef __cplusplus
Signature · 1 line
                                                 Gilles.
#6 lore raw
In reply to Henry Bausley
Quoted 2 lines · Henry Bausley

The patch makes it work for 32M. However if I try to go larger ie.48M or 64M I get the following

Do you get the same error if you only run a simple program that does such a big allocation ?

In other words, is it the big allocation by itself which causes this "badness" or the accumulation of allocations (and possible memory corruption).

You should be aware that the vmalloc space also has limits. Why do you need to share such big areas between kernel and user-space ?

Signature · 1 line
                                                 Gilles.
#8 lore raw
In reply to Henry Bausley
Quoted 11 lines · Henry Bausley

The patch makes it work for 32M. However if I try to go larger ie.48M or 64M I get the following

Program buffer: 67108864

     User buffer: 1048576
    Table buffer: 1048576
LookAhead buffer: 16777216
RT User Program ftruncate No Error
------------[ cut here ]------------
Badness at c00b6a94 [verbose debug info unavailable]

Please compile the kernel with more debug options so thatwe know exactly where this badness happens.

Signature · 1 line
                                                 Gilles.
#5 lore raw
In reply to Gilles Chanteperdrix

The patch makes it work for 32M. However if I try to go larger ie.48M or 64M I get the following

Program buffer: 67108864

    User buffer: 1048576
   Table buffer: 1048576
LookAhead buffer: 16777216
RT User Program ftruncate No Error
------------[ cut here ]------------
Badness at c00b6a94 [verbose debug info unavailable]
NIP: c00b6a94 LR: c00b7064 CTR: 00000000
REGS: ef1edbe0 TRAP: 0700   Not tainted  (2.6.26.8)
MSR: 00029000 <EE,ME>  CR: 48008248  XER: 00000007

TASK = ef8f75a0[2143] 'insmod' THREAD: ef1ec000
GPR00: 00000001 ef1edc90 ef8f75a0 ef1716c0 0000033b ef1edcc8 c1727978 ffffffff
GPR08: ef817800 00000000 c1726be0 ef034a54 88008284 100197d8 f4fc0000 f4fc0cf0
GPR16: f4fc0d2c ef9a106c c040b228 f4fc0000 ef1edd30 00101420 ffc00ffd c03f0000
GPR24: 0000033b ef1716c0 ff16cfff c03cafe0 ff16d000 ef1edcc8 ff16d000 ff100000 NIP [c00b6a94] map_vm_area+0xb0/0x174
LR [c00b7064] __vmalloc_area_node+0xd8/0x164

Call Trace:

[ef1edc90] [00101420] 0x101420 (unreliable)
[ef1edcc0] [c00b7064] __vmalloc_area_node+0xd8/0x164 [ef1edcf0] [c0051ff8] xnheap_init_mapped+0x13c/0x4a8 [ef1edd20] [c0094324] ftruncate+0x3a0/0x528
[ef1edd80] [f4fa2c5c] init_module+0x374/0x91c [rtpmac] [ef1ede70] [c00476ec] sys_init_module+0x134/0x1784
[ef1edf40] [c000e06c] ret_from_syscall+0x0/0x3c
Instruction dump:
418200cc 57e0bd38 7d090215 41820098 817d0000 81480004 39200000 7d205379 814b0000 38000000 41820008 38000001 <0f000000> 2f8a0000 3bff1000 7f1ef800

------------[ cut here ]------------

----- Original Message ----- From: "Gilles Chanteperdrix" <[email protected]>
To: "Henry Bausley" <[email protected]>
Cc: <[email protected]>
Sent: Tuesday, March 17, 2009 9:08 AM
Subject: Re: [Xenomai-help] ENXIO error with large shared memory

Quoted 34 lines
Quoted 6 lines · Gilles Chanteperdrix
Quoted 1 line · Henry Bausley

ftruncate returns 0

Ok. I think I understood what the problem is, I will try to send a patch tonight.

The following not very subtil patch seems to fix the issue:

Index: include/nucleus/heap.h
===================================================================

nucleus/heap.h (working copy) renamed from nucleus/heap.h (revision 4692) +5 -1
@@ -156,6 +156,7 @@
 
 static inline size_t xnheap_rounded_size(size_t hsize, size_t psize)
 {
+       size_t rounded_size;
       /*
        * Account for the minimum heap size (i.e. 2 * page size) plus
        * overhead so that the actual heap space is large enough to
@@ -167,7 +168,10 @@
       if (hsize < 2 * psize)
               hsize = 2 * psize;
       hsize += xnheap_overhead(hsize, psize);
-       return xnheap_align(hsize, psize);
+       rounded_size = xnheap_align(hsize, psize);
+       while (rounded_size - xnheap_overhead(rounded_size, psize) < 
 hsize)
+               rounded_size += psize;
+       return rounded_size;
 }
 
Quoted 5 lines

#ifdef __cplusplus

Signature · 1 line
                                                Gilles. 

**********************************************************
Outbound scan for Spam or Virus by Barracuda at Delta Tau
**********************************************************

#7 lore raw
In reply to Gilles Chanteperdrix

This problems was due to the limits of vmalloc. To increase the limit required changing the PAGE_OFFSET

The virtual address space used by vmalloc() is in the range of VMALLOC_START and VMALLOC_END. If
CONFIG_HIGMEM is defined while building the kernel (it will be, if the machine has more than 1GB memory), and
the PAGE_OFFSET is the default value of 0xc0000000,
this range is approximately 0xf8000000 to 0xfe000000.
This is about 96MB.
from -> http://mail.nl.linux.org/kernelnewbies/2001-12/msg00004.html

then changed the advanced kernel settings

#
# Advanced setup
#
CONFIG_ADVANCED_OPTIONS=y
# CONFIG_LOWMEM_SIZE_BOOL is not set
CONFIG_LOWMEM_SIZE=0x30000000
CONFIG_PAGE_OFFSET_BOOL=y
CONFIG_PAGE_OFFSET=0x80000000
CONFIG_KERNEL_START_BOOL=y
CONFIG_KERNEL_START=0x80000000
CONFIG_PHYSICAL_START=0x00000000
CONFIG_TASK_SIZE_BOOL=y
CONFIG_TASK_SIZE=0x80000000
# CONFIG_CONSISTENT_START_BOOL is not set
CONFIG_CONSISTENT_START=0xff100000

from

#
# Advanced setup
#
# CONFIG_ADVANCED_OPTIONS is not set

#
# Default settings for advanced configuration options are used #
CONFIG_LOWMEM_SIZE=0x30000000 CONFIG_PAGE_OFFSET=0xc0000000 CONFIG_KERNEL_START=0xc0000000 CONFIG_PHYSICAL_START=0x00000000 CONFIG_TASK_SIZE=0xc0000000 CONFIG_CONSISTENT_START=0xff100000 CONFIG_CONSISTENT_SIZE=0x00200000
CONFIG_NET=y

----- Original Message ----- From: "Gilles Chanteperdrix" <[email protected]>
To: "Henry Bausley" <[email protected]>
Cc: <[email protected]>
Sent: Tuesday, March 17, 2009 10:21 AM
Subject: Re: [Xenomai-help] ENXIO error with large shared memory

Quoted 7 lines
Quoted 2 lines · Henry Bausley

The patch makes it work for 32M. However if I try to go larger ie.48M or 64M I get the following

Do you get the same error if you only run a simple program that does such a big allocation ?

Quoted 9 lines

In other words, is it the big allocation by itself which causes this "badness" or the accumulation of allocations (and possible memory corruption).

You should be aware that the vmalloc space also has limits. Why do you need to share such big areas between kernel and user-space ?

Signature · 1 line
                                                Gilles. 

**********************************************************
Outbound scan for Spam or Virus by Barracuda at Delta Tau
**********************************************************