From patchwork Fri Nov 30 16:56:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10706813 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 2887018B8 for ; Fri, 30 Nov 2018 16:57:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18EA13041C for ; Fri, 30 Nov 2018 16:57:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D3A830422; Fri, 30 Nov 2018 16:57:27 +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=ham 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 A160B3041C for ; Fri, 30 Nov 2018 16:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727641AbeLAEHV (ORCPT ); Fri, 30 Nov 2018 23:07:21 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:32789 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbeLAEHU (ORCPT ); Fri, 30 Nov 2018 23:07:20 -0500 Received: by mail-it1-f193.google.com with SMTP id m8so2415782itk.0 for ; Fri, 30 Nov 2018 08:57:25 -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=78SuIHvJEGe4HNzKE6mphC3LsuN6oQSJbZlJ28AUFt4=; b=CybVR32+jarjJ76TPU/bO9CZh6/NEIOw504HgVXYL9vCvsOON6+ZEirHjPBmf6QLpA LlDMypoqqsx7t66NpCwcNR6Gs++5nv/R9tITUIT6sY9vEqUi66ulxuMNlbrc0nLDeN06 0islDq9NWRGbIbyKGRKzqOrkZFGWmjkOhA8kUnMjmXT91tts0+2Rss1WuCJ5pa3WmdwT afoqaAFQpyfksFrkEx7ebXP/UctwGkl4hrNoGadaRNjcHJuqNryzUv53jfB9P+e7zhK+ 1l7Itv23/zbquTD9ukbpxF+Vbx9akkAN02BfFJFncgzo4iETOuTxWjHit/xSgiCp5duU f0bg== 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=78SuIHvJEGe4HNzKE6mphC3LsuN6oQSJbZlJ28AUFt4=; b=F9Uls2mY0uoohNKwMI4yypvK9KO8pRm9PVfGfwRo/IxWzpz+ZWz/vV+ryQE8NxecSW TvHd3B68nKXKki3UrXlOfIbGwusX4i0JvofkN5HZiU2/IVBTnlT/TodMqku5gOYsr2ta J9MQN8BFAJ1mUgcrrXSpkxizv5zPA6csuKm1K8bEWJJ+UQYidrSee0FxvCDZBCSdVszO GmxHRgeH6HUEJeQTsfvdBtf8jou4OyopyDwgxl3p4sP05J/rpMnorO92UWLFGRgqZivv pcqi6RPaA6OeARmiBfd5ARiXJZmDDFEX8EhAvXrqdD1U5ijT9lT9aRN6QzOfgs1jPG7c Lzxg== X-Gm-Message-State: AA+aEWYb29JaP0ylxF2k1ncpmMsIaFlddM+G3v6dWgK6/9wRY3KPyQa4 lcYwr/EFVwsWpzep4TPzX5CL9w== X-Google-Smtp-Source: AFSGD/V5dWKOWJxvrGG9zXnr/xPm16NRoYiBRF3PbvhJS+lzC5P5Gb9ZAYpneogFNlSRcOEMATZzRQ== X-Received: by 2002:a24:570a:: with SMTP id u10mr6010544ita.11.1543597044784; Fri, 30 Nov 2018 08:57:24 -0800 (PST) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id j133sm2979447itj.16.2018.11.30.08.57.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 08:57:23 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org Cc: hch@lst.de, Jens Axboe Subject: [PATCH 22/27] aio: batch aio_kiocb allocation Date: Fri, 30 Nov 2018 09:56:41 -0700 Message-Id: <20181130165646.27341-23-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130165646.27341-1-axboe@kernel.dk> References: <20181130165646.27341-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 aio_kiocb's we need in bulk. Signed-off-by: Jens Axboe --- fs/aio.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 341eb1b19319..426939f1dae9 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -230,6 +230,8 @@ struct aio_kiocb { }; }; +#define AIO_IOPOLL_BATCH 8 + struct aio_submit_state { struct kioctx *ctx; @@ -244,6 +246,13 @@ struct aio_submit_state { struct list_head req_list; unsigned int req_count; + /* + * aio_kiocb alloc cache + */ + void *iocbs[AIO_IOPOLL_BATCH]; + unsigned int free_iocbs; + unsigned int cur_iocb; + /* * File reference cache */ @@ -1102,11 +1111,32 @@ static void aio_iocb_init(struct kioctx *ctx, struct aio_kiocb *req) * Allocate a slot for an aio request. * Returns NULL if no requests are free. */ -static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx) +static struct aio_kiocb *aio_get_req(struct kioctx *ctx, + struct aio_submit_state *state) { struct aio_kiocb *req; - req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL); + if (!state) + req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL); + else if (!state->free_iocbs) { + size_t size; + + size = min_t(size_t, state->ios_left, ARRAY_SIZE(state->iocbs)); + size = kmem_cache_alloc_bulk(kiocb_cachep, GFP_KERNEL, size, + state->iocbs); + if (size < 0) + return ERR_PTR(size); + else if (!size) + return ERR_PTR(-ENOMEM); + state->free_iocbs = size - 1; + state->cur_iocb = 1; + req = state->iocbs[0]; + } else { + req = state->iocbs[state->cur_iocb]; + state->free_iocbs--; + state->cur_iocb++; + } + if (req) aio_iocb_init(ctx, req); @@ -1347,8 +1377,6 @@ static bool aio_read_events(struct kioctx *ctx, long min_nr, long nr, return ret < 0 || *i >= min_nr; } -#define AIO_IOPOLL_BATCH 8 - /* * Process completed iocb iopoll entries, copying the result to userspace. */ @@ -2320,7 +2348,7 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb, return -EAGAIN; ret = -EAGAIN; - req = aio_get_req(ctx); + req = aio_get_req(ctx, state); if (unlikely(!req)) goto out_put_reqs_available; @@ -2452,6 +2480,9 @@ static void aio_submit_state_end(struct aio_submit_state *state) if (!list_empty(&state->req_list)) aio_flush_state_reqs(state->ctx, state); aio_file_put(state); + if (state->free_iocbs) + kmem_cache_free_bulk(kiocb_cachep, state->free_iocbs, + &state->iocbs[state->cur_iocb]); } /* @@ -2463,6 +2494,7 @@ static void aio_submit_state_start(struct aio_submit_state *state, state->ctx = ctx; INIT_LIST_HEAD(&state->req_list); state->req_count = 0; + state->free_iocbs = 0; state->file = NULL; state->ios_left = max_ios; #ifdef CONFIG_BLOCK