This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Too much memory for system

Other Parts Discussed in Thread: TVP7002

Hi,

I'm trying to increase the total memory available to apps running on DM365 board, but beside working with CMEM I've found that the Kernel is the major source of memory usage. After a clean boot of the board (no apps runing, minimal services), free says:

              total         used         free       shared      buffers
  Mem:        78272        44628        33644            0            0
 Swap:            0            0            0
Total:        78272        44628        33644

 

I'd like to know what's using 44Mb of the 78 available... Most probably it's the kernel, but isn't it a bit too much?

Considering that by default 80Mb are free for linux and 44 are used up by "something", this means that of 128MB on the board only 33Mb are usable by an app. It seems a bit too much to me.

 

  • This seems fairly normal though you can get it down to less I am sure, one thing to try is run 'ps -A v' to give a list of processes with how much memory they are using to see if you can free up any from processes that may have unknowingly started, as well as 'cat /proc/meminfo' to get more detailed statistics on memory usage. For the kernel allocated memory you can go into your kernel build options and start removing drivers and features you are not using, this should lower the size of your end binary and the amount of memory that the kernel takes in dynamic allocation, generally a production kernel for an embedded system like this will be far more stripped down than the out of the box kernel used on the EVM.

  • Hi bernie,

    I've done some tests and I think instead that there is NO space for improvement. Please follow me, sorry for the long post.

    First of all, I've configured the root file system to load almost nothing. So at boot there is only Kernel, init, and the shell.

    Then I've built a "BASIC" kernel, with most of the drivers built as modules (and not loaded during boot) and only the minimal drivers required for our project: DAVINCI MUX, MTD, ETHERNET, IPIPE, RESIZER, I2C, V4L, TVP7002 CAPTURE, FRAME BUFFER, SOUND, REALTIME CLOCK, JFFS2, SERIAL.

    The result is this:

    # free
                  total         used         free       shared      buffers
      Mem:        78688        43396        35292            0            0
     Swap:            0            0            0
    Total:        78688        43396        35292

    As you see, still 43Mb of memory used basically by the kernel. We can't remove anything else, since we really need those devices for our project. I've reduced the kernel memory by 2Mb, but I suppose that when I'll load the modules that were in the kernel, used mem will increase by 2Mb (we also reuire PWM, MMC support, etc).

    So the bad point is that there are no more feature we can remove, also this config is not so full of fancy useless stuff. This is the minimum we require.

    Don't you think that 35Mb remaining out of 128Mb on the system are a bit too much? After some tests I've found that V4L CAPTURE (via VPFE) requires 15Mb, V4L DISPLAY (via VPBE) requires another 15Mb and FB the last 7Mb. 37Mb out of a total of 43Mb.

    If someone sees another way to increase free memory, I'm open to any advice.

    Thanks!

     

    If you want to read on, here follow the details.

    This is the result of PS after completing the boot. No process are running, only init and shell.

    # ps
      PID USER       VSZ STAT COMMAND
        1 root      1976 S    init
        2 root         0 SW   [posix_cpu_timer]
        3 root         0 SW   [softirq-high/0]
        4 root         0 SW   [softirq-timer/0]
        5 root         0 SW   [softirq-net-tx/]
        6 root         0 SW   [softirq-net-rx/]
        7 root         0 SW   [softirq-block/0]
        8 root         0 SW   [softirq-tasklet]
        9 root         0 SW   [softirq-hrtimer]
       10 root         0 SW   [softirq-rcu/0]
       11 root         0 SW<  [desched/0]
       12 root         0 SW<  [events/0]
       13 root         0 SW<  [khelper]
       14 root         0 SW<  [kthread]
       25 root         0 SW<  [kblockd/0]
       26 root         0 SW<  [kseriod]
       35 root         0 SW<  [khubd]
       78 root         0 SW   [pdflush]
       79 root         0 SW   [pdflush]
       80 root         0 SW<  [kswapd0]
       81 root         0 SW<  [aio/0]
      118 root         0 SW   [mtdblockd]
      289 root         0 SWN  [jffs2_gcd_mtd7]
      337 root      2324 S    -sh
      344 root      2324 R    ps

    I've decided to find out where is all this memory really used. I've built a really stripped down kernel, with only the bare minimum for boot: MTD, JFFS2, SERIAL. I've had to include I2C support too, even if not strictly required for boot, since DaVinci DM365 platrform config won't compile without I2C (i consider this a thing to be fixed, but did not affect the test).

    The result is this:

    # free
                  total         used         free       shared      buffers
      Mem:        79776         4348        75428            0            0
     Swap:            0            0            0
    Total:        79776         4348        75428

    As you see, only 4MB are used by the system, so this confirm that the source of the problem is actually one of the drivers we load in the "BASIC" kernel. I've then tried to add one driver at a time, compile and test the memory with that kernel. Basically most of the drivers do not impact the memory usage. Skipping some passages:

    I2C, MTD, JFFS2, SERIAL, DAVINCI MUX, IP NETWORK, ETHERNET, SCSI SUPPORT, SMB, CIFS, INOTIFY, REALTIME CLOCK, MMC, USB, SPI, PWM, WATCHDOG, HWRANDOM (some as modules, as in "BASIC")

    # free
                  total         used         free       shared      buffers
      Mem:        79124         4996        74128            0            0
     Swap:            0            0            0
    Total:        79124         4996        74128

    As you see there is no major impact on memory usage. So the cause must be one of the TI drivers for VIDEO IN, VIDEO OUT, or AUDIO.

    Let's start with ALSA AUDIO support:

    # free
                  total         used         free       shared      buffers
      Mem:        78976         5292        73684            0            0
     Swap:            0            0            0
    Total:        78976         5292        73684

    Still an increase, but nothing to worry about. Now,  +IPIPE+RESIZER (no PREVIEWER):

    # free
                  total         used         free       shared      buffers
      Mem:        78900         5256        73644            0            0
     Swap:            0            0            0
    Total:        78900         5256        73644

    No differences. +V4L CAPTURE):

    # free
                  total         used         free       shared      buffers
      Mem:        78792        29840        48952            0            0
     Swap:            0            0            0
    Total:        78792        29840        48952

    The memory usage increased by 15Mb. +V4L DISPLAY (DAVINCI BACKEND + ENCODER MANAGER (1ch)):

    # free
                  total         used         free       shared      buffers
      Mem:        78728        36068        42660            0            0
     Swap:            0            0            0
    Total:        78728        36068        42660

    Again an increase of 15Mb. Then adding the last FRAMEBUFFER DRIVER:

    # free
                  total         used         free       shared      buffers
      Mem:        78688        43408        35280            0            0
     Swap:            0            0            0
    Total:        78688        43408        35280

    So this takes the last 7Mb.

    So basically VPFE + VPBE + FB = 37Mb required.

     

  • You have made some good analysis here, and this makes sense in general, the video related drivers tend to require large segments of physically contiguous memory which is best allocated at boot to ensure it is available, so it is not suprising that they end up being the bulk of your kernel owned space.

    Which kernel/PSP version are you using? You may want to consult the video driver documentation for your version to see what can be done to lessen the amount of allocation going to the video drivers, in the worst case you would have to do some digging through the source and modify how much space is being allocated.