From patchwork Tue Dec 4 23:37:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10712741 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 6677E17D5 for ; Tue, 4 Dec 2018 23:37:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5826B29C06 for ; Tue, 4 Dec 2018 23:37:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CB1529EB9; Tue, 4 Dec 2018 23:37:54 +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 CE8F729C06 for ; Tue, 4 Dec 2018 23:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbeLDXhx (ORCPT ); Tue, 4 Dec 2018 18:37:53 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38693 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726001AbeLDXhx (ORCPT ); Tue, 4 Dec 2018 18:37:53 -0500 Received: by mail-pg1-f195.google.com with SMTP id g189so8094594pgc.5 for ; Tue, 04 Dec 2018 15:37:52 -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=X5thebUgmjkZJznWx9PghrfmA/cZ8t8Zs5+DcD2OHEI=; b=dE8WS+kUC7yZA4W/psiXS2ohAuqeprvpmbU6SBBH2j//376jO5T895dTIRaKHvHs4i 4LXsmnPEopGbxesEKPAAIpWzOguX+nEM1KE1AK9UzjaITvaiFXrJ4Rl+R8a3rDJXvhxO ipcpJh/omuzdnmyroasy9amsPxS4Y3+7AlMqGAMiPc2SHBnp7D72Ych4lcIcJ3FDnwCd wUglliba9O8OjMMh9jsjoV2iCckthmeKav0NjAXJh83GTSQkekOwmSYKFXSlkyxAMuOl 7FPOL7nSsRy+NFEC115kEWA1EfeJkQZAvw4WNaZn31cLedsLxDyW7kg5vGFl+wCCFAfo UgMA== 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=X5thebUgmjkZJznWx9PghrfmA/cZ8t8Zs5+DcD2OHEI=; b=qxuqZyNxjyukW30u4/213VWBOx9FDNpE6wQzXfYwP/ylBkzsKhPHuplcrMQsQumpTV FveFF+Fdm4VtW88MjNRv9DVDNC9CAKwTMqaMRmFfDMh9N8ctmttzytSd5l/mAOJAZeph TOyzqugvdHgpMlKxowHRamORHolOiv+umeXLaApQFU6XN4nrCRMnk8k2hYwXC3LZJ/Gk PEOy7Qf4XT8qABur/mch/95oM1m6JO5qu8HzBxvnIbsKy7/67XTJp7p2CxujbDMUPZFE 8JEIPrnn9tORD+Ws8Bd6yD3LeC/VTbzKRUDCxtBat0p0lB3Rn+CIFZjDvQVKI9D5NRIX yZCg== X-Gm-Message-State: AA+aEWYyG4ULyfl8mP6py/v8uGqqjUf8ye6xXAwnohC9ezsW0DEMkAWi 2v5X6Ny7WhiELljEw13ZNsXyUGkeJCo= X-Google-Smtp-Source: AFSGD/UVaMY5FzeFtJ9H4penb1h/+C7kMxs1mWyVILtRTdEOYh5ylEJTTUtloBU3PRxVG3ELb2mc7w== X-Received: by 2002:a63:63c3:: with SMTP id x186mr18526940pgb.330.1543966672509; Tue, 04 Dec 2018 15:37:52 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id t13sm22527635pgr.42.2018.12.04.15.37.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 15:37:50 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org Cc: hch@lst.de, jmoyer@redhat.com, Jens Axboe Subject: [PATCH 07/26] aio: separate out ring reservation from req allocation Date: Tue, 4 Dec 2018 16:37:10 -0700 Message-Id: <20181204233729.26776-8-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181204233729.26776-1-axboe@kernel.dk> References: <20181204233729.26776-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 From: Christoph Hellwig This is in preparation for certain types of IO not needing a ring reserveration. Signed-off-by: Christoph Hellwig Signed-off-by: Jens Axboe --- fs/aio.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index cf0de61743e8..eaceb40e6cf5 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -901,7 +901,7 @@ static void put_reqs_available(struct kioctx *ctx, unsigned nr) local_irq_restore(flags); } -static bool get_reqs_available(struct kioctx *ctx) +static bool __get_reqs_available(struct kioctx *ctx) { struct kioctx_cpu *kcpu; bool ret = false; @@ -993,6 +993,14 @@ static void user_refill_reqs_available(struct kioctx *ctx) spin_unlock_irq(&ctx->completion_lock); } +static bool get_reqs_available(struct kioctx *ctx) +{ + if (__get_reqs_available(ctx)) + return true; + user_refill_reqs_available(ctx); + return __get_reqs_available(ctx); +} + /* aio_get_req * Allocate a slot for an aio request. * Returns NULL if no requests are free. @@ -1001,24 +1009,15 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx) { struct aio_kiocb *req; - if (!get_reqs_available(ctx)) { - user_refill_reqs_available(ctx); - if (!get_reqs_available(ctx)) - return NULL; - } - req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL|__GFP_ZERO); if (unlikely(!req)) - goto out_put; + return NULL; percpu_ref_get(&ctx->reqs); INIT_LIST_HEAD(&req->ki_list); refcount_set(&req->ki_refcnt, 0); req->ki_ctx = ctx; return req; -out_put: - put_reqs_available(ctx, 1); - return NULL; } static struct kioctx *lookup_ioctx(unsigned long ctx_id) @@ -1805,9 +1804,13 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, return -EINVAL; } + if (!get_reqs_available(ctx)) + return -EAGAIN; + + ret = -EAGAIN; req = aio_get_req(ctx); if (unlikely(!req)) - return -EAGAIN; + goto out_put_reqs_available; if (iocb.aio_flags & IOCB_FLAG_RESFD) { /* @@ -1870,11 +1873,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, goto out_put_req; return 0; out_put_req: - put_reqs_available(ctx, 1); percpu_ref_put(&ctx->reqs); if (req->ki_eventfd) eventfd_ctx_put(req->ki_eventfd); kmem_cache_free(kiocb_cachep, req); +out_put_reqs_available: + put_reqs_available(ctx, 1); return ret; }