From patchwork Fri Jan 18 16:12:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10770821 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 693B213B4 for ; Fri, 18 Jan 2019 16:13:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58DC82F432 for ; Fri, 18 Jan 2019 16:13:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D94C2F571; Fri, 18 Jan 2019 16:13: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 046F92F432 for ; Fri, 18 Jan 2019 16:13:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbfARQNJ (ORCPT ); Fri, 18 Jan 2019 11:13:09 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37963 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbfARQNJ (ORCPT ); Fri, 18 Jan 2019 11:13:09 -0500 Received: by mail-pg1-f194.google.com with SMTP id g189so6260430pgc.5 for ; Fri, 18 Jan 2019 08:13:08 -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=DTlkF97vGefqpS0bMWv746R15dMGRBYhpLm7YzqPk8E=; b=Vpd+bVRIeZu+98XKdNR5oAaJQdU3jBp1Sxi8qU7IQAPY7TIokkpLgrKpmwc3uy6iH1 x0Jp9e4lWBwqXdfCf7jN5xUAsGyrun3Gq22lre5vaDMoZJArjgAumCFZFsqGyfwSb07g 4ka/VZsFLjPMC1D7gLtbOwUdQTCFmGUs5Zle63XTJz4VIKJOUmL1QLBB34B3+APp4L2+ yvwx+4WJvK3Wm+vrk/vExHJmxauzzv+RJ26U/7jIWMCqgH/fR6kFRMDOT3/bUTC0eSZv l4vL6W4VtqjhBSM3clzku2i3Z/5K1aDnMdZWSpvRtCKcfHQckH38Qt/7Do3PAvxpIdg9 issA== 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=DTlkF97vGefqpS0bMWv746R15dMGRBYhpLm7YzqPk8E=; b=Bwn2HP6Z2bw9KBEyYu34kA8m4j/DYaLvPBqDpk98pGzAaPIZd40/JcalWSdYhQ/lU5 fWswL0J4WQFOD7gHQcyuYHF0UyFie9b/4WrDirewluGGjHhBhXNwKQGYAdKp5HEatYFF LS13UEAFcxgRDyfS30zJ2woyoc1Cn6p94rvYrAXKoSldxWYDp+hs3dEoTGLccIviitvU bNmTsbfHr5okP3qnZUjVfiIWbIGGZuwIwKzBX3AiGDiPUolbWEGCM55jk7hHYFbKfDDV WqRhvzkDiib9ztfxP+Z3L9U8u7BNcpg7LLqHeARwqWUNobj2T32KF3X5l2VVQnwSPHsG 8D5A== X-Gm-Message-State: AJcUukeFCn7Y+eCj5niGUk0l1hq20OqYNhreekD2k2GJZjgdYpi8U+N0 V4vqr9SHD1u7Exba1mwQ6EFVnghU67QEXA== X-Google-Smtp-Source: ALg8bN51A4DrcA9djqPZFWlvZUqpGWUCbey9g5sJ1DeJWqt4np/zgv/BqeGZ92uOU3ipTg3fYR2zXw== X-Received: by 2002:a63:5ec6:: with SMTP id s189mr17528226pgb.357.1547827987643; Fri, 18 Jan 2019 08:13: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 m20sm5317804pgv.93.2019.01.18.08.13.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 08:13: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 15/17] io_uring: add io_kiocb ref count Date: Fri, 18 Jan 2019 09:12:23 -0700 Message-Id: <20190118161225.4545-16-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 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 cdd9873edfe3..4f13b3371156 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); + } } /*