Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1509835rdb; Sat, 18 Nov 2023 21:44:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHAVKPl7wRTkJrACnVTqZz0a2I2T8grwFlyBGWBzJ2r1UVyaltPrrplP2TDoTW3a1sf5alY X-Received: by 2002:a05:620a:319d:b0:778:a93c:e661 with SMTP id bi29-20020a05620a319d00b00778a93ce661mr5408835qkb.32.1700372695638; Sat, 18 Nov 2023 21:44:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700372695; cv=none; d=google.com; s=arc-20160816; b=zbsT4X6Ja59Zoi1RDitYx4y6UU9TXGLqJ+i2xCa+PTPp1+YuPo7Sb+Kb+8xSfkwu1A Icth+ymhYrTeX/q/Hg9S3u0LMaL3h4VQ5CtfgmsCq03WrVQohmB1TYEOx/ZtUiw7Fk45 B7qYw/3mYJwJ6NPGwawS/RA1j2lJ+V9Qnf3PWqV6y9xBy3P2SawNTWUZVlpvSu9JbFt2 pSImp11hK1MKFcooSUdaJuPaM8weZeyZB9YW+km0r1OVBOBz1Cg+59jhDSkeV3H7e4+e ImjfgTL2z9LtrZb9WuBQGI0bwC2Bb9jfkUneeTCSVko0cWSD/AeQUBJtExr1aUTxNTfO kxnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=acisFztUKpjeKMKioP89uYReNJaDW+C6LZ8gdfib14g=; fh=aY7BzdyKm4Nm0M/uAtUmk2wfKPqEr2Dp62eUaXsSvjg=; b=XOffSc75kYApJlNFEYDM9vY33z7hq6dRjQIx+HxjRMXvVMsASzyQgGYW0Rdy80axFT FrLnUiQN7/c/OUm7yrMLwm8AF0gKQpHJ5ht2CRevjfh1g+RUFvtAnRPYdd5BdZRvNlO1 Ke8mbxytm2r/4t1OgwAbzk6L+6J9yIc7UCFqer0m4qNg5/XgeN8KKf7IMcg15WCrDyED 3h4NcD2RDWFki0Bg0Rp9aWyD7TKmM84UaWeZmoUShpyNPVZHdP3krAXJoyEaqGFrf1Vd Qc23gFnezAmZE37NRdCnRx0/mlympX8LsCXoPq1bLfGCS2/rt1PNWvR+j6uw7A44rQEt COag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mtA7JnCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h23-20020a17090adb9700b00283bc49ad11si3079600pjv.183.2023.11.18.21.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 21:44:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mtA7JnCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 2532880615C4; Sat, 18 Nov 2023 21:44:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229708AbjKSFoi (ORCPT + 99 others); Sun, 19 Nov 2023 00:44:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjKSFoh (ORCPT ); Sun, 19 Nov 2023 00:44:37 -0500 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EABC5E0 for ; Sat, 18 Nov 2023 21:44:31 -0800 (PST) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20231119054427epoutp02df8e6e3551a7520a262da8e006b3461c~Y7_6UXGP12034520345epoutp02k for ; Sun, 19 Nov 2023 05:44:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20231119054427epoutp02df8e6e3551a7520a262da8e006b3461c~Y7_6UXGP12034520345epoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1700372667; bh=acisFztUKpjeKMKioP89uYReNJaDW+C6LZ8gdfib14g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mtA7JnCPRutWsbCfRE3KFGXIiLcTPq6WX0Nh6pYqIIIq21lzwp/vb7a4YDrva7u1M VjcSaj7iswepOGuBoXT6Ipk3pVFs63mkv+gsY4wp9vblFq51uHtXUbMvW2Zy2H7zJE 0QEHbz3FnZK9vtaynmltV2jUuF2Qj/vjt1o6imp0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231119054426epcas5p3e6d458615f54d4b2dd71249773656510~Y7_5vxSGt1479714797epcas5p3g; Sun, 19 Nov 2023 05:44:26 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.178]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SY02K05mRz4x9Pq; Sun, 19 Nov 2023 05:44:25 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0A.5A.10009.8B0A9556; Sun, 19 Nov 2023 14:44:24 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20231118032740epcas5p20b6aad6264323376fa024bc2a56f0990~YmeMh0elz2208922089epcas5p25; Sat, 18 Nov 2023 03:27:40 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231118032740epsmtrp2a136bf86f3267b036f187156306d1c0d~YmeMg3Pug0866708667epsmtrp2d; Sat, 18 Nov 2023 03:27:40 +0000 (GMT) X-AuditID: b6c32a4a-261fd70000002719-1c-6559a0b8e667 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 68.BA.08755.B2F28556; Sat, 18 Nov 2023 12:27:39 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231118032738epsmtip22d14803f98dafe47a22a79304adc65de~YmeLQZepw2926129261epsmtip2t; Sat, 18 Nov 2023 03:27:38 +0000 (GMT) From: Xiaobing Li To: axboe@kernel.dk Cc: asml.silence@gmail.com, linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, kun.dou@samsung.com, peiwei.li@samsung.com, joshi.k@samsung.com, kundan.kumar@samsung.com, wenwen.chen@samsung.com, ruyi.zhang@samsung.com, xiaobing.li@samsung.com Subject: Re: [PATCH v3] io_uring/fdinfo: remove need for sqpoll lock for thread/pid retrieval Date: Sat, 18 Nov 2023 11:19:51 +0800 Message-Id: <20231118031951.21764-1-xiaobing.li@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <605eac76-ec47-436b-872a-f6e8b4094293@kernel.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprDJsWRmVeSWpSXmKPExsWy7bCmpu6OBZGpBgsem1vMWbWN0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ibL+12I11x7jet9spsRSnJFoqMVc VJwIACCkQsniAgAA X-CMS-MailID: 20231118032740epcas5p20b6aad6264323376fa024bc2a56f0990 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231118032740epcas5p20b6aad6264323376fa024bc2a56f0990 References: <605eac76-ec47-436b-872a-f6e8b4094293@kernel.dk> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 18 Nov 2023 21:44:53 -0800 (PST) On 11/15/23 6:42 AM, Jens Axboe wrote: > */ > has_lock = mutex_trylock(&ctx->uring_lock); > >- if (has_lock && (ctx->flags & IORING_SETUP_SQPOLL)) { >- struct io_sq_data *sq = ctx->sq_data; >- >- sq_pid = sq->task_pid; >- sq_cpu = sq->sq_cpu; >+ if (ctx->flags & IORING_SETUP_SQPOLL) { >+ struct io_sq_data *sq; >+ >+ rcu_read_lock(); >+ sq = READ_ONCE(ctx->sq_data); >+ if (sq) { >+ sq_pid = sq->task_pid; >+ sq_cpu = sq->sq_cpu; >+ } >+ rcu_read_unlock(); > } > > seq_printf(m, "SqThread:\t%d\n", sq_pid); >diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c >index 65b5dbe3c850..583c76945cdf 100644 >--- a/io_uring/sqpoll.c >+++ b/io_uring/sqpoll.c >@@ -70,7 +70,7 @@ void io_put_sq_data(struct io_sq_data *sqd) > WARN_ON_ONCE(atomic_read(&sqd->park_pending)); > > io_sq_thread_stop(sqd); >- kfree(sqd); >+ kfree_rcu(sqd, rcu); > } > } > >@@ -313,7 +313,7 @@ static int io_sq_thread(void *data) > } > > io_uring_cancel_generic(true, sqd); >- sqd->thread = NULL; >+ WRITE_ONCE(sqd->thread, NULL); > list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) > atomic_or(IORING_SQ_NEED_WAKEUP, &ctx->rings->sq_flags); > io_run_task_work(); >@@ -411,7 +411,7 @@ __cold int io_sq_offload_create(struct io_ring_ctx *ctx, > goto err_sqpoll; > } > >- sqd->thread = tsk; >+ WRITE_ONCE(sqd->thread, tsk); > ret = io_uring_alloc_task_context(tsk, ctx); > wake_up_new_task(tsk); > if (ret) >diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h >index 8df37e8c9149..0cf0c5833a27 100644 >--- a/io_uring/sqpoll.h >+++ b/io_uring/sqpoll.h >@@ -18,6 +18,8 @@ struct io_sq_data { > > unsigned long state; > struct completion exited; >+ >+ struct rcu_head rcu; > }; > > int io_sq_offload_create(struct io_ring_ctx *ctx, struct io_uring_params *p); I tested this and it worked after adding RCU lock. It consistently outputs correct results. The results of a simple test are as follows: Every 0.5s: cat /proc/10212/fdinfo/6 | grep Sq SqMask: 0x3 SqHead: 17422716 SqTail: 17422716 CachedSqHead: 17422716 SqThread: 10212 SqThreadCpu: 73 SqBusy: 97% ------------------------------------------------------------- But the name of the sq thread is "iou-sqp-" + "the PID of its parent process": PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 10211 root 20 0 184408 8192 0 R 99.9 0.0 4:01.42 fio 10212 root 20 0 184408 8192 0 R 99.9 0.0 4:01.48 iou-sqp-10211 Is this the originally desired effect?