Dynamic memory stack?

Alex (akhripin@MIT.EDU)
Wed, 15 Jan 2003 20:04:54 -0500


Hi,
A good way to prevent memory leaks and simplify code is to reduce the use of
kmalloc for a certain class of situations. Specifically, I am referring to
blocks of code with the following:

bar(){
.
.
foo=kmallc
.
.
.
kfree(foo)
.
.
}

This sort of thing is best handled on the stack, but, of course, that has
critical flaws. A way to deal with this is to create a per-cpu kmalloc'ed
dynamically extended stack from which memory can be allocated. Then, most
allocations/deallocations are done in O(1) and memory fragmentation due to
lots of small allocation is avoided.
Furthermore, with the help of macros, memory leaks due to mid-function returns
and such can be completely avoided.
A survey of kernel code revealed a number of places where this methodology can
be applied.
-Alex Khripin
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/