mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
tap-vsockd: allocate payload separately for better alignment
Previously we allocated `sizeof(struct ring) + size`. This patch allocates `sizeof(struct ring)` and then `size` for the payload separately. Hopefully the payload will be better aligned. Signed-off-by: David Scott <dave.scott@docker.com>
This commit is contained in:
parent
3fc0d994b5
commit
370a43de83
@ -23,14 +23,18 @@ struct ring {
|
|||||||
int size; /* Maximum number of buffered bytes */
|
int size; /* Maximum number of buffered bytes */
|
||||||
pthread_cond_t c;
|
pthread_cond_t c;
|
||||||
pthread_mutex_t m;
|
pthread_mutex_t m;
|
||||||
char data[];
|
char *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ring *ring_allocate(int size)
|
struct ring *ring_allocate(int size)
|
||||||
{
|
{
|
||||||
struct ring *ring = (struct ring*)malloc(sizeof(struct ring) + size);
|
struct ring *ring = (struct ring*)malloc(sizeof(struct ring));
|
||||||
if (!ring) {
|
if (!ring) {
|
||||||
fatal("Failed to allocate ring buffer");
|
fatal("Failed to allocate ring buffer metadata");
|
||||||
|
}
|
||||||
|
ring->data = (char*)malloc(size);
|
||||||
|
if (!ring->data) {
|
||||||
|
fatal("Failed to allocate ring buffer data");
|
||||||
}
|
}
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if ((err = pthread_cond_init(&ring->c, NULL)) != 0) {
|
if ((err = pthread_cond_init(&ring->c, NULL)) != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user