Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3297825rwo; Mon, 24 Jul 2023 09:02:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlGTjZcfv3MxqtpkCTl8D2uMlJt9ql520M67ZsiIqNQmumyhhpejWOcSQQh+zp5uDrqm8gbk X-Received: by 2002:a17:90a:7c46:b0:268:314f:8f35 with SMTP id e6-20020a17090a7c4600b00268314f8f35mr395001pjl.6.1690214521347; Mon, 24 Jul 2023 09:02:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690214521; cv=none; d=google.com; s=arc-20160816; b=SAVCFmd53rDZ3Lm8sOPEWaFs+PMdUxc6uGXQ/UqWaDmRk01XRkm7a2fVKJrdOGdNNX JWAmk+ZvvjEbjRtyHLRJUVcBaQmTMc5yupsR9SWhb6mwjY2MMtB8YLT0SOybceKSbhVS dXZ0+kxihlufWN0VjiJg/PbsPKjeSSQYL2iYtsOefx6/Q6m2mOsNEwoUeCQbB6Rllb5p qcFrQqmW8revbwK80ADcp8FS58hX4u1CxOT1nRopYgyF/70rJvlya5BNMNtoUhvrq8Nw zVHmuTvm/Yksd6Kxpp2mmGDEMb9veyLlZvwX578iKHtjG6hgxuS2C1GtDw2CxkIl9TX+ PMyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JxVUVt//RDm7fJf78yJOuIe4ZtlkJolhHRr3i1sX308=; fh=WSNwYnpZlBKlFrDmXvuCu0DXzpLKwLzZOdmHTKp2+9I=; b=GPtjPOP+UPbHBEdurANShJQKopyMwpv9FWp0JqNRDQXZxR9IZkhEkaxbLOsnG/6cbn jpO2vG6xLcs4so/p3l4WsemjP9n2yAXvsOYjlVt3fNguo25dezycGUUTxKIdLM+ue5Lo yJzi5cu/4fAxDuQZZH0Pptb2rbGU5+ymzAUZlAiUyYJaYa3PG12xlxo/UPC8TKx4Iuev 3VaRztGO9OcWKKkFBgN6qT47b14w+16MrCSkwY/LpG7Rpo21/iHEvj6182ppTsNAMS9m y10qzE0Qm2pqn5vJAWlwNs8FM9UqE644LeX4uQ/wF62HQvGzRNFLFSNk+tgapUD600gO PjAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=yu+8+EyP; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v6-20020a17090ac90600b00263e46aa26asi11707176pjt.18.2023.07.24.09.01.47; Mon, 24 Jul 2023 09:02:01 -0700 (PDT) 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=@kernel-dk.20221208.gappssmtp.com header.s=20221208 header.b=yu+8+EyP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231309AbjGXPtD (ORCPT + 99 others); Mon, 24 Jul 2023 11:49:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231250AbjGXPtC (ORCPT ); Mon, 24 Jul 2023 11:49:02 -0400 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCA70F9 for ; Mon, 24 Jul 2023 08:49:00 -0700 (PDT) Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-785d3a53ed6so45821139f.1 for ; Mon, 24 Jul 2023 08:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1690213740; x=1690818540; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JxVUVt//RDm7fJf78yJOuIe4ZtlkJolhHRr3i1sX308=; b=yu+8+EyPAM0ktL1EsHkJNyG5xHqrXZ9GLEN26LGiwrMZCcenDgelJhegvPh+zwwzi6 NUlMm5DFcyMTihkzfokLseyT1zaiV4J1SXsKyO6q4NwZ2WItu66zB/LdSbgaw3dYNDnb a3q2MwtaaEpSDRWa/BPoU2ZZ4kfDtSjo/L8kVS8ZLFqOc/PA7eFlXyYvmtLZsvNwF53D fV6hyTGxVZWNZb8gQJynaslObEECdc6GTIqhfTqUe/GDDjQCIcQ/U/lNjRg/bLN8XkhG 7GtjU1GzNv45hIFCps28+I9r4YfaCRlV2CucOzIUyyoN8VcDpeJbPraQH2X5h3xoV8OV l09w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690213740; x=1690818540; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JxVUVt//RDm7fJf78yJOuIe4ZtlkJolhHRr3i1sX308=; b=DFJ9nbM14C1kZGqWwU14NFSUkbq/0P7dPRnxQyexu+Gcf1A3BZEozoaubIHxsLap6w zuBRD0ZmTkzVNCvrRkVzwYg1ztkIIdTJXcWvmAwDji/P+9/B53bJ9Ii7JnuQG//tV6sD F5tQP3P7Hf60uqnAXpJEepFmKRzg3KnnOHqeUbWa2B07x+uK580Zfet1VXE9wfHKxJnE 7N10m87HQ59HtzRjjUuYyLGoT7Ae8phfI3oS2MxJVZDEwQw7IloKkMkHUoLRIgulQRiR hJb2Rz8DYLn/yVIbWkex65tZEDF5jr7oGNpCV+5rjWRPsIEsTdqTz1yG+F68ncChuOO+ mhSA== X-Gm-Message-State: ABy/qLaSyMN+GQl19Cf9WbVA/f5pG/S0vHJVrBdOkjmNWnNaYsBsyohw e/8LZ7lUFLihoKDwF/lzFu+f5Q== X-Received: by 2002:a92:ad0f:0:b0:346:10c5:2949 with SMTP id w15-20020a92ad0f000000b0034610c52949mr6942788ilh.1.1690213740067; Mon, 24 Jul 2023 08:49:00 -0700 (PDT) Received: from [192.168.1.94] ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id n12-20020a92dd0c000000b003423875af1bsm3098506ilm.1.2023.07.24.08.48.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Jul 2023 08:48:59 -0700 (PDT) Message-ID: <3d97ae14-dd8d-7f82-395a-ccc17c6156be@kernel.dk> Date: Mon, 24 Jul 2023 09:48:58 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] io_uring: Use io_schedule* in cqring wait Content-Language: en-US To: Phil Elwell Cc: andres@anarazel.de, asml.silence@gmail.com, david@fromorbit.com, hch@lst.de, io-uring@vger.kernel.org, LKML , linux-xfs@vger.kernel.org, stable References: From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 7/24/23 9:35?AM, Phil Elwell wrote: > Hi Andres, > > With this commit applied to the 6.1 and later kernels (others not > tested) the iowait time ("wa" field in top) in an ARM64 build running > on a 4 core CPU (a Raspberry Pi 4 B) increases to 25%, as if one core > is permanently blocked on I/O. The change can be observed after > installing mariadb-server (no configuration or use is required). After > reverting just this commit, "wa" drops to zero again. There are a few other threads on this... > I can believe that this change hasn't negatively affected performance, > but the result is misleading. I also think it's pushing the boundaries > of what a back-port to stable should do. It's just a cosmetic thing, to be fair, and it makes quite a large difference on important cases. This is why it also went to stable, which btw was not Andres's decision at all. I've posted this patch in another thread as well, but here it is in this thread too - this will limit the cases that are marked as iowait. diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 89a611541bc4..f4591b912ea8 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2493,11 +2493,20 @@ int io_run_task_work_sig(struct io_ring_ctx *ctx) return 0; } +static bool current_pending_io(void) +{ + struct io_uring_task *tctx = current->io_uring; + + if (!tctx) + return false; + return percpu_counter_read_positive(&tctx->inflight); +} + /* when returns >0, the caller should retry */ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, struct io_wait_queue *iowq) { - int token, ret; + int io_wait, ret; if (unlikely(READ_ONCE(ctx->check_cq))) return 1; @@ -2511,17 +2520,19 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx, return 0; /* - * Use io_schedule_prepare/finish, so cpufreq can take into account - * that the task is waiting for IO - turns out to be important for low - * QD IO. + * Mark us as being in io_wait if we have pending requests, so cpufreq + * can take into account that the task is waiting for IO - turns out + * to be important for low QD IO. */ - token = io_schedule_prepare(); + io_wait = current->in_iowait; + if (current_pending_io()) + current->in_iowait = 1; ret = 0; if (iowq->timeout == KTIME_MAX) schedule(); else if (!schedule_hrtimeout(&iowq->timeout, HRTIMER_MODE_ABS)) ret = -ETIME; - io_schedule_finish(token); + current->in_iowait = io_wait; return ret; } -- Jens Axboe