GUI Memory x Meminfo

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

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:

RMerlin

Asuswrt-Merlin dev
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.
 

Markfree

Regular Contributor
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:

RMerlin

Asuswrt-Merlin dev
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;
                }
        }
 

Markfree

Regular Contributor
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")?
 

RMerlin

Asuswrt-Merlin dev
That was just below the code that I pasted (I didn't paste the whole function):

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

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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