Difference between
modified post c1545de by Anonymous on Sat 17th Jan 2015 23:19
original post ee9c3 by Anonymous on Wed 14th Jan 2015 00:31
Download diff
Show
old version |
new version |
both versions
| 1 | 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 | 2 | 20150113.21:13:44 wim | 128Mb at the moment for 8 windows | |
| 3 | 3 | 20150113.21:14:31 wim | memory leak? | |
| 4 | 4 | ||
| 5 | 5 | 20150114.00:47:03 nicm | tmux returns memory to libc and is reliant on it to return it to the kernel | |
| 6 | 6 | 20150114.00:47:14 nicm | glibc does not do so very aggressively | |
| 7 | 7 | 20150114.00:47:19 nicm | this is a common issue on linux | |
| 8 | 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 | 9 | 20150114.00:48:32 nicm | malloc_trim(3) | |
| 10 | 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 | 11 | 20150114.00:50:24 nicm | or just live with it and assume glibc knows best | |
| 12 | 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 | 13 | ||
| 14 | 14 | 20150114.01:05:47 wim | nicm: nice! malloc_trim(0) works | |
| 15 | 15 | ||
| 16 | 16 | 20150114.01:11:55 freeroute | wim: are you running Linux? How did you get it working? Just add to source code? | |
| 17 | 17 | 20150114.01:12:12 wim | freeroute: yes and yes | |
| 18 | 18 | 20150114.01:12:35 wim | in grid_destroy() | |
| 19 | 19 | 20150114.01:12:35 wim | free(gd); | |
| 20 | 20 | 20150114.01:12:35 wim | malloc_trim(0); | |
| 21 | 21 | 20150114.01:12:45 wim | add it under the last free | |
| 22 | 22 | 20150114.01:14:41 wim | would be nice if it got into the code though :/ | |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ================================================================================================================================ | |
| 26 | 26 | ||
| 27 | 27 | So basically, in tmux/grid.c - you want it to look like this: | |
| 28 | 28 | ||
| 29 | 29 | /* Destroy grid. */ | |
| 30 | 30 | void | |
| 31 | 31 | grid_destroy(struct grid *gd) | |
| 32 | 32 | { | |
| 33 | 33 | struct grid_line *gl; | |
| 34 | 34 | u_int yy; | |
| 35 | 35 | ||
| 36 | 36 | for (yy = 0; yy < gd->hsize + gd->sy; yy++) { | |
| 37 | 37 | gl = &gd->linedata[yy]; | |
| 38 | 38 | free(gl->celldata); | |
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | 41 | free(gd->linedata); | |
| 42 | 42 | ||
| 43 | 43 | free(gd); | |
| 44 | 44 | malloc_trim(0); | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | - | ||
| 47 | + | ================================================================================================================================ | |
| 48 | 48 | ||
| 49 | - | ||
| 49 | + | :( | |
| 50 | 50 | ||
| 51 | - | ||
| 51 | + | 20150117.22:21:01 wim | nicm: is this something that could be merged? makes it portable? the malloc_trim thing - | |
| 52 | - | ||
| 52 | + | | https://github.com/42wim/tmux/commit/429fc7a7498ca39c5210b26d4e541e8d6969db3a | |
| 53 | - | ||
| 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 | - | ||
| 54 | + | 20150117.22:26:10 freeroute | if so then that means I can read C :D | |
| 55 | - | ||
| 55 | + | 20150117.22:26:59 wim | that's the gist of it yes | |
| 56 | - | ||
| 56 | + | 20150117.22:45:40 nicm | not really | |
| 57 | - | ||
| 57 | + | 20150117.22:46:45 nicm | it's up to glibc how malloc works really | |
| 58 | - | ||
| 58 | + | 20150117.22:52:26 wim | nicm: no power to the people instead of letting the system decide ? :-) | |
| 59 | - | ||
| 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 | - | ||
| 60 | + | 20150117.22:55:48 nicm | you need to talk to the glibc folks if their environment vars don't work | |
| 61 | - | ||
| 61 | + | 20150117.22:57:26 nicm | i don't think we should do this in the code | |
| 62 | - | ||
| 62 | + | 20150117.22:58:47 wim | ok thanks, was worth a try | |
| 63 | 63 |
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.
tmux.kpaste.net RSS