Skip to content

Commit e681cc6

Browse files
Jakub Kicinskidavem330
authored andcommitted
net/tls: align non temporal copy to cache lines
Unlike normal TCP code TLS has to touch the cache lines it copies into to fill header info. On memory-heavy workloads having non temporal stores and normal accesses targeting the same cache line leads to significant overhead. Measured 3% overhead running 3600 round robin connections with additional memory heavy workload. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Dirk van der Merwe <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e7b159a commit e681cc6

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

net/tls/tls_device.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,31 @@ static int tls_do_allocation(struct sock *sk,
372372
return 0;
373373
}
374374

375+
static int tls_device_copy_data(void *addr, size_t bytes, struct iov_iter *i)
376+
{
377+
size_t pre_copy, nocache;
378+
379+
pre_copy = ~((unsigned long)addr - 1) & (SMP_CACHE_BYTES - 1);
380+
if (pre_copy) {
381+
pre_copy = min(pre_copy, bytes);
382+
if (copy_from_iter(addr, pre_copy, i) != pre_copy)
383+
return -EFAULT;
384+
bytes -= pre_copy;
385+
addr += pre_copy;
386+
}
387+
388+
nocache = round_down(bytes, SMP_CACHE_BYTES);
389+
if (copy_from_iter_nocache(addr, nocache, i) != nocache)
390+
return -EFAULT;
391+
bytes -= nocache;
392+
addr += nocache;
393+
394+
if (bytes && copy_from_iter(addr, bytes, i) != bytes)
395+
return -EFAULT;
396+
397+
return 0;
398+
}
399+
375400
static int tls_push_data(struct sock *sk,
376401
struct iov_iter *msg_iter,
377402
size_t size, int flags,
@@ -445,12 +470,10 @@ static int tls_push_data(struct sock *sk,
445470
copy = min_t(size_t, size, (pfrag->size - pfrag->offset));
446471
copy = min_t(size_t, copy, (max_open_record_len - record->len));
447472

448-
if (copy_from_iter_nocache(page_address(pfrag->page) +
449-
pfrag->offset,
450-
copy, msg_iter) != copy) {
451-
rc = -EFAULT;
473+
rc = tls_device_copy_data(page_address(pfrag->page) +
474+
pfrag->offset, copy, msg_iter);
475+
if (rc)
452476
goto handle_error;
453-
}
454477
tls_append_frag(record, pfrag, copy);
455478

456479
size -= copy;

0 commit comments

Comments
 (0)