Skip to content

Triggering OOM when piping large amount of data from a function #2803

Closed

Description

@enricotagliavini

If I pipe a huge amount of data from a function, fish RSS memory quickly grows to GBs, system memory is exhausted and OOM killer is triggered.

Reproduction Steps:

To make testing less dangerous and easier to reproduce (since we are limited by how much memory is available to the system) I recommend creating (if on Linux) a cgroup limiting the amount of memory processes can use and add fish to this cgroup for the testing:

# as root
$ cd /sys/fs/cgroup/memory/
$ mkdir 4g
$ cd 4g/
$ echo 2147483648 > memory.limit_in_bytes
# I actually used 4 G on my tests, but there's no point. The lower the limit the easier to reproduce
$ cat memory.limit_in_bytes` 
2147483648
$ echo 2147483648 > memory.memsw.limit_in_bytes`
$ cat memory.memsw.limit_in_bytes
2147483648
# we use another shell for testing, not this that run as root
echo <fish client pid (reported by %self) here> > tasks
  1. Wrap cat into a function:
    function cat
    command cat $argv
    end
    enrico@quantdell ~ $ type cat
    cat is a function with definition
    function cat
    command cat $argv
    end
  2. have a lot of data passing though the function. For example count the lines in a very big file with something like
    $ cat ../virt/rhel-server-7.2-x86_64-dvd.iso | wc -l
  3. Observe OOM in dmesg

(this goes on until 20522 is finally killed)

Expected behavior:

I should be able to pipe huge amount of data from a function (see later for a real use case scenario)

Observed behavior:

[12364.705844] fish invoked oom-killer: gfp_mask=0x24000c0, order=0, oom_score_adj=0
[12364.705849] fish cpuset=/ mems_allowed=0
[12364.705856] CPU: 2 PID: 20522 Comm: fish Tainted: P     U     OE   4.4.4-200.fc22.x86_64 #1
[12364.705857] Hardware name: Dell Inc. XPS 13 9343/0TM99H, BIOS A07 11/11/2015
[12364.705859]  0000000000000286 000000006211cbb7 ffff88001234fc80 ffffffff813b515e
[12364.705861]  ffff88001234fd60 ffff88001897bc00 ffff88001234fcf0 ffffffff8122ad43
[12364.705863]  ffff88021f516e00 ffff88021f516e00 ffff8801dbabd500 ffffffff811b0546
[12364.705865] Call Trace:
[12364.705871]  [<ffffffff813b515e>] dump_stack+0x63/0x85
[12364.705874]  [<ffffffff8122ad43>] dump_header+0x5a/0x1be
[12364.705878]  [<ffffffff811b0546>] ? find_lock_task_mm+0x36/0x80
[12364.705882]  [<ffffffff8179fbae>] ? _raw_spin_unlock_irqrestore+0xe/0x10
[12364.705883]  [<ffffffff811b0af9>] oom_kill_process+0x1f9/0x3b0
[12364.705885]  [<ffffffff8121e8b4>] ? mem_cgroup_iter+0x204/0x390
[12364.705887]  [<ffffffff81220b1f>] mem_cgroup_out_of_memory+0x2af/0x2f0
[12364.705889]  [<ffffffff812217d8>] mem_cgroup_oom_synchronize+0x328/0x340
[12364.705890]  [<ffffffff8121cc10>] ? memcg_event_wake+0x70/0x70
[12364.705892]  [<ffffffff811b11d4>] pagefault_out_of_memory+0x44/0xc0
[12364.705895]  [<ffffffff810680d2>] mm_fault_error+0x82/0x160
[12364.705897]  [<ffffffff81068588>] __do_page_fault+0x3d8/0x400
[12364.705898]  [<ffffffff810685df>] do_page_fault+0x2f/0x80
[12364.705902]  [<ffffffff817a2308>] page_fault+0x28/0x30
[12364.705903] Task in /4g killed as a result of limit of /4g
[12364.705907] memory: usage 4194304kB, limit 4194304kB, failcnt 0
[12364.705908] memory+swap: usage 4194304kB, limit 4194304kB, failcnt 3787623
[12364.705909] kmem: usage 0kB, limit 9007199254740988kB, failcnt 0
[12364.705909] Memory cgroup stats for /4g: cache:0KB rss:4194304KB rss_huge:0KB mapped_file:0KB dirty:0KB writeback:0KB swap:0KB inactive_anon:1048612KB active_anon:3145652KB inactive_file:0KB active_file:0KB unevictable:0KB
[12364.705920] [ pid ]   uid  tgid total_vm      rss nr_ptes nr_pmds swapents oom_score_adj name
[12364.706098] [20522]  1000 20522  1663062  1049668    2078       9        0             0 fish
[12364.706103] [21937]  1000 21937    90196      359      23       3        0             0 fish
[12364.706105] [21938]  1000 21938    27417      185      11       3        0             0 cat
[12364.706106] Memory cgroup out of memory: Kill process 20522 (fish) score 1003 or sacrifice child
[12364.706117] Killed process 21937 (fish) total-vm:360784kB, anon-rss:1436kB, file-rss:0kB

Additional information:

Happens every time, I discovered this while doing some analysis on a huge apache httpd log file. The logfile is more than 8 GB in size and I used grep {expression} | wc -l to do some rough statistics. My system became unresponsive immediately. That was without the safety net of the cgroup. This system (my laptop) has only 8 GB of ram, much used by desktop apps already, swap is rather small (4 GB).

