Mmap crash when appending

G

Guillaume Marcais

[gus@hibernatus Bifurcation]$ cat mmap-abort.rb
require 'mmap'
mm = Mmap.new("test-mmap", "w")
10.times { |i| p i; mm << "\0" * 1024 }

[gus@hibernatus Bifurcation]$ > test-mmap
[gus@hibernatus Bifurcation]$ ruby mmap-abort.rb
0
1
2
3
4
mmap-abort.rb:3: [BUG] Bus Error
ruby 1.8.2 (2004-12-25) [i586-linux-gnu]

Aborted

[gus@hibernatus Bifurcation]$ ls -ls test-mmap
4 -rw-rw-r-- 1 gus gus 4096 Sep 10 07:45 test-mmap
[gus@hibernatus Bifurcation]$ uname -a
Linux hibernatus.gus.marcais.net 2.6.11-6mdksmp #1 SMP Tue Mar 22
15:40:42 CET 2005 i686 Pentium Pro unknown GNU/Linux

The same behavior was showned on two different Linux machines (same
distribution though).
Any idea why it crashes?

Guillaume.
 
T

ts

G> mm = Mmap.new("test-mmap", "w")

mm = Mmap.new("test-mmap", "rw")


Guy Decoux

p.s.: yes, I know this seems strange ...
 
G

Guillaume Marcais

Le 10 sept. 05, =E0 12:15, ts a =E9crit :
G> mm =3D Mmap.new("test-mmap", "w")

mm =3D Mmap.new("test-mmap", "rw")


Guy Decoux

p.s.: yes, I know this seems strange ...

It works!

Thanks.
Guillaume.=
 
T

ts

G> It works!

svg% diff -u mmap.c~ mmap.c
--- mmap.c~ 2004-11-07 15:31:26.000000000 +0100
+++ mmap.c 2005-09-10 18:36:02.000000000 +0200
@@ -522,7 +522,7 @@
if (!init) t_mm->real = size;
t_mm->pmode = pmode;
t_mm->vscope = vscope;
- t_mm->smode = smode;
+ t_mm->smode = smode & ~O_TRUNC;
t_mm->path = (path)?ruby_strdup(path):(char *)-1;
if (smode == O_RDONLY) {
obj = rb_obj_freeze(obj);
svg%



Guy Decoux
 
A

Ara.T.Howard

[gus@hibernatus Bifurcation]$ cat mmap-abort.rb
require 'mmap'
mm = Mmap.new("test-mmap", "w")
10.times { |i| p i; mm << "\0" * 1024 }

[gus@hibernatus Bifurcation]$ > test-mmap
[gus@hibernatus Bifurcation]$ ruby mmap-abort.rb
0
1
2
3
4
mmap-abort.rb:3: [BUG] Bus Error
ruby 1.8.2 (2004-12-25) [i586-linux-gnu]

Aborted

[gus@hibernatus Bifurcation]$ ls -ls test-mmap
4 -rw-rw-r-- 1 gus gus 4096 Sep 10 07:45 test-mmap
[gus@hibernatus Bifurcation]$ uname -a
Linux hibernatus.gus.marcais.net 2.6.11-6mdksmp #1 SMP Tue Mar 22 15:40:42
CET 2005 i686 Pentium Pro unknown GNU/Linux

The same behavior was showned on two different Linux machines (same
distribution though).
Any idea why it crashes?

works fine for me:

harp:~ > irb -r mmap -r fileutils
irb(main):001:0> FileUtils::touch 'mmap'
=> ["mmap"]
irb(main):002:0> mm = Mmap.new("mmap", "rw")
=> #<Mmap:0xb7570b3c>
irb(main):003:0> 1.times { |i| p i; mm << ("\0" * 1024) }
0
=> 1
irb(main):004:0> 10.times { |i| p i; mm << ("\0" * 1024) }
0
1
2
3
4
5
6
7
8
9
=> 10
irb(main):005:0> 20.times { |i| p i; mm << ("\0" * 1024) }
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
=> 20
irb(main):006:0> mm
=> #<Mmap:0xb7570b3c>
irb(main):007:0> mm.to_str.size
=> 31744
irb(main):008:0> mm.msync
=> #<Mmap:0xb7570b3c>
irb(main):009:0> IO::read('mmap').size
=> 31744


thoughts:

- redhat has had many bugs with there mmap code. a short while ago i
reported a simple c program that would hang the kernel

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=124626

perhaps your linux version is buggy. if so bug the developers - mmap is
such a fundemental operation (programs are always mmap'd when run by the
kernel) that it's astounding that bugs like this get released.

- did you install ruby via some package manager but compile the mmap dist?
if you i'd (always) compile ruby vs. trusting the binary dists and compile
mmap using this ruby, then see if the problem persists.

other than that i can tell you i'm abusing mmap in the most sinister ways with
no crashes or data corruption on a variety of linux dists.

hth.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
G

Guillaume Marcais

Le 10 sept. 05, =E0 15:01, Ara.T.Howard a =E9crit :
works fine for me:

harp:~ > irb -r mmap -r fileutils
irb(main):001:0> FileUtils::touch 'mmap'
=3D> ["mmap"]
irb(main):002:0> mm =3D Mmap.new("mmap", "rw")

Yes, as suggested by Guy, using "rw" instead of "w" fixes the problem,=20=

however weird that may seem. His patch in ruby-talk:155557 fixed the=20
problem too.
thoughts:

- redhat has had many bugs with there mmap code. a short while ago = i
reported a simple c program that would hang the kernel

https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=3D124626

perhaps your linux version is buggy. if so bug the developers -=20=
mmap is
such a fundemental operation (programs are always mmap'd when run=20=
by the
kernel) that it's astounding that bugs like this get released.

I am not using RedHat but Mandrake (note that I am not claiming=20
anything about the quality of one over the other).
- did you install ruby via some package manager but compile the mmap=20=
dist?
if you i'd (always) compile ruby vs. trusting the binary dists and=20=
compile
mmap using this ruby, then see if the problem persists.

Correct, it is the distro binary of ruby and a self compile mmap.
other than that i can tell you i'm abusing mmap in the most sinister=20=
ways with
no crashes or data corruption on a variety of linux dists.

Well, your recent posts on the subject have been inspirational... I=20
have crashed ruby using mmap after forking (haven't nailed down the bug=20=

yet). I'll recompile ruby to see if that's the problem.

Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top