@matheusbsbs / matheus-bagliano / commits / 2c1cbec1e2
Fork 0

Use proper object allocators for unknown object nodes too

We used to use a different allocator scheme for when we didn't know the object type. That meant that objects that were created without any up-front knowledge of the type would not go through the same allocation paths as normal object allocations, and would miss out on the statistics. But perhaps more importantly than the statistics (that are useful when looking at memory usage but not much else), if we want to make the object hash tables use a denser object pointer representation, we need to make sure that they all go through the same blocking allocator. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Apr 16, 2007 at 22:10 UTC 2c1cbec1e2f0bd7b15fe5e921d287babfd91c7d3
3 files changed +24 -20
alloc.c
+20 -8
@@ -18,26 +18,38 @@
18
19 #define BLOCKING 1024
20
21 -#define DEFINE_ALLOCATOR(name) \
21 +#define DEFINE_ALLOCATOR(name, type) \
22 static unsigned int name##_allocs; \
23 struct name *alloc_##name##_node(void) \
24 { \
25 static int nr; \
26 - static struct name *block; \
26 + static type *block; \
27 + void *ret; \
28 \
29 if (!nr) { \
30 nr = BLOCKING; \
30 - block = xcalloc(BLOCKING, sizeof(struct name)); \
31 + block = xmalloc(BLOCKING * sizeof(type)); \
32 } \
33 nr--; \
34 name##_allocs++; \
34 - return block++; \
35 + ret = block++; \
36 + memset(ret, 0, sizeof(type)); \
37 + return ret; \
38 }
39
37 -DEFINE_ALLOCATOR(blob)
38 -DEFINE_ALLOCATOR(tree)
39 -DEFINE_ALLOCATOR(commit)
40 -DEFINE_ALLOCATOR(tag)
40 +union any_object {
41 + struct object object;
42 + struct blob blob;
43 + struct tree tree;
44 + struct commit commit;
45 + struct tag tag;
46 +};
47 +
48 +DEFINE_ALLOCATOR(blob, struct blob)
49 +DEFINE_ALLOCATOR(tree, struct tree)
50 +DEFINE_ALLOCATOR(commit, struct commit)
51 +DEFINE_ALLOCATOR(tag, struct tag)
52 +DEFINE_ALLOCATOR(object, union any_object)
53
54 #ifdef NO_C99_FORMAT
55 #define SZ_FMT "%u"
cache.h
+1
@@ -484,6 +484,7 @@ extern struct blob *alloc_blob_node(void);
484 extern struct tree *alloc_tree_node(void);
485 extern struct commit *alloc_commit_node(void);
486 extern struct tag *alloc_tag_node(void);
487 +extern struct object *alloc_object_node(void);
488 extern void alloc_report(void);
489
490 /* trace.c */
object.c
+3 -12
@@ -120,22 +120,13 @@ void created_object(const unsigned char *sha1, struct object *obj)
120 nr_objs++;
121 }
122
123 -union any_object {
124 - struct object object;
125 - struct commit commit;
126 - struct tree tree;
127 - struct blob blob;
128 - struct tag tag;
129 -};
130 -
123 struct object *lookup_unknown_object(const unsigned char *sha1)
124 {
125 struct object *obj = lookup_object(sha1);
126 if (!obj) {
135 - union any_object *ret = xcalloc(1, sizeof(*ret));
136 - created_object(sha1, &ret->object);
137 - ret->object.type = OBJ_NONE;
138 - return &ret->object;
127 + obj = alloc_object_node();
128 + created_object(sha1, obj);
129 + obj->type = OBJ_NONE;
130 }
131 return obj;
132 }