In one of the runs I actually got a bad_alloc (or something like that, sorry this doesn't happen frequently). abrt captured a coredump for me that I can attach if necessary. The backtrace is:

{   "signal": 6
,   "executable": "/usr/bin/fish"
,   "only_crash_thread": true
,   "stacktrace":
      [ {   "crash_thread": true
        ,   "frames":
              [ {   "address": 140662809467336
                ,   "build_id": "97a5b712e93b188f314f8a5c8fb2eb0285c3d842"
                ,   "build_id_offset": 215496
                ,   "function_name": "raise"
                ,   "file_name": "/usr/lib64/libc-2.21.so"
                }
              , {   "address": 140662809474650
                ,   "build_id": "97a5b712e93b188f314f8a5c8fb2eb0285c3d842"
                ,   "build_id_offset": 222810
                ,   "function_name": "abort"
                ,   "file_name": "/usr/lib64/libc-2.21.so"
                }
              , {   "address": 140662819146589
                ,   "build_id": "96d5cd365a2a3aff78d359ad65aa4de888ae994a"
                ,   "build_id_offset": 588637
                ,   "function_name": "__gnu_cxx::__verbose_terminate_handler()"
                ,   "file_name": "/usr/lib64/libstdc++.so.6.0.21"
                }
              , {   "address": 140662819137958
                ,   "build_id": "96d5cd365a2a3aff78d359ad65aa4de888ae994a"
                ,   "build_id_offset": 580006
                ,   "file_name": "/usr/lib64/libstdc++.so.6.0.21"
                }
              , {   "address": 140662819138033
                ,   "build_id": "96d5cd365a2a3aff78d359ad65aa4de888ae994a"
                ,   "build_id_offset": 580081
                ,   "file_name": "/usr/lib64/libstdc++.so.6.0.21"
                }
              , {   "address": 140662819138569
                ,   "build_id": "96d5cd365a2a3aff78d359ad65aa4de888ae994a"
                ,   "build_id_offset": 580617
                ,   "file_name": "/usr/lib64/libstdc++.so.6.0.21"
                }
              , {   "address": 140662819140012
                ,   "build_id": "96d5cd365a2a3aff78d359ad65aa4de888ae994a"
                ,   "build_id_offset": 582060
                ,   "file_name": "/usr/lib64/libstdc++.so.6.0.21"
                }
              , {   "address": 4541190
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 346886
                ,   "function_name": "void std::vector<char, std::allocator<char> >::_M_range_insert<char const*>(__gnu_cxx::__normal_iterator<char*, std::vector<char, std::allocator<char> > >, char const*, char const*, std::forward_iterator_tag)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4668422
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 474118
                ,   "function_name": "read_try(job_t*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4669931
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 475627
                ,   "function_name": "job_continue(job_t*, bool)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4535845
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 341541
                ,   "function_name": "exec_job(parser_t&, job_t*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4997824
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 803520
                ,   "function_name": "parse_execution_context_t::run_1_job(parse_node_t const&, block_t const*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4998374
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 804070
                ,   "function_name": "parse_execution_context_t::run_job_list(parse_node_t const&, block_t const*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 5003799
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 809495
                ,   "function_name": "parse_execution_context_t::eval_node_at_offset(unsigned int, block_t const*, io_chain_t const&)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4657813
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 463509
                ,   "function_name": "parser_t::eval_block_node(unsigned int, io_chain_t const&, block_type_t)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4658797
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 464493
                ,   "function_name": "parser_t::eval(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, io_chain_t const&, block_type_t)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4526309
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 332005
                ,   "function_name": "internal_exec_helper(parser_t&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, unsigned int, block_type_t, io_chain_t const&) [clone .constprop.117]"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4535169
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 340865
                ,   "function_name": "exec_job(parser_t&, job_t*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4997824
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 803520
                ,   "function_name": "parse_execution_context_t::run_1_job(parse_node_t const&, block_t const*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4998374
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 804070
                ,   "function_name": "parse_execution_context_t::run_job_list(parse_node_t const&, block_t const*)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 5003799
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 809495
                ,   "function_name": "parse_execution_context_t::eval_node_at_offset(unsigned int, block_t const*, io_chain_t const&)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4657813
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 463509
                ,   "function_name": "parser_t::eval_block_node(unsigned int, io_chain_t const&, block_type_t)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4658797
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 464493
                ,   "function_name": "parser_t::eval(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, io_chain_t const&, block_type_t)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4687575
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 493271
                ,   "function_name": "reader_run_command(parser_t&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4724620
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 530316
                ,   "function_name": "reader_read(int, io_chain_t const&)"
                ,   "file_name": "/usr/bin/fish"
                }
              , {   "address": 4348615
                ,   "build_id": "2f155eeefe0bd905cd88db964afa9469f5105de1"
                ,   "build_id_offset": 154311
                ,   "function_name": "main"
                ,   "file_name": "/usr/bin/fish"
                } ]
        } ]
}

Fish version: fish, version 2.2.0

Operating system: Fedora 22 up to date as of today

Terminal or terminal emulator: Konsole

Activity

  1. faho commented on Mar 8, 2016

    @faho
    Member

    This is a very unfortunate manifestation of #1396 - we currently buffer script output.

    Sorry!

  2. enricotagliavini commented on Mar 8, 2016

    @enricotagliavini
    Author

    Argh, and I even looked for already open bugs.... and missed it... sorry :)

  3. faho commented on Mar 8, 2016

    @faho
    Member

    Nah, it's okay. Sometimes it's hard to guess how other people would call things, and sometimes (like in this case) the phrase you're looking for ("buffer") is related to the root-cause.

  4. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions