Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 6 Jul 2017 21:14:23 +0200
From: Markus Wichmann <>
Subject: Clever code in malloc()


since it was brought up recently, I do have a question about some code
in malloc(). Namely this line:

			if (new_size+size > RECLAIM && (new_size+size^size) > size)
				reclaim = 1;

What is that doing? I just do not get it at all. For one, I have never
seen an expression of the form a+b^b. I don't know what that is supposed
to do. I tried evaluating it for a couple of inputs but could find no
patterns. And what's it supposed to do, anyway? At that point, new_size
is the size of the chunk we originally wanted to free, and size is the
size of the chunk we are currently devouring. Other already devoured
chunks are not taken into account (that would be in final_size).

The only thing this decision will change is whether or not the central
part of the chunk will be sent to madvise(), to tell the kernel that we
won't need the memory anytime soon. Which seems to me we could do
whenever the chunk we free is large enough in the end. Or is there some
reason not to do this in all cases?

So, could someone clarify this? And maybe add an explanatory comment?


Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.