Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tmux using 1G RAM even after clearing all scrollback history

I use tmux (in fact byobu with tmux backend) on ubuntu 14.04.

My tmux uses 1GB of memory (VIRT and RES in top) and I have already used the clear-history command.

Now my scrollback is gone but the memory usage is not going down.

This tmux was running for a long time and lots of text scrolled through it. top shows it used more than 1 hour of CPU time in total.

What could be the reason?

Could there be a memory leak?

What could I try?

I cannot restart it or do dangerous things because the session runs an experiment that takes around one week more to complete...

like image 323
peschü Avatar asked May 08 '14 07:05

peschü


People also ask

Why can’t I scroll back in tmux?

As soon as lines go out of view, they are lost. To prevent history loss, tmux implements it’s own “inner” scrollback buffer. The consequence of this is that you cannot work with tmux inner scrollback same as you usually do within your terminal.

How do I clear history in tmux?

This binds ctrl-k to the tmux clear-history command. The -n after bind makes it so you don't have to issue the tmux command prefix (ctrl-b by default). I use bash, so ctrl-l already does the equivalent of typing "clear" at the command line.

How to clear tmux history and zsh with one key combination?

How to clear both tmux history ( tmux clear-history) and zsh ( zle clear-screen) with one key combination? A common way of clearing screen is ^L, and I tried adding the following to .tmux.conf: So ^L clears the screen, and clears almost all the history, except that last one screen. A subsequent ^L clears it all.

What is scrollback buffer in tmux?

Usually terminal emulators implement scrollback buffer, so you can explore past output, when it moves out of view. tmux, like other full-screen terminal applications like vim, runs in so-called alternate screen buffer of a parent terminal. Alternate buffer has exact width and height dimensions as physical window size.


2 Answers

There seems to have been a bug in tmux, resulting in memory not being freed on a history clear.

This bug existed up to including version 1.9a, fixed in version 2.0. I'm posting this as a late answer, as version 1.9a seems to be still in use (with me at least).

https://groups.google.com/forum/#!topic/tmux-users/WiSZy6ft1As https://github.com/tmux/tmux/commit/28f23f18e9d79405a60348c4f7aeded33da9135b

like image 120
sstn Avatar answered Sep 30 '22 18:09

sstn


Since no one has answered this, I'll offer my speculation on what's happening.

tmux allocates space in memory for its history, and that memory grows as you use up more of your history. Clearing history makes it invisible, but doesn't free up the actual memory. This means that tmux can use memory up the total number of lines for each open pane, regardless of whether those panes currently contain anything in them.

This is arguably a bug, or a bad feature at best.

I don't have a solution.

like image 40
quant Avatar answered Sep 30 '22 19:09

quant