pastebin - collaborative debugging tool
tmux.kpaste.net RSS


improvement?
Posted by Anonymous on Sat 17th Jan 2015 23:19
raw | new post
modification of post by Anonymous (view diff)

  1. 20150113.21:13:21        wim | hi guys, after using tmux for a while it seems like it's using quite some memory (using 1.9a).
  2. 20150113.21:13:44        wim | 128Mb at the moment for 8 windows
  3. 20150113.21:14:31        wim | memory leak?
  4.  
  5. 20150114.00:47:03       nicm | tmux returns memory to libc and is reliant on it to return it to the kernel
  6. 20150114.00:47:14       nicm | glibc does not do so very aggressively
  7. 20150114.00:47:19       nicm | this is a common issue on linux
  8. 20150114.00:47:48       nicm | there is a library call you can put into tmux if you want it to be returned more quickly
  9. 20150114.00:48:32       nicm | malloc_trim(3)
  10. 20150114.00:50:08       nicm | add malloc_trim(0) somewhere, server_second_callback in server.c would be a good place, or grid_destroy in grid.c
  11. 20150114.00:50:24       nicm | or just live with it and assume glibc knows best
  12. 20150114.00:51:23       nicm | i believe OS X is similar, if not worse, although it has different ways to reclaim the memory, i think it is kernel-side there
  13.  
  14. 20150114.01:05:47        wim | nicm: nice! malloc_trim(0) works
  15.  
  16. 20150114.01:11:55  freeroute | wim: are you running Linux? How did you get it working? Just add to source code?
  17. 20150114.01:12:12        wim | freeroute: yes and yes
  18. 20150114.01:12:35        wim | in grid_destroy()
  19. 20150114.01:12:35        wim |     free(gd);
  20. 20150114.01:12:35        wim |     malloc_trim(0);
  21. 20150114.01:12:45        wim | add it under the last free
  22. 20150114.01:14:41        wim | would be nice if it got into the code though :/
  23.  
  24.  
  25. ================================================================================================================================
  26.  
  27. So basically, in tmux/grid.c - you want it to look like this:
  28.  
  29. /* Destroy grid. */
  30. void
  31. grid_destroy(struct grid *gd)
  32. {
  33.         struct grid_line        *gl;
  34.         u_int                    yy;
  35.  
  36.         for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
  37.                 gl = &gd->linedata[yy];
  38.                 free(gl->celldata);
  39.         }
  40.  
  41.         free(gd->linedata);
  42.  
  43.         free(gd);
  44.         malloc_trim(0);
  45. }
  46.  
  47. ================================================================================================================================
  48.  
  49. :(
  50.  
  51. 20150117.22:21:01        wim | nicm: is this something that could be merged? makes it portable? the malloc_trim thing -
  52.                              | https://github.com/42wim/tmux/commit/429fc7a7498ca39c5210b26d4e541e8d6969db3a
  53. 20150117.22:24:42  freeroute | wim: does the code say like "If this is going to get compiled by glibc, then also include this code" and by 'this code' I mean that malloc_trim thing.
  54. 20150117.22:26:10  freeroute | if so then that means I can read C :D
  55. 20150117.22:26:59        wim | that's the gist of it yes
  56. 20150117.22:45:40       nicm | not really
  57. 20150117.22:46:45       nicm | it's up to glibc how malloc works really
  58. 20150117.22:52:26        wim | nicm: no power to the people instead of letting the system decide ? :-)
  59. 20150117.22:53:46        wim | nicm: i tried fiddling with the environment variables, but didn't get it to work as well as malloc_trim()
  60. 20150117.22:55:48       nicm | you need to talk to the glibc folks if their environment vars don't work
  61. 20150117.22:57:26       nicm | i don't think we should do this in the code
  62. 20150117.22:58:47        wim | ok thanks, was worth a try

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at