What's new

GUI Memory x Meminfo

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Markfree

Regular Contributor
I noticed that the memory information shown at the router's web GUI ("Network Map > System Status") is different from the one shown by "/proc/meminfo".
I read somewhere that the web GUI used information from "free" command, but the amounts are different as well.

GUI
1608774213043.png


Code:
# free
             total       used       free     shared    buffers     cached
Mem:        440420     240544     199876       1624       5404      43320
-/+ buffers/cache:     191820     248600
Swap:            0          0          0

Why does GUI shows total, used and free memory so different from meminfo?
How is the web GUI information is collected?

Thanks
 
Last edited:
I noticed that the memory information shown at the router's web GUI ("Network Map > System Status") is different from the one shown by "/proc/meminfo".
I read somewhere that the web GUI used information from "free" command, but the amounts are different as well.

GUI
View attachment 28759

Code:
# free
             total       used       free     shared    buffers     cached
Mem:        440420     240544     199876       1624       5404      43320
-/+ buffers/cache:     191820     248600
Swap:            0          0          0

Why does GUI shows total, used and free memory so different from meminfo?
How is the web GUI information is collected?

Thanks

meminfo doesn't consider memory reserved by the kernel to be available at all, so it only reports 430 MB instead of 512 MB as max memory. The Broadcom pool manager reserves 13% of the total memory for itself, for instance. The webui extrapolates the max memory to compensate for that.

The rest of the info is retrieved directly from the kernel's /proc/meminfo interface.
 
So, does it means that total memory shown in webui is hardcoded?

I see that meminfo's free memory data actually matches the webui data.

meminfo_with_webui.PNG


Does that means webui's Used memory data is just a subtraction, 512 - "free memory"?
 
Last edited:
So, does it means that total memory shown in webui is hardcoded?

It's rounded up to the nearest power of two.

Code:
ej_memory_usage(int eid, webs_t wp, int argc, char_t **argv){
        unsigned long total, used, mfree  /*, shared, buffers, cached, driver occupied*/;
        char buf[80];
        int from_app = 0, i = 0;
        int memSize[] = {4,8,16,32,64,128,256,512,1024};
        int length = sizeof(memSize)/4;
        unsigned long  maxSize = 0, currentSize = 0;

        from_app = check_user_agent(user_agent);
        FILE *fp = NULL;
        fp = fopen("/proc/meminfo", "r");

        if(fp == NULL)
                return -1;

        fscanf(fp, "MemTotal: %lu %s\n", &total, buf);
        fscanf(fp, "MemFree: %lu %s\n", &mfree, buf);
        fclose(fp);

        for(i=0;i<length;i++){
                currentSize = memSize[i]*1024;
                if(currentSize > total){
                        maxSize = currentSize;
                        break;
                }
        }
 
I enjoyed researching those C functions and trying to understand the code.
That was enlightning.
Thank you @RMerlin.

Just one more question...
I didn't see how "used" value is collected.
Can I assume webui's "Used" data is (512 - "mfree")?
 
That was just below the code that I pasted (I didn't paste the whole function):

Code:
        used = maxSize - mfree; // (maxSize - total) + (total -mfree)
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top