From patchwork Fri Jan 18 16:12:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10770801 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4734A186E for ; Fri, 18 Jan 2019 16:12:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D3382F432 for ; Fri, 18 Jan 2019 16:12:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DF7B2F3B0; Fri, 18 Jan 2019 16:12:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6A622F3B0 for ; Fri, 18 Jan 2019 16:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728053AbfARQM5 (ORCPT ); Fri, 18 Jan 2019 11:12:57 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35280 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728046AbfARQM5 (ORCPT ); Fri, 18 Jan 2019 11:12:57 -0500 Received: by mail-pl1-f193.google.com with SMTP id p8so6566135plo.2 for ; Fri, 18 Jan 2019 08:12:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eSRoBWEYatYiUOfFsoUKfPfK8ZgE8idbL4z9lJ2pW/A=; b=OgZ2nF9N5lOkJoaoGeKmSfl/dGF76lnXTz4BmTXwvmsIe3dDSJ8/rNqBDQ/F459ZWy 57XuGDOPfF2wcAG0d8hSHd7hOSV97VqaXbVJWSxMjeF264amaFgvktYYm7G0xpCFQW1R 4bWaIASito8lCr+Ty6QSg0xNNRXHV0rHNfq8o03yQhZbP+Oc/9jVRWYQuGxdekg4CJ9l +qzz1z7rtE4IW9J5eHDmi4edOvrcOvxxRj/OopvCv1tG/YCvJBV63TDWaDO/LUb15cws DBu0Ju+Dk8PAS/qkYC3wPFdPnBm9rTjDgATm1O5TKfXfkz+vvSl9EkzfwU/KnWrWhetT jITA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eSRoBWEYatYiUOfFsoUKfPfK8ZgE8idbL4z9lJ2pW/A=; b=scD9O1hWwd/7dCEg9eBOuHYugEUfR7f7uy4Ew2nAihEfGhE7VbTNUVAxNEDf4yck7x deXqxRj0tpJBGQo3q9f43ucnt9jsO142kgB7mgtUwx9F4uYugaxYzH9PdQBgj2sM0PxD XMUNO02eKNBmo970/v8DzGikEPJD3XrvHiqh4WiArt4I53KtztWPHXmhNl1bOBa0VCiF rgT4kI+O7nMPzpgkyb5br4aQz2cqKBAgXV2gehAHfJpo/sMknXXZcWoC9xMUsvltsIRO hnl3D9gVjQMIINba37ynJGhKNQ2kao2yvCwE7NiQr54uTmuxT2IWvab01MIeO42ttmx6 ytsA== X-Gm-Message-State: AJcUukfNXKSDniNlWgNllR4UK0b67XyKZ37HJpVy+H95WaEscD+Uu/ma 6BpZelUI2A/8buzxCsD8RG4j/rCFWOXDRQ== X-Google-Smtp-Source: ALg8bN6CmGOl4Nf2+on7FWN/sh41gbuhgkly7v4BPf35H+1oR9BSVHAzZTNnyN2n9Y0fegnzz83aWg== X-Received: by 2002:a17:902:7296:: with SMTP id d22mr20123933pll.265.1547827976250; Fri, 18 Jan 2019 08:12:56 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id m20sm5317804pgv.93.2019.01.18.08.12.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 08:12:55 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-block@vger.kernel.org Cc: hch@lst.de, jmoyer@redhat.com, avi@scylladb.com, Jens Axboe Subject: [PATCH 10/17] io_uring: batch io_kiocb allocation Date: Fri, 18 Jan 2019 09:12:18 -0700 Message-Id: <20190118161225.4545-11-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190118161225.4545-1-axboe@kernel.dk> References: <20190118161225.4545-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similarly to how we use the state->ios_left to know how many references to get to a file, we can use it to allocate the io_kiocb's we need in bulk. Signed-off-by: Jens Axboe --- fs/io_uring.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 668043c87ddb..666f4cee1a5b 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -135,6 +135,13 @@ struct io_kiocb { struct io_submit_state { struct blk_plug plug; + /* + * io_kiocb alloc cache + */ + void *reqs[IO_IOPOLL_BATCH]; + unsigned int free_reqs; + unsigned int cur_req; + /* * File reference cache */ @@ -258,20 +265,42 @@ static void io_ring_drop_ctx_refs(struct io_ring_ctx *ctx, unsigned refs) wake_up(&ctx->wait); } -static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx) +static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx, + struct io_submit_state *state) { + gfp_t gfp = GFP_ATOMIC | __GFP_NOWARN; struct io_kiocb *req; /* safe to use the non tryget, as we're inside ring ref already */ percpu_ref_get(&ctx->refs); - req = kmem_cache_alloc(req_cachep, GFP_ATOMIC | __GFP_NOWARN); + if (!state) + req = kmem_cache_alloc(req_cachep, gfp); + else if (!state->free_reqs) { + size_t sz; + int ret; + + sz = min_t(size_t, state->ios_left, ARRAY_SIZE(state->reqs)); + ret = kmem_cache_alloc_bulk(req_cachep, gfp, sz, + state->reqs); + if (ret <= 0) + goto out; + state->free_reqs = ret - 1; + state->cur_req = 1; + req = state->reqs[0]; + } else { + req = state->reqs[state->cur_req]; + state->free_reqs--; + state->cur_req++; + } + if (req) { req->ctx = ctx; req->flags = 0; return req; } +out: io_ring_drop_ctx_refs(ctx, 1); return NULL; } @@ -881,7 +910,7 @@ static int io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s, if (unlikely(s->sqe->flags)) return -EINVAL; - req = io_get_req(ctx); + req = io_get_req(ctx, state); if (unlikely(!req)) return -EAGAIN; @@ -905,6 +934,9 @@ static void io_submit_state_end(struct io_submit_state *state) { blk_finish_plug(&state->plug); io_file_put(state, NULL); + if (state->free_reqs) + kmem_cache_free_bulk(req_cachep, state->free_reqs, + &state->reqs[state->cur_req]); } /* @@ -914,6 +946,7 @@ static void io_submit_state_start(struct io_submit_state *state, struct io_ring_ctx *ctx, unsigned max_ios) { blk_start_plug(&state->plug); + state->free_reqs = 0; state->file = NULL; state->ios_left = max_ios; }