From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C4E4C433E1 for ; Thu, 14 May 2020 14:55:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 260BB20643 for ; Thu, 14 May 2020 14:55:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N38RyPUP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727917AbgENOzI (ORCPT ); Thu, 14 May 2020 10:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727885AbgENOzH (ORCPT ); Thu, 14 May 2020 10:55:07 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32830C061A0C for ; Thu, 14 May 2020 07:55:07 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id g12so33075667wmh.3 for ; Thu, 14 May 2020 07:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:references:from:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=VljZtSHHMdgBlV/KrRhfcZ5jyPxHSZPX8efDlkCs+fs=; b=N38RyPUP6MGAiThceFSfGNit1M3isjsAYy9CvmL7Mjd7fk5XEjkcYR02VtFYa3Syl2 ShCdBoodHvS9rnuSys6sIX18Bj2GR/dcuTAu58bXrD5vvurmiP+Q+TS1ExyaAPWXRI5J 6Sgn4pu2V1eHW0jjlyBCM3WXJuqW2af6FcBxlV9pN8RwqOD6ETl5G5pHUmPz57L9WJv/ 0Mw/8vUHlLZQhLUpli08q97+G8FpFx/G93xTf9Gn0SGNjXstTtyX/xu/YVU2ldlQCXFb uQLpoYco/L0AFd82T+Pp/97kumpI9tni0Efp7lnK+ghohU6EhdenU843f5Kd4jnRvm5v WZtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=VljZtSHHMdgBlV/KrRhfcZ5jyPxHSZPX8efDlkCs+fs=; b=dxfpzyMv1r6S8wNBwxSKy2qqF5oxUfL0lt2pCx/cDi3tIgCxnqgHzl/VlLL7R4xbxi 9l+/QJ1c0yR+7kQhKEelubK2omhPFEYuNBz1o0JXMb3MNu4dZbcu5NaD6UdSbVmkpTAy 82vAL84VqO6S2H3MBGOtfzByO6tAYJjCmzGl+XMeGj4g72wxTsBSufdY94QBYlgCyyD7 ZxbFCV7dEQfjvm3x7LDmbo0Cv2sQNVYfRWKAng+BLPPvd+Ripo64FDRfPwIS+4tL1IkQ gyie5yhI21JmH8nr4TKGs+8BK3/EMXfWJVtqlzjCsTITSw5vHn7x7jLtRpniD86VXwoe 7bnA== X-Gm-Message-State: AGi0Pubx834rj6CVq0+FCfV1FXkhnAcRDSCUnfIXPxX4Xg3A1lNUJtqg cDn81yfyB8BR7xnOYV2QR/w= X-Google-Smtp-Source: APiQypL6yaV7p0kQ/7zJK62zaLWUDEKG9yIhhHGX8skY8DtJlbQB32sJmOalyfuDgY5t3UAIcZU5Dg== X-Received: by 2002:a7b:c5c7:: with SMTP id n7mr38901743wmk.18.1589468105527; Thu, 14 May 2020 07:55:05 -0700 (PDT) Received: from [192.168.43.127] ([46.191.65.149]) by smtp.gmail.com with ESMTPSA id s15sm4282329wro.80.2020.05.14.07.55.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 May 2020 07:55:04 -0700 (PDT) To: Jens Axboe , Xiaoguang Wang , io-uring Cc: joseph qi , Jiufei Xue References: <492bb956-a670-8730-a35f-1d878c27175f@kernel.dk> <70602a13-f6c9-e8a8-1035-6f148ba2d6d7@kernel.dk> From: Pavel Begunkov Autocrypt: addr=asml.silence@gmail.com; prefer-encrypt=mutual; keydata= mQINBFmKBOQBEAC76ZFxLAKpDw0bKQ8CEiYJRGn8MHTUhURL02/7n1t0HkKQx2K1fCXClbps bdwSHrhOWdW61pmfMbDYbTj6ZvGRvhoLWfGkzujB2wjNcbNTXIoOzJEGISHaPf6E2IQx1ik9 6uqVkK1OMb7qRvKH0i7HYP4WJzYbEWVyLiAxUj611mC9tgd73oqZ2pLYzGTqF2j6a/obaqha +hXuWTvpDQXqcOZJXIW43atprH03G1tQs7VwR21Q1eq6Yvy2ESLdc38EqCszBfQRMmKy+cfp W3U9Mb1w0L680pXrONcnlDBCN7/sghGeMHjGKfNANjPc+0hzz3rApPxpoE7HC1uRiwC4et83 CKnncH1l7zgeBT9Oa3qEiBlaa1ZCBqrA4dY+z5fWJYjMpwI1SNp37RtF8fKXbKQg+JuUjAa9 Y6oXeyEvDHMyJYMcinl6xCqCBAXPHnHmawkMMgjr3BBRzODmMr+CPVvnYe7BFYfoajzqzq+h EyXSl3aBf0IDPTqSUrhbmjj5OEOYgRW5p+mdYtY1cXeK8copmd+fd/eTkghok5li58AojCba jRjp7zVOLOjDlpxxiKhuFmpV4yWNh5JJaTbwCRSd04sCcDNlJj+Teh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3N6rpodi4Dkdli8HylM5iq4ooeb5VkQ7UZxbCWt UVMKkOCdFhutRmYp0mbv2e87IK4erwNHQRkHUkzbsuym8RVpAZbLzLPIYK/J3RTErL6Z99N2 m3J6pjwSJY/zNwuFPs9zGEnRO4g0BUbwGdbuvDzaq6/3OJLKohr5eLXNU3JkT+3HezydWm3W OPhauth7W0db74Qd49HXK0xe/aPrK+Cp+kU1HRactyNtF8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Subject: Re: [PATCH RFC} io_uring: io_kiocb alloc cache Message-ID: <0ec1b33d-893f-1b10-128e-f8a8950b0384@gmail.com> Date: Thu, 14 May 2020 17:53:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: io-uring-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 14/05/2020 17:33, Jens Axboe wrote: > On 5/14/20 8:22 AM, Jens Axboe wrote: >>> I still use my previous io_uring_nop_stress tool to evaluate the improvement >>> in a physical machine. Memory 250GB and cpu is "Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz". >>> Before this patch: >>> $sudo taskset -c 60 ./io_uring_nop_stress -r 300 >>> total ios: 1608773840 >>> IOPS: 5362579 >>> >>> With this patch: >>> sudo taskset -c 60 ./io_uring_nop_stress -r 300 >>> total ios: 1676910736 >>> IOPS: 5589702 >>> About 4.2% improvement. >> >> That's not bad. Can you try the patch from Pekka as well, just to see if >> that helps for you? >> >> I also had another idea... We basically have two types of request life >> times: >> >> 1) io_kiocb can get queued up internally >> 2) io_kiocb completes inline >> >> For the latter, it's totally feasible to just have the io_kiocb on >> stack. The downside is if we need to go the slower path, then we need to >> alloc an io_kiocb then and copy it. But maybe that's OK... I'll play >> with it. Does it differ from having one pre-allocated req? Like fallback_req, but without atomics and returned only under uring_mutex (i.e. in __io_queue_sqe()). Putting aside its usefulness, at least it will have a chance to work with reads/writes. > > Can you try this with your microbenchmark? Just curious what it looks > like for that test case if we completely take slab alloc+free out of it. > > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index d2e37215d05a..4ecd6bd38f02 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -525,6 +525,7 @@ enum { > REQ_F_POLLED_BIT, > REQ_F_BUFFER_SELECTED_BIT, > REQ_F_NO_FILE_TABLE_BIT, > + REQ_F_STACK_REQ_BIT, > > /* not a real bit, just to check we're not overflowing the space */ > __REQ_F_LAST_BIT, > @@ -580,6 +581,8 @@ enum { > REQ_F_BUFFER_SELECTED = BIT(REQ_F_BUFFER_SELECTED_BIT), > /* doesn't need file table for this request */ > REQ_F_NO_FILE_TABLE = BIT(REQ_F_NO_FILE_TABLE_BIT), > + /* on-stack req */ > + REQ_F_STACK_REQ = BIT(REQ_F_STACK_REQ_BIT), > }; > > struct async_poll { > @@ -695,10 +698,14 @@ struct io_op_def { > unsigned pollout : 1; > /* op supports buffer selection */ > unsigned buffer_select : 1; > + /* op can use stack req */ > + unsigned stack_req : 1; > }; > > static const struct io_op_def io_op_defs[] = { > - [IORING_OP_NOP] = {}, > + [IORING_OP_NOP] = { > + .stack_req = 1, > + }, > [IORING_OP_READV] = { > .async_ctx = 1, > .needs_mm = 1, > @@ -1345,7 +1352,8 @@ static void __io_req_aux_free(struct io_kiocb *req) > if (req->flags & REQ_F_NEED_CLEANUP) > io_cleanup_req(req); > > - kfree(req->io); > + if (req->io) > + kfree(req->io); > if (req->file) > io_put_file(req, req->file, (req->flags & REQ_F_FIXED_FILE)); > if (req->task) > @@ -1370,6 +1378,8 @@ static void __io_free_req(struct io_kiocb *req) > } > > percpu_ref_put(&req->ctx->refs); > + if (req->flags & REQ_F_STACK_REQ) > + return; > if (likely(!io_is_fallback_req(req))) > kmem_cache_free(req_cachep, req); > else > @@ -5784,12 +5794,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req, > * link list. > */ > req->sequence = ctx->cached_sq_head - ctx->cached_sq_dropped; > - req->opcode = READ_ONCE(sqe->opcode); > req->user_data = READ_ONCE(sqe->user_data); > req->io = NULL; > req->file = NULL; > req->ctx = ctx; > - req->flags = 0; > /* one is dropped after submission, the other at completion */ > refcount_set(&req->refs, 2); > req->task = NULL; > @@ -5839,6 +5847,7 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, > { > struct io_submit_state state, *statep = NULL; > struct io_kiocb *link = NULL; > + struct io_kiocb stack_req; > int i, submitted = 0; > > /* if we have a backlog and couldn't flush it all, return BUSY */ > @@ -5865,20 +5874,31 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, > for (i = 0; i < nr; i++) { > const struct io_uring_sqe *sqe; > struct io_kiocb *req; > - int err; > + int err, op; > > sqe = io_get_sqe(ctx); > if (unlikely(!sqe)) { > io_consume_sqe(ctx); > break; > } > - req = io_alloc_req(ctx, statep); > - if (unlikely(!req)) { > - if (!submitted) > - submitted = -EAGAIN; > - break; > + > + op = READ_ONCE(sqe->opcode); > + > + if (io_op_defs[op].stack_req) { > + req = &stack_req; > + req->flags = REQ_F_STACK_REQ; > + } else { > + req = io_alloc_req(ctx, statep); > + if (unlikely(!req)) { > + if (!submitted) > + submitted = -EAGAIN; > + break; > + } > + req->flags = 0; > } > > + req->opcode = op; > + > err = io_init_req(ctx, req, sqe, statep, async); > io_consume_sqe(ctx); > /* will complete beyond this point, count as submitted */ > -- Pavel Begunkov