1

I am using version 3.12.10 of Linux. I am writing a simple module that loops through the task list and checks the stack usage of each process to see if any are in danger of overflowing the stack. To get the stack limit of the process I use:

tsk->signal->rlim[ RLIMIT_STACK ].rlim_cur

To get the memory address for the start of the stack I use:

tsk->mm->start_stack

I then subract from it the result of this macro:

KSTK_ESP( tsk )

Most of the time this seems to work just fine, but on occasion I a situation where a process uses more than its stack limit ( usually 8 MB ), but the process continues to run and Linux itself is not reporting any sort of issue.

My question is, am I using the right variables to check this stack usage?

Barmar
  • 741,623
  • 53
  • 500
  • 612
tpotter01
  • 79
  • 9

1 Answers1

0

After doing more research I think I have realized that this is not a good way of determining how much stack was used. The problem arises when the kernel allocates more pages of memory to the stack for that process. Those pages may not be contiguous to the other pages. Thus the current stack pointer may be some value that would result in an invalid calculation.

The value in task->mm->stack_vm can be used to determine how much space was actually allocated to a process' stack. This is not as accurate as how much is actually used, but for my use, good enough.

tpotter01
  • 79
  • 9