From patchwork Wed Jan 23 15:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10777497 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 52AE81399 for ; Wed, 23 Jan 2019 15:36:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 445D22CB00 for ; Wed, 23 Jan 2019 15:36:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38A832CFC0; Wed, 23 Jan 2019 15:36:29 +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 E7E512CB00 for ; Wed, 23 Jan 2019 15:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726345AbfAWPg2 (ORCPT ); Wed, 23 Jan 2019 10:36:28 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37622 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbfAWPg0 (ORCPT ); Wed, 23 Jan 2019 10:36:26 -0500 Received: by mail-pf1-f194.google.com with SMTP id y126so1353876pfb.4 for ; Wed, 23 Jan 2019 07:36: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=xuCT6eBYZtmluqgZSIP7z54GOK7JK42Z5rDnSlWKERE=; b=rRUIo1jUDqtLwqAiYR2I2RiQhcz+ceiQ00mSdgCE/bVaxU2oqPaPEA6/A+Zq5KY+dS 8umcP68IzVPDO/IvY3fF8bXiG2IwQU/E6xGHZgIXaLy8fAukee4gfeEs9HrkC0scIIOO 3Gn/yu9C2JBcEJFTuC80Dk1HNzChZImgBn9BFqCzuBuia0B2oOPqtLQ9MXR4qtwNdmbX +U73de3g9ztgPdNViRGTglE/SaV3CfedfAjXRMo2QO0jbvCsRwQujsInGJn6ePSwRKDn MeczxsnD5rPDVsknRVzzlbXksxsHCXMeBH90/6lYYIwMYBFr9qhNZ5jdthJUccJAc+nF 9KCg== 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=xuCT6eBYZtmluqgZSIP7z54GOK7JK42Z5rDnSlWKERE=; b=uSa/nDTPPqPjmdGKyDvCBHyojClYupDgj49IJgOArP9v92v6l894+vgz0XmEMnb+ok x+U1qlIp3+d0lMrx/BKfKOmaz0pCu7GJlXvlWfV0YCHTv/6ysfWLfSxKv9M+K+ak1FSu QJTcxnTxcJqp3p0LjzRUP30ef3adxqqbtsmOspwZmI9fDrF3mEA9jbAB3yBkihW+23hl /cFXgRjEpxJDepQLccOf63/9o1ifq1K5X6ChMxpLrDkcEmGzVrytv3oFLVJ/IRoU3Mj/ HYMwQL1cIMzhv/yf80P+G08ZG9IuiiHI0xgdBrcB1KzkGF0ToGE/F/TehIchWV0rWsCX 6gug== X-Gm-Message-State: AJcUukc8wE2bJSyaWyDyanXxDFCBdhxF3seSMdLJKYCM7Nab0AJBI1fB m4ZFVax+Ggjhjiog93haBDfvQ6IgLU1gAw== X-Google-Smtp-Source: ALg8bN5hNaTwCXFw8do6QrLm72+wOZEwbyzG0bwTwPd3ButQeHcfqyeDUK2aTtwFCXPJxO5g9JfLyg== X-Received: by 2002:a62:b15:: with SMTP id t21mr2494946pfi.136.1548257784875; Wed, 23 Jan 2019 07:36:24 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id u8sm30731715pfl.16.2019.01.23.07.36.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 07:36:24 -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 15/18] io_uring: add io_kiocb ref count Date: Wed, 23 Jan 2019 08:35:33 -0700 Message-Id: <20190123153536.7081-23-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190123153536.7081-1-axboe@kernel.dk> References: <20190123153536.7081-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 We'll use this for the POLL implementation. Regular requests will NOT be using references, so initialize it to 0. Any real use of the io_kiocb ref will initialize it to at least 2. Signed-off-by: Jens Axboe --- fs/io_uring.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 2deda7b1b3dd..c10653be39c0 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -141,6 +141,7 @@ struct io_kiocb { struct io_ring_ctx *ctx; struct list_head list; unsigned int flags; + refcount_t refs; #define REQ_F_FORCE_NONBLOCK 1 /* inline submission attempt */ #define REQ_F_IOPOLL_COMPLETED 2 /* polled IO has completed */ #define REQ_F_IOPOLL_EAGAIN 4 /* submission got EAGAIN */ @@ -322,6 +323,7 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx, if (req) { req->ctx = ctx; req->flags = 0; + refcount_set(&req->refs, 0); return req; } @@ -341,8 +343,10 @@ static void io_free_req_many(struct io_ring_ctx *ctx, void **reqs, int *nr) static void io_free_req(struct io_kiocb *req) { - io_ring_drop_ctx_refs(req->ctx, 1); - kmem_cache_free(req_cachep, req); + if (!refcount_read(&req->refs) || refcount_dec_and_test(&req->refs)) { + io_ring_drop_ctx_refs(req->ctx, 1); + kmem_cache_free(req_cachep, req); + } } /*