From patchwork Wed Jan 23 15:35:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10777457 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 A92581399 for ; Wed, 23 Jan 2019 15:36:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4FC2CA5A for ; Wed, 23 Jan 2019 15:36:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ED6A2CF1D; Wed, 23 Jan 2019 15:36:10 +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 485122CA5A for ; Wed, 23 Jan 2019 15:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726265AbfAWPgJ (ORCPT ); Wed, 23 Jan 2019 10:36:09 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39254 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726235AbfAWPgI (ORCPT ); Wed, 23 Jan 2019 10:36:08 -0500 Received: by mail-pg1-f194.google.com with SMTP id w6so1229937pgl.6 for ; Wed, 23 Jan 2019 07:36:07 -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=U1wUTZwaRtIZRdk1VT/3tLjLiqjg26G0o06pj1r/SNMSfiY9V9ovzFoLsaTXdtLgTz Z0/31oCbEQEDa/dMwz284qrVsqVAO5LAA0zeqTbKZPx1PlhGPGQTG04+HBOct0DOCmfr wp65FH5upJ8ZkbdUsJBrPjDtiSjr0LCTlxnwEV3QfxF2uoVwPR981VHPKo9RWjOsKoMs xP/Q4fc4LAQK3EbvYvdaB3zcXm3pQ1Ir19gnsgsOpV40mAn4gMldxsJRtwtNKxyzaFOI pYJH96AeCVqBTJJapboFRi6emyyyvKd4Pb8xPonFjWbPMezlOxsmvHcY3HEZ3Q0GDn1E bx4w== 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=TmZ6SgzN57A35thdEnHagTbMoWJKHma9nsBlEV+m25ekPp/m79JiFqYaDrt+AdCSS8 vwNsuSXrz2HI4/CHkeK/BE1IjAXRm1DJy5RxKQ6Qspd18T0Xt8lM7xmTLyJJdX8gJSdi YCVj5YD4rokR8fSQes9mAgoh8WdmeKip/VP2Iy12aljJZ6XXQxceTR25J5FtejQBMT8V i+A/dTlYHw5O5MuSwqq6l6ClnbPjLTrvDCWMpNMPB/76dQcjU5/zCI2qOc35ub2GJwDZ 9KmAtc/L+Vtguqwiv43qr8OFpjtlkvmjdyOeEDZH5rqPqZNgll9Np3sOBb9X3ZNDZw5k fOiQ== X-Gm-Message-State: AJcUukcGoqP3ba73M3wOfFyOu8ha8GK5snPxFW+cD9y0PS2Z4MBDC2U/ fmgXiCsCNTKJknOhNCQXP7VX2YY5Yj3OpA== X-Google-Smtp-Source: ALg8bN6ZdDm1+KmWjKh0xgKk90lub9Ij7IrqpVaZOBkEMG2qJj4Fc04oWpoaI5lxqFb28GCsVMUOmQ== X-Received: by 2002:a63:e247:: with SMTP id y7mr2265364pgj.84.1548257767152; Wed, 23 Jan 2019 07:36:07 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 07:36:06 -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/13] io_uring: add io_kiocb ref count Date: Wed, 23 Jan 2019 08:35:24 -0700 Message-Id: <20190123153536.7081-14-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); + } } /*