kmalloc() and kfree()

6 views
Skip to first unread message

thematrixeatsyou

unread,
Nov 6, 2006, 2:11:45 PM11/6/06
to AWOS-devel
Hey, I think I might know the problem with your kmalloc() and kfree()
code.

Discussing my own malloc()/free() system with Awilcox on IRC last
night, I made a mention that my code actually allocates a chunk of
memory to put the malloc ID blocks. I was wondering, does the current
code do this? Because if the head and freehead blocks aren't allocated,
then any memory allocations may overwrite the head and freehead blocks,
and who knows what would happen?

Andrew Wilcox [maintainer]

unread,
Nov 6, 2006, 5:58:00 PM11/6/06
to AWOS-devel
thematrixeatsyou wrote:
> Hey, I think I might know the problem with your kmalloc() and kfree()
> code.
Really!?

> Discussing my own malloc()/free() system with Awilcox on IRC last
> night

You may call me Andrew.

>, I made a mention that my code actually allocates a chunk of
> memory to put the malloc ID blocks. I was wondering, does the current
> code do this?

Not in so many words, but yes.


> Because if the head and freehead blocks aren't allocated,
> then any memory allocations may overwrite the head and freehead blocks,
> and who knows what would happen?

Okay I believe I know what you're talking about.

The blocks are part of the allocation. One of the first things you'll
see if you look at the code is:

size += sizeof(struct freehead);

So it is part of the entire allocation. e.g. That's why when I
allocate 512 bytes, it says size = 528.

Best regards,

Andrew

Reply all
Reply to author
Forward
0 new messages