Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7298442imu; Tue, 22 Jan 2019 03:48:20 -0800 (PST) X-Google-Smtp-Source: ALg8bN7mslUvJqHWYuWA9UUaJXj5dbBV9JEQZoRNYsD6UfRxbpJmTef0aeOhkly8jlulQeZXGxUl X-Received: by 2002:a63:6ecf:: with SMTP id j198mr32260773pgc.3.1548157700772; Tue, 22 Jan 2019 03:48:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548157700; cv=none; d=google.com; s=arc-20160816; b=0JrrGHPyYmjqGn6JaVeicBASQM9pkLpnoV+vzqHbMWzzTYDnlsfyPdIataZxtqO0QW Q7nk5vfqYQLN4HEjxbuXT3pnAmJk6HAeFMfFroe1mjGVXWYsYmyS8ND+e8fM/58i0Mfv GTaHIuB9uk+HOdH1kf65JUSlX0l9AsCsxyt0tyuI2ms5ppyWYssqzKLdB/aTY8QFRzT3 kysPtqVi9+UNI85UwVKqlpSn/BbD+SQjuDH3fL7UEBnMXiAbDrMTjDLzINe+TuVHXZ1/ m1P8Nk9JP9i/NRTyHUBVJ8iuj8b9c/E4DGN9voulT2oOrwVIczMVDdRjbf3uAsbwQ1Yh Bw+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version; bh=+xm27CHCIHIh0cfryVWikE02LSPT17js8SegKl+N/wQ=; b=qTI743DY1G9ioqB+L//ddL82a86+MqyyYiOOk2xACgBzCQyfBs6zwwhexTkyeL5ob1 F7Xmd70ulbK8DgrgLd8SfQNxctMsCK9cgE1sUN0vcg5EP0nwloN0XlCYxszB2mhkFieA oe13jDCTkINoCROXQoXmuUR/1dEJmGddV5dUJA5efWzAS664kDJM9wCwQ1yvXTcv4kAQ 9sOnYVSWUgphIYHigw9PgrDFYOaYfIQGRUdkaxTGJp6FcSugYSwCBUBx83bFzYURgAC8 wQnEWEGoXl+Q4t5z0gyDSo9fExFx+KNVzB4WE02r5jvCGqzloEym58FjWhCSrE/IjKyX YAyQ== 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 b6si15199348pgd.292.2019.01.22.03.48.04; Tue, 22 Jan 2019 03:48:20 -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 S1728171AbfAVLq6 (ORCPT + 99 others); Tue, 22 Jan 2019 06:46:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:54288 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727663AbfAVLq6 (ORCPT ); Tue, 22 Jan 2019 06:46:58 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CB587AE03; Tue, 22 Jan 2019 11:46:56 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 22 Jan 2019 12:46:55 +0100 From: Roman Penyaev To: Linus Torvalds Cc: Andrew Morton , Davidlohr Bueso , Jason Baron , Al Viro , "Paul E. McKenney" , Andrea Parri , linux-fsdevel , Linux List Kernel Mailing Subject: Re: [RFC PATCH v2 02/13] epoll: introduce user structures for polling from userspace In-Reply-To: References: <20190121201456.28338-1-rpenyaev@suse.de> <20190121201456.28338-3-rpenyaev@suse.de> Message-ID: <891cb81595dbad8b90cbb6de940da97f@suse.de> X-Sender: rpenyaev@suse.de User-Agent: Roundcube Webmail Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-01-21 22:34, Linus Torvalds wrote: > So I'm not entirely convinced, but I guess actual numbers and users > might convince me otherwise. > > However, a quick comment: > > On Tue, Jan 22, 2019 at 9:15 AM Roman Penyaev wrote: >> >> +struct epoll_uitem { >> + __poll_t ready_events; >> + struct epoll_event event; >> +}; > > This really ends up being a horrible data structure. > > struct epoll_event is declared as > > struct epoll_event { > __poll_t events; > __u64 data; > } EPOLL_PACKED; > > and __poll_t is "unsigned". So on pretty much all 64-bit architectures > except for x86-64 (which sets that packed attribute), you have a > packing hole there in between the events and the data, and "struct > epoll_event" has 8-byte alignment. > > Now, in "struct epoll_uitem", you end up having *another* packing hold > in between "ready_events" and "struct epoll_event". > > So this data structure that has 16 bytes of actual data, ends up being > 24 bytes in size. > > Again, x86-64 happens to be the exception to this, but that's a random > small implementation detail, not a design thing. > > I think "struct epoll_event" was badly designed to begin with to have > this issue, but it shouldn't then be an excuse to make things even > worse with this array of "struct epoll_uitem" things. > > Hmm? Ha! Yes, you are right. Eyes see "packed" and brain responds "ok, this is 12 bytes, + 4 for ready_events = 16, perfect". I have not paid any attention to how actually this EPOLL_PACKED is defined. Not nice at all. I will unfold the structure like this: /* * Item, shared with userspace. Unfortunately we can't embed epoll_event * structure, because it is badly aligned on all 64-bit archs, except * x86-64 (see EPOLL_PACKED). sizeof(epoll_uitem) == 16 */ struct epoll_uitem { __poll_t ready_events; __poll_t events; __u64 data; }; Also BUILD_BUG_ON(sizeof(epoll_uitem) != 16) somewhere in alloc won't hurt. -- Roman