Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4292516rwb; Tue, 8 Nov 2022 15:06:54 -0800 (PST) X-Google-Smtp-Source: AMsMyM6QDxwgYvdb4dDSF5cEjqIY2JLm/5bKSb3fWrDiQxECnSG31XOVEwf0vQS5djcTqD3/wqJD X-Received: by 2002:a05:6402:2751:b0:443:d90a:43d4 with SMTP id z17-20020a056402275100b00443d90a43d4mr58745690edd.368.1667948814016; Tue, 08 Nov 2022 15:06:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948814; cv=none; d=google.com; s=arc-20160816; b=of6toXeHzstrP++jzyZS9nyJAJVe7cD2fu9273oah+YjSqdAC6pyupXthuUZlKhx8W wWmW2YuKMnfcGQMIbCAVcJnibT4YnqdKibaQ0wQgW8qmCMtHv/PsTgvjZ1TB8t0P/NoI 1uc1stJt5YMA/INpy7rmSIXJX9MfvcToCAvjwzXSao0nwL9BFVzo2th8Bp9McGWfWtPC mHxC6gXiFaJVAkBUnjWC57r6P8F2qpVsbMSDYDhRMEYcPZaBBn+Dk8G5XJde6DEMQM/k xZfM9XsardOU8dM3BrWvJvWWPwmOps8OnPlztM6cmaWtsPoQ6XP3kuPBMFtA4CDJRL3R CNbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=tnDk2k9M8/LVHtazSqy+bXviz9yt0llV/82RlpALNZU=; b=xGt9niCi7ucuytws2lxJHfQhivk5ea9Vphcg8klg1usHXggoRvf2yvvW1M9i3q6sIH yk3Xr5TWnCbmlCCGghw1NLN5LOmW+zAx3WMX2XQmLh1T05refj3Md0K6hM9Mrf1s2pCm zqKVdnAwWCLOWjkn7zDPhlLqfpKvCLgCY0tALuRSSnHObROWPHjOLYokWz6kegmrULs1 ucp/TSJB+Fj0jbsZb4/85yzd2gA/tF7yAY7pufKwyCzonAd8ePdA8fb7P5Hu1COjBaJt p8txgE4lpCvW5yqfGu3jqLjB2Wmxkb698USaJjLJRlTK+eF9wJGk5YOHFKacCclNnFNF G01g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="AUOW/h1u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h18-20020aa7c612000000b00458cd6f8506si12316017edq.173.2022.11.08.15.06.32; Tue, 08 Nov 2022 15:06:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="AUOW/h1u"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229682AbiKHWm1 (ORCPT + 92 others); Tue, 8 Nov 2022 17:42:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229622AbiKHWmY (ORCPT ); Tue, 8 Nov 2022 17:42:24 -0500 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7EF46035D for ; Tue, 8 Nov 2022 14:42:22 -0800 (PST) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-367cd2807f2so147490097b3.1 for ; Tue, 08 Nov 2022 14:42:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tnDk2k9M8/LVHtazSqy+bXviz9yt0llV/82RlpALNZU=; b=AUOW/h1u1FYK+H4+PLsSeADr4/+ODoTN3DzAnxb2B5ppCYAPRUAPVB5WygYNXNI3Lx UHaKux2Mj+tl5XEee4y/7+yWqveJ35A4ozXA4yWTLd5Vp3AWRe3mvg0yhzD/NM1pN4X8 1L8VQE4MDpcJm/dsDc07kxIlXMftM+joJbYqe+FgFNMJP3mOCFmKNCjcCn5igOejlq5M nmq1vjrKKt7lzWGMNkjUGR9Ghj9Rm66SHT0AgVZIFW292YjMLt0Sl36+vv6LElZtv2hF aOAoICZnmrKeqIDGN4GEu+shE9+0IZtToOfvj/sqNS7tu0JcF6MOd0YojqAqLza1Qdfq GSgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tnDk2k9M8/LVHtazSqy+bXviz9yt0llV/82RlpALNZU=; b=HHgjCiNVoCdFafJ6IJkohFfZMcJWvsVD+J7C3n2LLuUsKRvrN54a+vjBNo6xm5/Fmc +KYhBGbbvYsdDs/nUQvXdOPWGRnFHLKf1PIOkW8YBmL2pLJ6r1iyeFgKV2w1dcGXTzNx VGq+cHcfZD9Y6KUhNqqVWZxQhFrOhWCGgx6maSGgCzVJXW6/g4btK+AoliyR5wFp08tV SYUeBJTVwZFaByg+05TE31gNpm3BJkOihK1EOjjC8ey0qWn6WRoCJ3ZRwlqVB5k6w3MD xJtw8No2SqQRRPcS8XsovYiF80+Vr8mRAk+2DgeSkpHn0hge529mX3w7z3TRoswvyXrz hfmg== X-Gm-Message-State: ACrzQf0GC729ciTbOlHQI6rZarbvRMNac/z7UvmEsZneuljduTvwJonx mMrsjXCDeH4QzmoUHFO970izWKkwB2ObNdjid7lLY3d4KYSJkfAf X-Received: by 2002:a81:6e05:0:b0:35d:7f88:12f9 with SMTP id j5-20020a816e05000000b0035d7f8812f9mr959219ywc.471.1667947341642; Tue, 08 Nov 2022 14:42:21 -0800 (PST) MIME-Version: 1.0 References: <20221030220203.31210-1-axboe@kernel.dk> <20221030220203.31210-7-axboe@kernel.dk> <4764dcbf-c735-bbe2-b60e-b64c789ffbe6@kernel.dk> In-Reply-To: <4764dcbf-c735-bbe2-b60e-b64c789ffbe6@kernel.dk> From: Soheil Hassas Yeganeh Date: Tue, 8 Nov 2022 17:41:45 -0500 Message-ID: Subject: Re: [PATCH 6/6] eventpoll: add support for min-wait To: Jens Axboe Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Willem de Bruijn , Shakeel Butt Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 8, 2022 at 5:20 PM Jens Axboe wrote: > > Is there a way to short cut the wait if the process is being terminated? > > > > We issues in production systems in the past where too many threads were > > in epoll_wait and the process got terminated. It'd be nice if these > > threads could exit the syscall as fast as possible. > > Good point, it'd be a bit racy though as this is called from the waitq > callback and hence not in the task itself. But probably Good Enough for > most use cases? Sounds good. We can definitely do that as a follow up later. > This should probably be a separate patch though, as it seems this > affects regular waits too without min_wait set? > > >> @@ -1845,6 +1891,18 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events, > >> ewq.timed_out = true; > >> } > >> > >> + /* > >> + * If min_wait is set for this epoll instance, note the min_wait > >> + * time. Ensure the lowest bit is set in ewq.min_wait_ts, that's > >> + * the state bit for whether or not min_wait is enabled. > >> + */ > >> + if (ep->min_wait_ts) { > > > > Can we limit this block to "ewq.timed_out && ep->min_wait_ts"? > > AFAICT, the code we run here is completely wasted if timeout is 0. > > Yep certainly, I can gate it on both of those conditions. Thanks. I think that would help. You might also want to restructure the if/else condition above but it's your call. On Tue, Nov 8, 2022 at 5:29 PM Jens Axboe wrote: > > On 11/8/22 3:25 PM, Willem de Bruijn wrote: > >>> This would be similar to the approach that willemb@google.com used > >>> when introducing epoll_pwait2. > >> > >> I have, see other replies in this thread, notably the ones with Stefan > >> today. Happy to do that, and my current branch does split out the ctl > >> addition from the meat of the min_wait support for this reason. Can't > >> seem to find a great way to do it, as we'd need to move to a struct > >> argument for this as epoll_pwait2() is already at max arguments for a > >> syscall. Suggestions more than welcome. > > > > Expect an array of two timespecs as fourth argument? > > Unfortunately even epoll_pwait2() doesn't have any kind of flags > argument to be able to do tricks like that... But I guess we could do > that with epoll_pwait3(), but it'd be an extra indirection for the copy > at that point (copy array of pointers, copy pointer if not NULL), which > would be unfortunate. I'd hate to have to argue that API to anyone, let > alone Linus, when pushing the series. I personally like what Willem suggested. It feels more natural to me and as you suggested previously it can be a struct argument. The overheads would be similar to any syscall that accepts itimerspec. I understand your concern on "epoll_pwait3". I wish Linus would weigh in here. :-)