In this post , we will see how to Fix Kafka Error - "failed; error='Cannot allocate memory' " or memory allocation error. At times when we restart Kafka application, it throws an error which looks like somewhat below in the the screen -
failed; error='Cannot allocate memory'
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::**commit_memory**(0x00007f4fe5cc0000, **65536**, 1) failed; error='Cannot allocate memory' (errno=12)
[thread 139980200949504 also had an error]
First thing first, note the highlighted info in the error messages. It has the clue for the issue. It is a memory exception which happens due to two reasons -
sysctl vm.max_map_count
Or you can also use
cat /proc/[kafka-pid]/maps | wc -l
vm.max_map_count=<MODIFIED_VALUE>
and then run to save & apply the changes.
sysctl -p
sysctl -w vm.max_map_count=<MODIFIED_VALUE>
Note : This is an OS-level exception and hence you would need to perform this step in each of the Kafka Brokers. Hope this helps you to fix the Kafka Restart error.
Other Interesting Reads -