mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-11 20:58:50 +03:00
o Cut down number of vmallocs to increase speed and efficiency
This commit is contained in:
parent
44206f5e75
commit
e33e89637c
@ -96,14 +96,13 @@ static int alloc_targets(struct dm_table *t, int num)
|
|||||||
offset_t *n_highs;
|
offset_t *n_highs;
|
||||||
struct target *n_targets;
|
struct target *n_targets;
|
||||||
int n = t->num_targets;
|
int n = t->num_targets;
|
||||||
|
int size = (sizeof(struct target) + sizeof(offset_t)) * num;
|
||||||
|
|
||||||
if (!(n_highs = vmalloc(sizeof(*n_highs) * num)))
|
n_highs = vmalloc(size);
|
||||||
|
if (n_highs == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (!(n_targets = vmalloc(sizeof(*n_targets) * num))) {
|
n_targets = (struct target *)(n_highs + num);
|
||||||
vfree(n_highs);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
memcpy(n_highs, t->highs, sizeof(*n_highs) * n);
|
memcpy(n_highs, t->highs, sizeof(*n_highs) * n);
|
||||||
@ -111,7 +110,6 @@ static int alloc_targets(struct dm_table *t, int num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
vfree(t->highs);
|
vfree(t->highs);
|
||||||
vfree(t->targets);
|
|
||||||
|
|
||||||
t->num_allocated = num;
|
t->num_allocated = num;
|
||||||
t->highs = n_highs;
|
t->highs = n_highs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user