After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 342338 - suffers from memory fragmentation
suffers from memory fragmentation
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
: 354324 559385 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-05-19 12:12 UTC by Benoît Dejean
Modified: 2010-01-13 19:24 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Benoît Dejean 2006-05-19 12:12:28 UTC
Hi, i'm using gnome-terminal 2.14.0 at work. I'm a sysadmin, so i usually have 20-60 tabs opened. With scrollback buffer of 5 MiB 

I started gnome-terminal 17 days ago : 

cpu usage : 63 minutes
virtual memory : 198.8 MiB
private_dirty : 53.1 MiB
heap size : 177 MiB
resident memory : 73.5 MiB

My problem is that memory gets more and more fragmented which leads to higher memory usage. As i have several too terminals opened, i'm not able to close gnome-terminal. I actually never close it. I think the problem is that buffers are not allocated at once. It really looks like each buffer line is allocated separately. That's why the heap is so big, so fragmented and that memory is never returned to the system. Moreover, closing a tab opened a long time ago (but recently used) can take up to 15s and generate a lot of disk activity (in order to free each memory chunk that got swapped i guess).

So in a perfect world, gnome-terminal (or vte, i don't know) would use a separate memory storage for each terminal buffer and would allocate big chunk of memory at once (i mean g_malloc(5MiB) if buffer size is 5MiB).

Thanks.
Comment 1 Guilherme de Siqueira Pastore 2006-05-19 19:19:00 UTC
Indeed, that's vte. Reassigning.
Comment 2 Behdad Esfahbod 2006-05-20 22:32:05 UTC
Vte uses g_array .  I don't see how this can be improved easily.  And even if you malloc one single buffer, that still will be swapped out when not used.

If you 5MiB per tab and 20..60 tabs open, I don't see how the memory usage is other than expected.
Comment 3 Benoît Dejean 2006-05-21 08:09:35 UTC
Closing terminals doesnt return any memory to the system. gnome-terminal memory usage keeps increasing with time.
Comment 4 Behdad Esfahbod 2006-05-21 08:29:32 UTC
True...  That's because g_array allocates using g_malloc... Using g_slice doesn't necessarily help, 'cause that uses memalign that is essentially same as malloc I guess.  Allocing the 5MiB straight may help, but its really hard, when you resize your terminal for example.
Comment 5 Benoît Dejean 2006-05-21 08:45:22 UTC
I never suggested using g_slice. I'm just disappointed because when i close a windows with 5 tabs, no memory is returned to the system. And i never said it would be easy :)
Comment 6 Chris Wilson 2007-01-26 00:35:03 UTC
*** Bug 354324 has been marked as a duplicate of this bug. ***
Comment 7 Chris Wilson 2007-02-05 09:54:11 UTC
We can reduce the pain slightly by managing our heap allocations better. The preferred solution to this problem, as Behdad has suggested, is to implement a custom block allocator. This has other advantages such as perhaps implementing a MVC paradigm to enable split-view and friends.


r1620: 2007-02-05  Chris Wilson  <chris@chris-wilson.co.uk>

	cf Bug 342338 – suffers from memory fragmentation

	Reuse the last VteRowData instead of immediately freeing it. Avoids
	recreating and *regrowing* a new GArray on the heap.

	In the simple scrolling benchmarks this can boost performance by as
	much as 10%!

	* src/ring.c: (_vte_ring_insert), (_vte_ring_insert_preserve),
	(_vte_ring_remove), (_vte_ring_append):
	* src/ring.h:
	* src/vte-private.h:
	* src/vte.c: (_vte_reset_row_data), (_vte_terminal_ensure_cursor),
	(_vte_terminal_insert_char), (vte_terminal_reset_rowdata):
	* src/vteseq.c: (vte_insert_line_internal),
	(vte_sequence_handler_scroll_up_or_down),
	(vte_sequence_handler_cd), (vte_sequence_handler_sf),
	(vte_sequence_handler_clear_screen),
	(vte_sequence_handler_screen_alignment_test):

Comment 8 Simone Gotti 2007-07-02 21:30:51 UTC
Hi,

konsole can handle an infinite history (quite useful sometimes) and it's really fast by using an an mmapped file as the ondisk buffer. The code is here:
http://websvn.kde.org/trunk/KDE/kdebase/apps/konsole/src/BlockArray.cpp?revision=662726&view=markup

Maybe a similar approach can be used by vte?

Thanks!
Comment 9 Mildred 2008-07-19 18:51:00 UTC
It seems that vte doesn't release memory at all when a terminal is cleared or is closed (when you close a tab for example).

One way to easily test it is to start the following command line:

hexdump </dev/urandom

On my system, memory usage increase until about 110MB (when the buffer is filled). Then it stays constant. Clearing the terminal or closing it doesn't release memory.

I don't know if this is the same bug or not, because when this command is run, all the memory is allocated in a limited time. If it's not the same bug, I'll be happy to open, a new bug report.

See this for further information: https://sourceforge.net/tracker/index.php?func=detail&aid=2021978&group_id=124080&atid=698428 (bug in roxterm)
Comment 10 Benoît Dejean 2008-07-20 09:57:46 UTC
cat -tev /dev/urandom gives even worst results.
I've resumed a sysadmin job and gnome-terminal is a great tool. About a dozen of open windows, 1-5 tabs each. The problem is less annoying than it used to be because my workstation now has 2GiB of memory (so it's not swapping), but i often see heap's size (with pmap) around 200MiB, even when i do some cleanup on friday night before leaving.
Comment 11 Behdad Esfahbod 2008-11-05 16:33:45 UTC
*** Bug 559385 has been marked as a duplicate of this bug. ***
Comment 12 Anatoly Pugachev 2008-11-06 13:13:12 UTC
why this bug still in unconfirmed state?
Comment 13 Behdad Esfahbod 2010-01-13 19:24:40 UTC
This has been completely fixed for a few months now.