-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce stack usage for recursive traverse_visitbp()
Due to limited stack space recursive functions are frowned upon in the Linux kernel. However, they often are the most elegant solution to a problem. The following code preserves the recursive function traverse_visitbp() but moves the local variables AND function arguments to the heap to minimize the stack frame size. Enough space is initially allocated on the stack for 20 levels of recursion. This change does ugly-up-the-code but it reduces the worst case usage from roughly 4160 bytes to 960 bytes on x86_64 archs.
- Loading branch information
1 parent
428870f
commit 34229a2
Showing
3 changed files
with
193 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
From: Brian Behlendorf <[email protected]> | ||
Subject: [PATCH] fix stack traverse_visitbp | ||
|
||
Due to limited stack space recursive functions are frowned upon in | ||
the Linux kernel. However, they often are the most elegant solution | ||
to a problem. The following code preserves the recursive function | ||
traverse_visitbp() but moves the local variables AND function | ||
arguments to the heap to minimize the stack frame size. Enough | ||
space is initially allocated on the stack for 20 levels of recursion. | ||
This change does ugly-up-the-code but it reduces the worst case | ||
usage from roughly 4160 bytes to 960 bytes on x86_64 archs. | ||
|
||
Signed-off-by: Brian Behlendorf <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters