I am writing a P4 program on an Ubuntu virtual machine in VMware, with 8.5GB of allocated memory and an 8-core CPU. Since my program is quite large, I encountered the error “Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS” during compilation. Apart from increasing the virtual machine’s memory, are there any other ways to resolve this issue?
Have you run a program like top
in a separate terminal while trying to compile your P4 program, and verified that some P4 compiler process like p4c-bm2-ss
is using multiple GBytes of RESident memory before this error occurs? Or is it some other process using a lot of memory?
If it is the P4 compiler, you say your P4 program is “quite large”. Could you usefully, or at least as an experiment, create a copy of the program and delete or comment out a large chunk of it to see if it compiles with the amount of memory your system has now?
What is the output of p4c --version
on your system? I ask because during the past 6-12 months several P4 compiler developers have been working on changes to speed up the compiler and enable it to use less memory than older versions. Trying out the most recent version, e.g something built from source code from today or any time during the last month, might help reduce the memory required.
All of that said, if you are using the latest version of the P4 compiler, and you need everything in your large program, I have seen some evidence that the error message you are seeing might be due to the GC library used by the P4 compiler needing more than 8GBytes of RAM. There appear to be environment variables that can be used to increase this limit, like export GC_MAXIMUM_HEAP_SIZE=16G
that I found mentioned in an Internet search on this page: Too many heap sections: Increase MAXHINCR or MAX_HEAP_SECTS when allocating many sets · Issue #5610 · crystal-lang/crystal · GitHub
But if. you need that option to increase the RAM that the P4 compiler’s GC can use, then you would also need to run it on a system with more RAM available.
Thank you for your reply. Below are my responses to your questions:
- I ran the
top
command and found thatp4c-bm2-ss
is consuming a large amount of memory. There are no other programs competing for resources withp4c
on the system. - After commenting out some parts of the code, my P4 program can be compiled and run successfully.
- The version of the
p4c
program I am using is indeed quite outdated, as I have not updated it since downloading it last September.
Thanks again for your response. I will try using the latest version of the p4c
program. If the issue persists, I will consider allocating more memory.