From: Jeremy Hinegardner Date: 2005-11-08T16:54:42+09:00 Subject: OpenBSD AMD64 NoMemoryError - bug ? --qVHblb/y9DPlgkHs Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, I'm encountering an odd error, but only on the amd64 using OpenBSD. I believe I've boiled it down to the attached test case. Here's an example run on 2 systems I have: First on CentOS 4.2 x86 with 1GB of RAM: $ ./obsd-amd64-membug.rb Allocating a big array of strings of length 300. We've done enough: Array size = 1789570 Estimated memory size = ruby + 512.00008392334 MB Good, it does the right thing. Next on AMD64 OpenBSD 3.7 with 1GB of RAM: % ./obsd-amd64-membug.rb Allocating a big array of strings of length 300. Caught exception Array size = 126103 [FATAL] failed to allocate memory Hmm... odd it failed to allocate memory on a 'puts'. Very strange. Now if we alter the script slightly, just remove the '\t' from lines 27 and 28 in the rescue block we get: % ./obsd-amd64-membug.rb Allocating a big array of strings of length 300. Caught exception Array size = 126103 Estimated memory size = ruby + 36.0783576965332 MB ./obsd-amd64-membug.rb:13:in `initialize_copy' ./obsd-amd64-membug.rb:13 1) Caught exception failed to allocate memory 2) Caught exception NoMemoryError I seemed to remember several times in the past year where there have been whitespace issues in a script that caused odd bugs, but I was unable to find them. Anyone have a clue? enjoy, -jeremy -- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org --qVHblb/y9DPlgkHs Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="obsd-amd64-membug.rb" #!/usr/local/bin/ruby MULTIPLIER = 10 MAX_ALLOC = 1024 * 1024 * 512 # 512MB msg = "This is some ruby data (#####)" * MULTIPLIER max_msg_kb = msg.length.to_f / 1024.0 puts "Allocating a big array of strings of length #{msg.length}." y = Array.new begin while true do y << msg.dup est_size = y.length * max_msg_kb * 1024 if est_size >= MAX_ALLOC then puts "We've done enough:" puts "\tArray size = #{y.length}" puts "\tEstimated memory size = ruby + #{est_size / 1024 / 1024} MB" exit 0 end end rescue SystemExit => se exit 0 rescue Exception => e begin puts "Caught exception" puts "\tArray size = #{y.length}" puts "\tEstimated memory size = ruby + #{(y.length * max_msg_kb) / 1024} MB" puts puts e.backtrace.join("\n") puts " 1) Caught exception #{$!}" puts " 2) Caught exception #{e.class}" rescue Exception => e2 puts e2.backtrace.join('\n') end exit 1 end exit 0 --qVHblb/y9DPlgkHs--