Skip to contentSkip to conversation

thoughts stac/clac and get user for vhost

DISCUSSION Michael S. Tsirkin 2 participants 12 messages Dec 25, 2018 – Jan 8, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

Signature · 1 line
MST
#1 lore raw
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

Quoted 7 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#2 lore raw
Quoted 13 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

user_access_begin

 for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor

}
user_access_end

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

Quoted 7 lines
Quoted 7 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#3 lore raw
Quoted 29 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

user_access_begin

  for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
Quoted 5 lines

}
user_access_end

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#4 lore raw
Quoted 69 lines · Jason Wang
Quoted 29 lines · Michael S. Tsirkin
Quoted 11 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

user_access_begin

  for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
Quoted 5 lines

}
user_access_end

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

Quoted 8 lines

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

But my point was really fundamental - if ring accesses are expensive then we should batch them. Right now we have an API that gets an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#5 lore raw
Quoted 71 lines · Michael S. Tsirkin
Quoted 70 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

   user_access_begin
   for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
   }
   user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

Quoted 7 lines
Quoted 4 lines

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

Quoted 3 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP

2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is: for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#6 lore raw
Quoted 77 lines · Jason Wang
Quoted 75 lines · Michael S. Tsirkin
Quoted 74 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

   user_access_begin
   for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
   }
   user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

Quoted 8 lines
Quoted 3 lines

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Quoted 40 lines
Quoted 4 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#7 lore raw
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Michael S. Tsirkin
Quoted 65 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

    user_access_begin
    for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
    }
    user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

Quoted 8 lines

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

Quoted 5 lines
Quoted 3 lines

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Well, 2%-3% difference is not quite a lot.

I think it's not hard to let split ring faster have some small optimizations on the code itself.

Thanks

Quoted 36 lines
Quoted 36 lines
Quoted 4 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#8 lore raw
Quoted 82 lines · Jason Wang
Quoted 80 lines · Michael S. Tsirkin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Michael S. Tsirkin
Quoted 65 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

    user_access_begin
    for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
    }
    user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

Quoted 8 lines

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Well, 2%-3% difference is not quite a lot.

People reported a 10% gain with tiny packets, others reported more.

Again, packed ring is faster sometimes by a factor of 3x but virtio is just virtio, there's a lot going on besides just passing the buffer addresses guest to host, and a different ring layout won't help with that.

Quoted 4 lines

I think it's not hard to let split ring faster have some small optimizations on the code itself.

Thanks

Speed up the split ring support in virtio pmd in dpdk? There have been several people working on that for a while now. It seems more likely that we can speed up the newer packed ring code. E.g. things like prefetch have a much better chance to work will with the packed layout, with split one it was a wash IIRC.

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
Quoted 5 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#9 lore raw
Quoted 81 lines · Michael S. Tsirkin
Quoted 80 lines · Jason Wang
Quoted 79 lines · Michael S. Tsirkin
Quoted 78 lines · Jason Wang
Quoted 77 lines · Michael S. Tsirkin
Quoted 65 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

     user_access_begin
     for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
     }
     user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

Quoted 8 lines

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Well, 2%-3% difference is not quite a lot.

People reported a 10% gain with tiny packets, others reported more.

Good to know this, any pointer. 2%-3% is the number I got from Jens' cover letter.

Quoted 10 lines

Again, packed ring is faster sometimes by a factor of 3x but virtio is just virtio, there's a lot going on besides just passing the buffer addresses guest to host, and a different ring layout won't help with that.

Quoted 3 lines

I think it's not hard to let split ring faster have some small optimizations on the code itself.

Quoted 6 lines
Quoted 1 line

Thanks

Speed up the split ring support in virtio pmd in dpdk? There have been several people working on that for a while now. It seems more likely that we can speed up the newer packed ring code. E.g. things like prefetch have a much better chance to work will with the packed layout, with split one it was a wash IIRC.

But what happen when in order is implemented for packed ring?

I post a patch that increase 10% of PPS with less than 10 lines of code for vhost (bypass the avail ring reading). I have similar patch for dpdk but just don't have time to test it. Similar optimization could be applied to used ring for TX easily.

Thanks

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 35 lines
Quoted 4 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#10 lore raw
Quoted 89 lines · Jason Wang
Quoted 87 lines · Michael S. Tsirkin
Quoted 86 lines · Jason Wang
Quoted 84 lines · Michael S. Tsirkin
Quoted 74 lines · Jason Wang
Quoted 73 lines · Michael S. Tsirkin
Quoted 72 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

     user_access_begin
     for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
     }
     user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Well, 2%-3% difference is not quite a lot.

People reported a 10% gain with tiny packets, others reported more.

Good to know this, any pointer. 2%-3% is the number I got from Jens' cover letter.

Oh interesting. Also Jens' cover letter only from an earlier version, Jan 29. What happened between these two dates I don't know, worth investigating.

Quoted 19 lines
Quoted 11 lines

Again, packed ring is faster sometimes by a factor of 3x but virtio is just virtio, there's a lot going on besides just passing the buffer addresses guest to host, and a different ring layout won't help with that.

Quoted 3 lines

I think it's not hard to let split ring faster have some small optimizations on the code itself.

Quoted 6 lines
Quoted 1 line

Thanks

Speed up the split ring support in virtio pmd in dpdk? There have been several people working on that for a while now. It seems more likely that we can speed up the newer packed ring code. E.g. things like prefetch have a much better chance to work will with the packed layout, with split one it was a wash IIRC.

