Project

General

Profile

Actions

Bug #5437

closed

Using fibers leads to huge memory leak

Added by rupert (Robert Pankowecki) over 12 years ago. Updated over 11 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 1.9.3dev (2011-10-11 revision 33457) [x86_64-linux]
Backport:
[ruby-core:40117]

Description

It appears to me that there is something wrong with reallocating (reusing?) memory used by fibers. Here is a little script:

require 'fiber'

fibers = 10_000.times.map do
Fiber.new do
f = Fiber.current
Fiber.yield
end
end; nil

fibers.each(&:resume); nil
fibers.each(&:resume); nil
fibers = []

GC.start

Running this code in IRB multiple times leads to consuming more and more memory every time. However every time I execute this code the amount of newly consumed memory is lower. I was able to repeat this bug with ruby 1.9.2.p290 and 1.9.3-head using 32 and 64 bit architecture.

Here are some memory stats:
a) 32bit
Iter | VSZ | RSS
1 186268 63508
2 360196 119580
3 360340 147600
4 360484 178552
5 360616 199968
6 360612 210716
7 360612 221920
8 360612 224544
9 360612 229976

b) 64bit
1 395152 107600
2 739924 176532
3 739924 187972
4 739924 203300
5 739924 217716
6 739924 218344
7 739924 218540
8 739924 234040
9 739924 234256

We can see on our production instance that the more Fibers are in use the more memory is never reclaimed back to OS and the bigger the leak is.


Files

cieknace_fibery (510 Bytes) cieknace_fibery Source code of micro benchmark rupert (Robert Pankowecki), 10/17/2011 05:50 PM
65536.txt (1.61 KB) 65536.txt output when running with MALLOC_MMAP_THRESHOLD_ set to 65536 rupert (Robert Pankowecki), 10/17/2011 05:50 PM
131072.txt (1.61 KB) 131072.txt output when running with MALLOC_MMAP_THRESHOLD_ set to 131072 rupert (Robert Pankowecki), 10/17/2011 05:50 PM
262144.txt (1.61 KB) 262144.txt output when running with MALLOC_MMAP_THRESHOLD_ set to 262144 rupert (Robert Pankowecki), 10/17/2011 05:50 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0