Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp54891pja; Fri, 22 Nov 2019 03:22:35 -0800 (PST) X-Google-Smtp-Source: APXvYqxEsLjxoECMg8i3HeeC+dTGqQRmtML9Kz8pQptpJdxP+mSr3EUb986WbL5vug6BVog2ls61 X-Received: by 2002:a17:906:7f8a:: with SMTP id f10mr22162202ejr.209.1574421755275; Fri, 22 Nov 2019 03:22:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421755; cv=none; d=google.com; s=arc-20160816; b=Llas/YCA3uPgEp3yAeOZk5CLH3xDWq6cnwG7f59jqTSDeXdy+5u8bQfbFKlqESEjqz 2cpu8tZCivwVlX9z9XEByx0pMbNfNREbJFMgLe40VDSm5aLZZRhqBi72/aR9ncQVS8Nl QBg3V6lTVeo1k4pV4wJBp+/wXA9rOpy68amcc3nev8LUKa0i1BhyYYgZD5QmX5apVa5G NGiv8IMl0dJCD+LIlKLIrETVC+GOnBIixrSCxqTwcIexyTP30Lt25NzvrBmFCxdh+PSK dxPb88yorc3HAoLiOBTifeu7/taVFOPbwB+0ZC6q9Ov/FpUqsO+FSjgBYA50OKsVl5IL k6MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=5gF2k2LHuNaWv2KSjHBKmMkFE7+VekYpQOAgB7bChvY=; b=ihuFdY8hY0w0edJ/RiPGbOICVRD0glJoe+n92BP49iO+v2SwSlGCWAOtpCWgJGNf1O kw4cDPepek7IiU7zw39bBXCyIfB1FqGUtYbFCsRr92IxJaC3+SYqk/3UFSjvR5Z5+qHy schBdvxTJmswAdkdADPM026nIcuKJHpU51NUFUbzr803jZSjkWJ8P/uP+qoDLBIxJgVt +Tg8/jQvknLe5oQ+K7rL3m/KBYQXcH91KQK3hdHTBbhz7gNe1Y4Gsh+5pmXMfHJXlYQE pHdy4skxk9uD/qGNieVzIv41UtlrRIaxFNIHhzQ9QPRYwP2rT+BOU8ew/AcleQ+IV327 n70g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q24si4124600eju.127.2019.11.22.03.22.11; Fri, 22 Nov 2019 03:22:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730559AbfKVLR6 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 22 Nov 2019 06:17:58 -0500 Received: from eu-smtp-delivery-151.mimecast.com ([146.101.78.151]:57895 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728221AbfKVLR4 (ORCPT ); Fri, 22 Nov 2019 06:17:56 -0500 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-67-7umQ3wvKPsm7jLHIlIOsjw-1; Fri, 22 Nov 2019 11:17:52 +0000 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 22 Nov 2019 11:17:51 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Fri, 22 Nov 2019 11:17:51 +0000 From: David Laight To: linux-kernel CC: network dev Subject: epoll_wait() performance Thread-Topic: epoll_wait() performance Thread-Index: AdWgk3jgEIFNwcnRS6+4A+/jFPxTuQ== Date: Fri, 22 Nov 2019 11:17:51 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-MC-Unique: 7umQ3wvKPsm7jLHIlIOsjw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I'm trying to optimise some code that reads UDP messages (RTP and RTCP) from a lot of sockets. The 'normal' data pattern is that there is no data on half the sockets (RTCP) and one message every 20ms on the others (RTP). However there can be more than one message on each socket, and they all need to be read. Since the code processing the data runs every 10ms, the message receiving code also runs every 10ms (a massive gain when using poll()). While using recvmmsg() to read multiple messages might seem a good idea, it is much slower than recv() when there is only one message (even recvmsg() is a lot slower). (I'm not sure why the code paths are so slow, I suspect it is all the copy_from_user() and faffing with the user iov[].) So using poll() we repoll the fd after calling recv() to find is there is a second message. However the second poll has a significant performance cost (but less than using recvmmsg()). If we use epoll() in level triggered mode a second epoll_wait() call (after the recv()) will indicate that there is more data. For poll() it doesn't make much difference how many fd are supplied to each system call. The overall performance is much the same for 32, 64 or 500 (all the sockets). For epoll_wait() that isn't true. Supplying a buffer that is shorter than the list of 'ready' fds gives a massive penalty. With a buffer long enough for all the events epoll() is somewhat faster than poll(). But with a 64 entry buffer it is much slower. I've looked at the code and can't see why splicing the unread events back is expensive. I'd like to be able to change the code so that multiple threads are reading from the epoll fd. This would mean I'd have to run it in edge mode and each thread reading a smallish block of events. Any suggestions on how to efficiently read the 'unusual' additional messages from the sockets? FWIW the fastest way to read 1 RTP message every 20ms is to do non-blocking recv() every 10ms. The failing recv() is actually faster than either epoll() or two poll() actions. (Although something is needed to pick up the occasional second message.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)