Quoted 8 lines

But what happen when in order is implemented for packed ring?

I post a patch that increase 10% of PPS with less than 10 lines of code for vhost (bypass the avail ring reading). I have similar patch for dpdk but just don't have time to test it. Similar optimization could be applied to used ring for TX easily.

Thanks

Oh I have no doubt we can speed things up with interface extensions.

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 5 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?

#11 lore raw
Quoted 88 lines · Michael S. Tsirkin
Quoted 87 lines · Jason Wang
Quoted 86 lines · Michael S. Tsirkin
Quoted 85 lines · Jason Wang
Quoted 84 lines · Michael S. Tsirkin
Quoted 74 lines · Jason Wang
Quoted 73 lines · Michael S. Tsirkin
Quoted 72 lines · Jason Wang
Quoted 31 lines · Michael S. Tsirkin
Quoted 10 lines · Jason Wang
Quoted 9 lines · Michael S. Tsirkin

Hi!
I was just wondering: packed ring batches things naturally. E.g.

user_access_begin
check descriptor valid
smp_rmb
copy descriptor
user_access_end

Quoted 9 lines

But without speculation on the descriptor (which may only work for in-order or even a violation of spec). Only one two access of a single descriptor could be batched. For split ring, we can batch more since we know how many descriptors is pending. (avail_idx - last_avail_idx).

Anything I miss?

Thanks

just check more descriptors in a loop:

      user_access_begin
      for (i = 0; i < 16; ++i) {
	 if (!descriptor valid)
		break;
	 smp_rmb
	 copy descriptor
      }
      user_access_end
Quoted 2 lines

you don't really need to know how many there are ahead of the time as you still copy them 1 by one.

So let's see the case of split ring

user_access_begin

n = avail_idx - last_avail_idx (1)

n = MIN(n, 16)

smp_rmb

read n entries from avail_ring (2)

for (i =0; i <n; i++)

    copy descriptor (3)

user_access_end

Consider for the case of heavy workload. So for packed ring, we have 32 times of userspace access and 16 times of smp_rmb()

For split ring we have

(1) 1 time

(2) 2 times at most

(3) 16 times

19 times of userspace access and 1 times of smp_rmb(). In fact 2 could be eliminated with in order. 3 could be batched completely with in order and partially when out of order.

I don't see how packed ring help here especially consider lfence on x86 is more than memory fence, it prevents speculation in fact.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks

So on x86 at least RMB is free, this is why I never bothered optimizing it out. Is smp_rmb still worth optimizing out for ARM? Does it cost more than the extra indirection in the split ring?

I don't know, but obviously, RMB has a chance to damage the performance more or less. But even on arch where the RMB is free, packed ring still does not show obvious advantage.

People do measure gains with a PMD on host+guest.
So it's a question of optimizing the packed ring implementation in Linux.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Quoted 1 line

Well, 2%-3% difference is not quite a lot.

People reported a 10% gain with tiny packets, others reported more.

Good to know this, any pointer. 2%-3% is the number I got from Jens' cover letter.

Oh interesting. Also Jens' cover letter only from an earlier version, Jan 29. What happened between these two dates I don't know, worth investigating.

Btw, the increased times of userspace memory access looks like the root cause of regression of packed ring implementation in vhost. If I manage to do some out of spec stuffs to reduce the time, packed ring will be at most as fast as split ring. I wonder whether or not it's the same case of hardware implementation consider each PCI transaction is not free.

Quoted 19 lines
Quoted 19 lines
Quoted 10 lines

Again, packed ring is faster sometimes by a factor of 3x but virtio is just virtio, there's a lot going on besides just passing the buffer addresses guest to host, and a different ring layout won't help with that.

Quoted 3 lines

I think it's not hard to let split ring faster have some small optimizations on the code itself.

Quoted 6 lines
Quoted 1 line

Thanks

Speed up the split ring support in virtio pmd in dpdk? There have been several people working on that for a while now. It seems more likely that we can speed up the newer packed ring code. E.g. things like prefetch have a much better chance to work will with the packed layout, with split one it was a wash IIRC.

But what happen when in order is implemented for packed ring?

Quoted 8 lines
Quoted 6 lines

I post a patch that increase 10% of PPS with less than 10 lines of code for vhost (bypass the avail ring reading). I have similar patch for dpdk but just don't have time to test it. Similar optimization could be applied to used ring for TX easily.

Thanks

Oh I have no doubt we can speed things up with interface extensions.

Ok, let me repost the in order series for vhost.

Thanks

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
Quoted 2 lines

But my point was really fundamental - if ring accesses are expensive then we should batch them.

I don't object the batching, the reason that they are expensive could be:

1) unnecessary overhead caused by speculation barrier and check likes SMAP
2) cache contention

So it does not conflict with the effort that I did to remove 1). My plan is:
for metadata, try to eliminate all the 1) completely. For data, we can do batch copying to amortize its effort. For avail/descriptor batching, we can try to it on top.

Quoted 9 lines

Right now we have an API that gets
an iovec directly. That limits the optimizations you can do.

The translation works like this:

ring -> valid descriptors -> iovecs

We should have APIs for each step that work in batches.

Yes.

Thanks

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

So packed layout should show the gain with this approach. That could be motivation enough to finally enable vhost packed ring support.

Thoughts?