Re: I'm a total push-over..

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Friday, January 25, 2008 - 9:24 am

On Thu, 24 Jan 2008, Junio C Hamano wrote:

Good point, although we actually do things wrong for *another* reason.

We currently force cache_entry to be 8-byte aligned regardless of what the 
actual "sizeof(ptr)" is, so we should assume that alignment:

	#define cache_entry_size(len) ((offsetof(struct cache_entry,name) + (len) + 8) & ~7)

and if that isn't correct, we'd need to change this #define.

So right now, the right thing to do is probably to make this alignment 
explicit:

	#define CE_ALIGN 8

and then use that both in the "cache_entry_size()" _and_ in the 
"estimate_cache_size()" calculations to make it obvious what the alignment 
is.

And then we could actually make the alignment less on architectures that 
don't need that much (there may be architectures that need more, but I 
doubt it: we don't have any large fields in that structure, so the 
structure alignment really probably does max out at 8 in practice even if 
the C language theory doesn't give you any such guarantees).

Side note: this is not likely to be a problem in _practice_. The on-disk 
representation is also aligned (also by 8), and while they can be 
*differently* aligned due to the relative alignment of the varying-length 
"name[]" field, and that can cause some padding to be needed, in practice 
it will never matter. The on-disk size also contains a header that we 
don't take into account, so it's already "over-estimated" to begin with 
for the in-memory representation.

So "estimate_cache_size()" really does over-estimate its needs by a 
biggish amount, which is why it all works regardless, but better safe than 
sorry. 

		Linus
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
I'm a total push-over.., Linus Torvalds, (Tue Jan 22, 4:37 pm)
Re: I'm a total push-over.., Kevin Ballard, (Tue Jan 22, 6:35 pm)
Re: I'm a total push-over.., Junio C Hamano, (Tue Jan 22, 7:23 pm)
Re: I'm a total push-over.., Junio C Hamano, (Tue Jan 22, 7:36 pm)
Re: I'm a total push-over.., Linus Torvalds, (Tue Jan 22, 7:58 pm)
Re: I'm a total push-over.., Linus Torvalds, (Tue Jan 22, 8:19 pm)
Re: I'm a total push-over.., Junio C Hamano, (Wed Jan 23, 12:23 am)
Re: I'm a total push-over.., Andreas Ericsson, (Wed Jan 23, 1:32 am)
Re: I'm a total push-over.., Dmitry Potapov, (Wed Jan 23, 2:15 am)
Re: I'm a total push-over.., Andreas Ericsson, (Wed Jan 23, 2:31 am)
Re: I'm a total push-over.., Johannes Schindelin, (Wed Jan 23, 5:24 am)
Re: I'm a total push-over.., Johannes Schindelin, (Wed Jan 23, 5:25 am)
Re: I'm a total push-over.., David Kastrup, (Wed Jan 23, 5:28 am)
Re: I'm a total push-over.., Theodore Tso, (Wed Jan 23, 5:56 am)
Re: I'm a total push-over.., Marko Kreen, (Wed Jan 23, 7:01 am)
Re: I'm a total push-over.., Andreas Ericsson, (Wed Jan 23, 7:39 am)
Re: I'm a total push-over.., Linus Torvalds, (Wed Jan 23, 9:06 am)
Re: I'm a total push-over.., Linus Torvalds, (Wed Jan 23, 9:25 am)
Re: I'm a total push-over.., Johannes Schindelin, (Wed Jan 23, 9:34 am)
Re: I'm a total push-over.., Linus Torvalds, (Wed Jan 23, 10:09 am)
Re: I'm a total push-over.., Dmitry Potapov, (Wed Jan 23, 10:10 am)
Re: I'm a total push-over.., Linus Torvalds, (Wed Jan 23, 10:29 am)
Re: I'm a total push-over.., Luke Lu, (Wed Jan 23, 11:51 pm)
Re: I'm a total push-over.., Andreas Ericsson, (Thu Jan 24, 3:24 am)
Re: I'm a total push-over.., Andreas Ericsson, (Thu Jan 24, 3:39 am)
Re: I'm a total push-over.., Marko Kreen, (Thu Jan 24, 6:19 am)
Re: I'm a total push-over.., Andreas Ericsson, (Thu Jan 24, 9:00 am)
Re: I'm a total push-over.., Marko Kreen, (Thu Jan 24, 9:13 am)
Re: I'm a total push-over.., Dmitry Potapov, (Thu Jan 24, 9:28 am)
Re: I'm a total push-over.., Linus Torvalds, (Thu Jan 24, 10:15 am)
Re: I'm a total push-over.., Dmitry Potapov, (Thu Jan 24, 11:45 am)
Re: I'm a total push-over.., Linus Torvalds, (Thu Jan 24, 12:08 pm)
Re: I'm a total push-over.., Jeremy Maitin-Shepard, (Thu Jan 24, 10:21 pm)
Re: I'm a total push-over.., Junio C Hamano, (Thu Jan 24, 11:50 pm)
Re: I'm a total push-over.., Johannes Schindelin, (Fri Jan 25, 5:51 am)
Re: I'm a total push-over.., Linus Torvalds, (Fri Jan 25, 9:24 am)
Re: I'm a total push-over.., Jeremy Maitin-Shepard, (Fri Jan 25, 11:19 am)
Re: I'm a total push-over.., Johannes Schindelin, (Fri Jan 25, 11:24 am)
Re: I'm a total push-over.., Junio C Hamano, (Fri Jan 25, 12:07 pm)
Re: I'm a total push-over.., Marko Kreen, (Fri Jan 25, 1:08 pm)
Re: I'm a total push-over.., Marko Kreen, (Fri Jan 25, 1:52 pm)
Re: I'm a total push-over.., Linus Torvalds, (Fri Jan 25, 3:16 pm)
Re: I'm a total push-over.., Linus Torvalds, (Fri Jan 25, 3:35 pm)
Re: I'm a total push-over.., Marko Kreen, (Sat Jan 26, 5:16 am)
Re: I'm a total push-over.., Marko Kreen, (Sat Jan 26, 5:37 am)
Re: I'm a total push-over.., Linus Torvalds, (Sat Jan 26, 11:51 pm)
Re: I'm a total push-over.., Dmitry Potapov, (Sun Jan 27, 1:21 am)
Re: I'm a total push-over.., Marko Kreen, (Sun Jan 27, 2:45 am)
Re: I'm a total push-over.., Johannes Schindelin, (Sun Jan 27, 7:07 am)
Re: I'm a total push-over.., Dmitry Potapov, (Sun Jan 27, 7:48 am)
Re: I'm a total push-over.., Dmitry Potapov, (Sun Jan 27, 8:06 am)