ports/165361: x11-wm/e17-module-mem counts memory incorrectly
Volodymyr Kostyrko
c.kworr at gmail.com
Tue Feb 21 13:50:10 UTC 2012
>Number: 165361
>Category: ports
>Synopsis: x11-wm/e17-module-mem counts memory incorrectly
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Feb 21 13:50:10 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator: Volodymyr Kostyrko
>Release: RELENG_9
>Organization:
None
>Environment:
FreeBSD green.tandem.local 9.0-STABLE FreeBSD 9.0-STABLE #0 r231929: Mon Feb 20 12:00:55 EET 2012 arcade at green.tandem.local:/usr/obj/usr/src/sys/MINIMAL_4BSD amd64
>Description:
Enlightenment indeed has very small footprint, but when I have big swap or memory (bigger then signed int) this modules draws junk.
I composed a small patch which changes how the module sees things. I don't think it's final because for me it's just works. While we can settle on a more simple way of dealing with things without counting just any single byte, like:
#define PAGES_PER_MEG (1024 * 1024) / getpagesize()
int xM;
xM = some_page_count() / PAGES_PER_MEG;
This way we would count distinct megabytes and not bother with bytes. We could also skip all '>> 10' and '/ 1024' in module source. If it's 0k I can try to rewrite the sources this way.
My patch changes _only_ freebsd part of module, the linux one still needs to be cleaned up.
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
diff -ur src/e_mod_main.c src.new/e_mod_main.c
--- src/e_mod_main.c 2010-11-13 17:56:21.000000000 +0200
+++ src.new/e_mod_main.c 2012-02-21 15:33:01.000000000 +0200
@@ -415,7 +415,7 @@
{
Instance *inst;
Edje_Message_Float msg;
- int real, swap, total_real, total_swap;
+ long long real, swap, total_real, total_swap;
char real_str[100];
char swap_str[100];
@@ -424,10 +424,10 @@
if (!inst->ci->show_percent)
{
- snprintf (real_str, sizeof (real_str), "Real: %d/%d MB", (real / 1024),
+ snprintf (real_str, sizeof (real_str), "Real: %lld/%lld MB", (real / 1024),
(total_real / 1024));
if ( total_swap )
- snprintf (swap_str, sizeof (swap_str), "Swap: %d/%d MB", (swap / 1024),
+ snprintf (swap_str, sizeof (swap_str), "Swap: %lld/%lld MB", (swap / 1024),
(total_swap / 1024));
}
else
diff -ur src/e_mod_main.h src.new/e_mod_main.h
--- src/e_mod_main.h 2010-11-13 17:56:21.000000000 +0200
+++ src.new/e_mod_main.h 2012-02-21 09:39:04.000000000 +0200
@@ -34,7 +34,7 @@
void _mem_config_updated(Config_Item *ci);
void _config_mem_module(Config_Item *ci);
-void _mem_get_values(Config_Item *ci, int *real, int *swap, int *total_real, int *total_swap);
+void _mem_get_values(Config_Item *ci, long long *real, long long *swap, long long *total_real, long long *total_swap);
extern Config *mem_config;
#endif
diff -ur src/machdep_freebsd.c src.new/machdep_freebsd.c
--- src/machdep_freebsd.c 2010-11-13 17:56:21.000000000 +0200
+++ src.new/machdep_freebsd.c 2012-02-21 15:33:23.000000000 +0200
@@ -30,13 +30,13 @@
}
static int
-swapinfo (int *total, int *used)
+swapinfo (long long *total, long long *used)
{
int pagesize = getpagesize ();
size_t mibsize, size;
struct xswdev xsw;
int mib[16], n;
- int tmp_total, tmp_used;
+ long long tmp_total, tmp_used;
*total = 0;
*used = 0;
@@ -63,8 +63,8 @@
tmp_total = (long long) xsw.xsw_nblks * pagesize;
tmp_used = (long long) xsw.xsw_used * pagesize;
- *total += tmp_total;
- *used += tmp_used;
+ *total += tmp_total >> 10;
+ *used += tmp_used >> 10;
}
if (errno != ENOENT)
warn ("sysctl()");
@@ -75,10 +75,10 @@
void
_mem_get_values (ci, phys_used, sw_used, phys_total, sw_total)
Config_Item *ci;
- int *phys_used;
- int *sw_used;
- int *phys_total;
- int *sw_total;
+ long long *phys_used;
+ long long *sw_used;
+ long long *phys_total;
+ long long *sw_total;
{
int total_pages, inactive_pages, free_pages;
@@ -102,8 +102,8 @@
return;
}
- *phys_total = (total_pages * pagesize) >> 10;
- *phys_used = ((total_pages - free_pages - inactive_pages) * pagesize) >> 10;
+ *phys_total = ((long long)total_pages * pagesize) >> 10;
+ *phys_used = (((long long)total_pages - free_pages - inactive_pages) * pagesize) >> 10;
if ((swapinfo (sw_total, sw_used)) != 0)
{
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list