When coding an extension to the Linux kernel(e.g. a new system call) I am going to maintain data size of which can dynamically change during runtime.
There are two alternative approaches I may take. First is allocating an initial space using kmalloc, and reallocating when necessary using krealloc. The second is allocating a large-enough space with kmalloc and never having to resize it. You may assume that I have an upper bound to my data size and "large-enough" is a well-defined value, say N. I was wondering whether there are any guidelines as to which approach one should take while coding in kernel space.
The tradeoff between the time overhead by multiple reallocations and allocating a large space is obvious, even when coding in user space. But my question asks whether there is a suggested way to go. And if there isn't any, and it depends on the specific circumstances, how large an N value should be considered as too much space, or how frequent calls to krealloc should be deemed too many, leading one to choose the other method?