Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp151773pxx; Wed, 28 Oct 2020 00:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcXmebCHvuHyE+yBB64pE9/tgX3WISJQpIFESciJeFEUZaI25lwuEjY4+6PS/vfV8NWpKu X-Received: by 2002:a17:906:3650:: with SMTP id r16mr6252005ejb.419.1603871344042; Wed, 28 Oct 2020 00:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603871344; cv=none; d=google.com; s=arc-20160816; b=kcukLBtEsscJq1A+WVCBOyXQn/TV7rrPF3+oyj8kSEJzZ/62IHIEZqq48HWP8kejVI B0i5R9kdZnFlJrvP8W5tHjpNOLatUL5dXPkl0eoJnjuBc863uxVwndkVDi+CHe8Wbswx JVJyEIbisZZ+6XZIvHmGoINinwXcfn7L7armxgmnX06tKGPjiKEoJTbrSVJZLx5/Xs06 tlp78i3obFjveoiIzNDDsPfFdS48Lkz8hAcA/Y15pcxZDzd1Qk/j+SZqu3oswKK6DFVn D3fgK1E+RmwFeh0WrFByfR93R519Yz2uHd14UlopC+yP5UezVYT28vUAgzF+PakOPYC0 3gsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=rXqxuhCPhInDJFWMwIOJySkG+GwelVIGToJrk2cMB18=; b=fB0rmMwZvHLVHoglQO6TkqJNbqgk/L9adeHtVdagRKWOddX/I3Du1waXVtQb8nWGkh HG+RoO57tlUPqGZnXfJ1THBFiU7PPykyIoG9sHmZP4Scrz1VFtFudO54bted5mIHfbJ8 jJTKsEvCfGqzfQexx1zPZFHay21dHRBFqpLmrcYQsPwIftOeTTUo0IljcKWYIwU5o+1C E5o3KxQhUxrLVu8il/vGtpIDbs3ppCU/CuK51d4h+1D1v5ooujU23hi2CDLPRNt69X/m e7z61fKumXSfr+iR2CD1YH9Zo50R3uH+PYcqmgwXwBiLQAjISNVYrKy+qAuyJdzwguFm 5QLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=fUAGAyTs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf17si2900638ejb.226.2020.10.28.00.48.38; Wed, 28 Oct 2020 00:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=fUAGAyTs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752266AbgJ0NfE (ORCPT + 99 others); Tue, 27 Oct 2020 09:35:04 -0400 Received: from mail-il1-f177.google.com ([209.85.166.177]:40979 "EHLO mail-il1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752261AbgJ0NfE (ORCPT ); Tue, 27 Oct 2020 09:35:04 -0400 Received: by mail-il1-f177.google.com with SMTP id x20so1498762ilj.8 for ; Tue, 27 Oct 2020 06:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=rXqxuhCPhInDJFWMwIOJySkG+GwelVIGToJrk2cMB18=; b=fUAGAyTsFkZOo34w1RJd30qc33lBq6mgjy75wt8giheCNdkRN8fhcfu2ixO0WSP/ZD xz//LGxwt3B+bxU5kToi0HgT3LKJQF1D9Hqg1v00W9F/+N1il/j1DIemFKBbNw6GnV50 59zNnum0+eVt5pMQfJQmoCRd3jfZ4slJqrvfpOu5owdjq6stvPBTt0qS0WIV6/wNzfgR Ww2DcbruLzZC+DQphnM+8x7fUNEOI36I+uYy0XHOYL2xwOTneL8VWpBZL0PZC5kboL+G TI4AfBJuS9sdALwz+FgwLqoN4KcvxrmWtQIZrC/iEfaWNhtwV4j6jRSGuqSlQh7LmsM8 LmiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=rXqxuhCPhInDJFWMwIOJySkG+GwelVIGToJrk2cMB18=; b=H4x/QeK5Czl9EWbUq+GX6JdnWtVmwmQLPLQkJgwi2bsVB0HhlDtB/D3I/Kj24XDwlF Shgu5j3FUe3o2A6bsSfHZY3Yhniv17mMR5aRojmsCSI127/L8J/YVAQV+RCHO07qJZ3L XM35Gru1TT+oHE16qzcerke+Whimb85AbExZaFJrap5AbyAmfonl8+XdNHznOQMBQ2gp 83fwhKUaK/NWuYzLp+OxXzBzgymVnzuAiogWH+hJZVGkt7ORrNGXdDaH9BzjhpmoiVOJ wbrcad8I2npzHmIunxug0UIMQhxQyNHdMS+4xlzYQBfkDc9iySLsjxYoq5zj4TrOLK1q xWMg== X-Gm-Message-State: AOAM532dtj05lwpOYeYXYSBNkqmWn+RaBOmzA9Og9D19kHtDt64u7wdK 6fEW0k2Utxcz+f8ZNVswLtdx4ODc4wnE7A== X-Received: by 2002:a92:3590:: with SMTP id c16mr2029804ilf.286.1603805701310; Tue, 27 Oct 2020 06:35:01 -0700 (PDT) Received: from [192.168.1.30] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id 186sm1057735ile.4.2020.10.27.06.35.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 27 Oct 2020 06:35:00 -0700 (PDT) Subject: Re: [PATCH] io-wq: set task TASK_INTERRUPTIBLE state before schedule_timeout To: qiang.zhang@windriver.com Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <20201027030911.16596-1-qiang.zhang@windriver.com> From: Jens Axboe Message-ID: Date: Tue, 27 Oct 2020 07:35:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201027030911.16596-1-qiang.zhang@windriver.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/26/20 9:09 PM, qiang.zhang@windriver.com wrote: > From: Zqiang > > In 'io_wqe_worker' thread, if the work which in 'wqe->work_list' be > finished, the 'wqe->work_list' is empty, and after that the > '__io_worker_idle' func return false, the task state is TASK_RUNNING, > need to be set TASK_INTERRUPTIBLE before call schedule_timeout func. I don't think that's safe - what if someone added work right before you call schedule_timeout_interruptible? Something ala: io_wq_enqueue() set_current_state(TASK_INTERRUPTIBLE(); schedule_timeout(WORKER_IDLE_TIMEOUT); then we'll have work added and the task state set to running, but the worker itself just sets us to non-running and will hence wait WORKER_IDLE_TIMEOUT before the work is processed. The current situation will do one extra loop for this case, as the schedule_timeout() just ends up being a nop and we go around again checking for work. Since we already unused the mm, the next iteration will go to sleep properly unless new work came in. -- Jens Axboe