0

I have a device driver which requires 500MB of continuous kmalloc memory during init. The driver loads during the boot time and I have verified using free command that there is enough memory available at that time. But, sometimes I am not able to get the 500MB of memory.

Is there any command/way in linux to know how much of continuous memory is available at a certain time in system.

/proc/buddyinfo shows the amount of memory in each block but it never says whether the blocks are continuous or not.

lokesharo
  • 305
  • 2
  • 11
  • 1
    Well, if `kmalloc(500MB, ...)` returns NULL, that means that there are no continuous block of 500MB available on this system. Why do you need to first check if it is available and then allocate? What if the memory becomes unavailable between the check and allocation? You just allocate 500MB of memory. We can check if 500MB of memory is available by allocating it and then freeing, but that is soo expensive. I wonder, why (how?) kmalloc let you allocate more then PAGE_SIZE. Shouldn't you use `alloc_pages()` for big chunks of memory? – KamilCuk Jul 02 '18 at 10:12
  • 1
    Out of morbid curiosity, why do you need 500MB for a driver? Typically drivers try to operate with less memory, not more memory. – jww Jul 02 '18 at 10:48
  • On a system with mmu mostly all memory is "linear" if you want. I am wrong? – Klaus Jul 02 '18 at 11:10
  • @jww memory is required to register with the network adapter. – lokesharo Jul 02 '18 at 12:15
  • @KamilCuk During system init, we have entire RAM unused. We expect that we should get 500MB of free memory, I just want to know are there any reasons for a 64G system to not have 500MB continuous memory. – lokesharo Jul 02 '18 at 12:18
  • "System init" is in the `start_kernel()` function or after the init process is started? Cause we can write the init process to be an endless allocating bash loop. How do you allocate that memory? What flags do you pass to kmalloc? I think kmalloc is limited to the first 1GB of memory (I can't find a good source for that statement, I am not sure, for example first point [here](https://www.linuxjournal.com/article/6930)), so it shouldn't matter how memory you have if it's over 1000 Mb. – KamilCuk Jul 02 '18 at 12:49

0 Answers0