Stack usage increased after increasing the task's stack size

sze3gi wrote on Monday, May 06, 2019:


I am using FreeRTOS 9.0.0. I am trying to determine the stack usage of my tasks and during this I ran into the following problem.

When I increase the stack of the task, it starts to use more stack. For example when the stack size was 100 (words - 32 bit) the uxTaskGetStackHighWaterMark returned 56, meaning that the task uses 56 bytes of stack at maximum. Then I increased the stack size to 160 words and a uxTaskGetStackHighWaterMark returned 126, meaning that the stack usage doubled! I ran the same test code in both cases, the only difference between the to cases is the stack size of the task. No stackoverflow occured, because i did not ran into the stackoverflow hook, which was enabled the whole time. I am using STM32F030F4. How is this possible?


rtel wrote on Monday, May 06, 2019:

When the stack was 100 words the high water mark was 56 words, so 44
words had actually been used. When the stack is 160 words the high
water mark was 126 words, so 34 words had been used. Seems the stack
usage had gone down a little, but as the stack size makes no difference
to how the compiler uses the stack I’m assuming that is because you had
not gone through which ever path was using that last 10 words before
checking the high water mark.