All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Grandegger <wg@domain.hid>
To: Roderik_Wildenburg@domain.hid
Cc: xenomai@xenomai.org
Subject: Re: AW: [Xenomai-help] memset of heap crashes Xenomai-Task
Date: Tue, 11 Jul 2006 10:09:27 +0200	[thread overview]
Message-ID: <44B35CB7.8010708@domain.hid> (raw)
In-Reply-To: <5D63919D95F87E4D9D34FF7748CE2C2A3F9210@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 2172 bytes --]

Roderik_Wildenburg@domain.hid wrote:
>> memset should work with Xenomai heaps, I suspect your problem 
>> is rather that the memory is not really allocated until you 
>> memset it, which fails when no memory is available. In this 
>> case, calling memset on memory allocated with malloc should 
>> segfault the same way when the system memory is exhausted. 
>> IIRC, this behaviour is documented in mlockall manual page.
>>
> 
> Mr. Denk told me about this strange (for RTOSs) behaviour of the 
> Linux kernel. Therefore I used the Xenomai heap mechanism, expecting
> allocated memory is allocated at once not some time later 
> (why do I allocate memory otherwise : to be shure memory is available).
> Does Xenomai use the Linux allocation mechanism ??
> 
> 
>> Be careful with sysconf(_SC_AVPHYS_PAGES), it may include the 
>> swap size, but when mlocking memory, your application can not 
>> use swap pages, so, you should substract the size of swap, if any.
>> Also, what is the value of /proc/sys/vm/overcommit_memory on 
>> your system ?
>>
> 
> Our System does not have a swap device\space.
> /proc/sys/vm/overcommit_memory = 0
> (whatever this means)

I gave your program a try on my MPC5200 and got the following output 
(after some corrections):

bash-2.05b# ./heap2
Start Heap
root_thread_init :
timer startedt
display task created
root_thread_init beendet
Available Memory 56238080 (Pagesize 4096)
heap 0 of size 16000000 created
Heap 0 allocated size 16000000
heap 1 of size 16000000 created
Heap 1 allocated size 16000000
heap 2 of size 16000000 created
Heap 2 allocated size 16000000
__alloc_pages: 0-order allocation failed (gfp=0x1f2/0)
Available Memory after allocation 8933376
__alloc_pages: 0-order allocation failed (gfp=0x1f0/0)
Heap 3 created with size 4218880
Heap 3 allocated size 4218880
Memory allocated in total : 52218880
Segmentation fault

The are some long delays (approx. 40 secs) around __alloc_pages. Finally 
it crashes in memset. With the attached xenomai patch, which touches the 
reserved page once, memset works fine. Let's wait what Philippe says. I 
remember that the "touch" was needed for RTAI shared memory as well.

Wolfgang.

[-- Attachment #2: xenomai-heap-access.patch --]
[-- Type: text/x-patch, Size: 582 bytes --]

+ diff -u xenomai/ksrc/nucleus/heap.c.OLD xenomai/ksrc/nucleus/heap.c
--- xenomai/ksrc/nucleus/heap.c.OLD	2006-06-30 10:29:34.000000000 +0200
+++ xenomai/ksrc/nucleus/heap.c	2006-07-11 09:46:30.000000000 +0200
@@ -1044,8 +1044,10 @@
 
 		vabase = (unsigned long)ptr;
 
-		for (vaddr = vabase; vaddr < vabase + size; vaddr += PAGE_SIZE)
+		for (vaddr = vabase; vaddr < vabase + size; vaddr += PAGE_SIZE) {
 			SetPageReserved(virt_to_page(__va_to_kva(vaddr)));
+			*(int *)vaddr = 0; /* touch page once */
+		}
 	} else {
 		/*
 		 * Otherwise, we have been asked for some kmalloc()

  reply	other threads:[~2006-07-11  8:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-11  6:25 AW: [Xenomai-help] memset of heap crashes Xenomai-Task Roderik_Wildenburg
2006-07-11  8:09 ` Wolfgang Grandegger [this message]
2006-07-11  8:22   ` Jan Kiszka
2006-07-11  8:42     ` Wolfgang Grandegger
  -- strict thread matches above, loose matches on Subject: below --
2006-07-11  6:09 Roderik_Wildenburg
2006-07-11  6:22 ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44B35CB7.8010708@domain.hid \
    --to=wg@domain.hid \
    --cc=Roderik_Wildenburg@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.