From patchwork Tue Jan 29 15:47:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10786517 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 1305014E1 for ; Tue, 29 Jan 2019 15:47:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 010262CEEC for ; Tue, 29 Jan 2019 15:47:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E99992CEED; Tue, 29 Jan 2019 15:47:57 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 9DE322CDE7 for ; Tue, 29 Jan 2019 15:47:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbfA2Pr4 (ORCPT ); Tue, 29 Jan 2019 10:47:56 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45456 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbfA2Pr4 (ORCPT ); Tue, 29 Jan 2019 10:47:56 -0500 Received: by mail-wr1-f66.google.com with SMTP id t6so22579351wrr.12 for ; Tue, 29 Jan 2019 07:47:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=E4MKslIV05xWh4l1wKj2vgGSS530K1EBt3sGfeVP3ow=; b=unPgHVyrO9lhEMVu1VjEChVc5/mIu91L+pjHPNtBLqXQGJdtnHGT905xU8FpL1nzEl X1OCzHjZ7HKDR4RmRs0MEQKh6PWrNwheeg15ANU4vWYqvna0X4uRW+o5iX1hY0M7H2C4 OWXnOYuRphpVy9DKzqSZ3IwYhvAjHQiHI4RRRC/ueQPTjATk0JKo8lWm/YOIENzbKzkO JumOHFF1A2WyBI/HLDgyug5SzTYx7/hP3Go/zgE7BFTS4Pwe1DiLp6IHQgR7usSVav6Z QmAPAbu6k/WcCE2WH8fy/yAVV0a0DQrsZREOP08TBxUu/fgL7d5oFRQaKSFvzXYT0WsI 8A8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=E4MKslIV05xWh4l1wKj2vgGSS530K1EBt3sGfeVP3ow=; b=clvtWivLTQaHwEfltLX9MqLUcHg7lySKSBC/mXN68a0HsW0qnhiaj2Ky21IjHetfna 5byH1V6EKO1V5iBxbWMNMKy6Ezco6LZcE2ih80TLM/i5VbIJoP7Ztt46CXa78NAGg4eV 7ZJ9hNRcf91vA0UpnqoaiqOWufUrXzlYvMiUwgXFhRSxmzfZwxWzNAW1GrU/n1B8Z4yQ Up3Lkw5OpYUNUYG6c0T9ZjWfwTJPh6+aFEHOymZGHX0Ffo+4zFU8Y5ceTbrXX9H/nert 5JZA+f/dtA2i/2syil7qta3EAeQPdR8wZWI34m0V7XmrdVMDt/9yh5aZBhlWeZgzrJpe nlHQ== X-Gm-Message-State: AJcUukdBDzPlj1MI1y8loaBfNyQhXuFIn5ySU3qsqwXITZtpT/9s5HBr 1Prndx69mIK8yJHjfl3woaw3x0dQ X-Google-Smtp-Source: ALg8bN7oDNctQrS06HJHlrm31rI9VGZ8Rm9/Z7wAfz+dglqJ37T3QOVBlgWyzS8caDo2aX9snMRsYw== X-Received: by 2002:adf:ee89:: with SMTP id b9mr27410387wro.246.1548776874408; Tue, 29 Jan 2019 07:47:54 -0800 (PST) Received: from orange.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g9sm3129423wmg.44.2019.01.29.07.47.53 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 07:47:53 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 1/3] rbd: get rid of obj_req->obj_request_count Date: Tue, 29 Jan 2019 16:47:27 +0100 Message-Id: <20190129154729.1031-2-idryomov@gmail.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190129154729.1031-1-idryomov@gmail.com> References: <20190129154729.1031-1-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is effectively unused. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 2f91dee0ab5f..7f78b814d57f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -291,7 +291,6 @@ struct rbd_img_request { int result; /* first nonzero obj_request result */ struct list_head object_extents; /* obj_req.ex structs */ - u32 obj_request_count; u32 pending_count; struct kref kref; @@ -1345,7 +1344,6 @@ static inline void rbd_img_obj_request_add(struct rbd_img_request *img_request, /* Image request now owns object's original reference */ obj_request->img_request = img_request; - img_request->obj_request_count++; img_request->pending_count++; dout("%s: img %p obj %p\n", __func__, img_request, obj_request); } @@ -1355,8 +1353,6 @@ static inline void rbd_img_obj_request_del(struct rbd_img_request *img_request, { dout("%s: img %p obj %p\n", __func__, img_request, obj_request); list_del(&obj_request->ex.oe_item); - rbd_assert(img_request->obj_request_count > 0); - img_request->obj_request_count--; rbd_assert(obj_request->img_request == img_request); rbd_obj_request_put(obj_request); } @@ -1672,7 +1668,6 @@ static void rbd_img_request_destroy(struct kref *kref) for_each_obj_request_safe(img_request, obj_request, next_obj_request) rbd_img_obj_request_del(img_request, obj_request); - rbd_assert(img_request->obj_request_count == 0); if (img_request_layered_test(img_request)) { img_request_layered_clear(img_request); From patchwork Tue Jan 29 15:47:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10786519 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 7FFE01390 for ; Tue, 29 Jan 2019 15:48:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E5F42CADC for ; Tue, 29 Jan 2019 15:48:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F3EE2CEED; Tue, 29 Jan 2019 15:48:00 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 AA99A2CADC for ; Tue, 29 Jan 2019 15:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727512AbfA2Pr6 (ORCPT ); Tue, 29 Jan 2019 10:47:58 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36835 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbfA2Pr6 (ORCPT ); Tue, 29 Jan 2019 10:47:58 -0500 Received: by mail-wm1-f66.google.com with SMTP id p6so18293191wmc.1 for ; Tue, 29 Jan 2019 07:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=q58NgTMXPV4o+9oNQwc0lQ3/x/i9CYytxUSpD9gDhJ8=; b=ebPeel2Yiv4ylictqbjaCg8F0UM6YqC9ng5VJ2rOubN1ea1MUbfnNjEuK3jfjD1eic XPPuzzxn/bby9h7fmZ9N6IncaOGIWbzVqlJloM2otKgp+6I3BdxFKjFZ2c8YbkfMrLPL BnQHVKOJ9hH4QIRjDvYE4gz/aMs5MRunyB+th9zJmkgZVbtOK8IJ9M+uaO5IMEHYK5Ab n6PrS65lBnmxsHNcAyXrNvgbRuUz785M06HXRmqEaBY8AZvZLd3GgfSw8c1EqE6ZSjSE DEohNuQib1gSbXGJZOu5HFPLlfoUhgAhcuzAqE5kZCB8CrL2Xr6Kl02m7lHPBgm7299c +/+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=q58NgTMXPV4o+9oNQwc0lQ3/x/i9CYytxUSpD9gDhJ8=; b=Gdo0jMvT0BJOwW0OZvNM7DMdpwCTaUzckVeW10YLrE1HEsNvBR2fF2oiFCvgktLbF+ srDFS4k/zMUArr1QaeEdGd2IuEobATTAsfjD9J/brxdaYgy9ZX/bd++E3FT5cufJwhcp DZm626XbVRZ5V5on9H4xNKZQKVQr2jONjCa0jhhpc5x3HvNRB00J2KyQVGwnvMSd/JaF mTOQ9mZMLfG7Lgw2aykmyL5nJEGXMkVrUK8Sh9v5AuGzhp+VQQnjCcw9V2XyhZ6E+jM9 Yksnu4ZjT86ofYQ/h0duDVtiDFfgtKLxNqvk2/1unAIGnVBWM7y8xlHz54bSsS/oQi+2 1DSw== X-Gm-Message-State: AJcUukeRgaigOpyKxEaYsHvYJz++wI0mjB9VDBzVUd3deqorxm+POrYJ pn03FeLtQiHwk9Wwi/hBTYaEDywG X-Google-Smtp-Source: ALg8bN4NB0o4acjaOF7he43gWZ4vDD8z+fH7CD+ewTp0WZtyLAEQp72t8Ym44aLWTR8h8Ck5q2gGTQ== X-Received: by 2002:a1c:c181:: with SMTP id r123mr21698416wmf.8.1548776875396; Tue, 29 Jan 2019 07:47:55 -0800 (PST) Received: from orange.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g9sm3129423wmg.44.2019.01.29.07.47.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 07:47:54 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 2/3] rbd: handle DISCARD and WRITE_ZEROES separately Date: Tue, 29 Jan 2019 16:47:28 +0100 Message-Id: <20190129154729.1031-3-idryomov@gmail.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190129154729.1031-1-idryomov@gmail.com> References: <20190129154729.1031-1-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With discard_zeroes_data gone in commit 48920ff2a5a9 ("block: remove the discard_zeroes_data flag"), continuing to provide this guarantee is pointless: applications can't query it and discards can only be used for deallocating. Add OBJ_OP_ZEROOUT and move the existing logic under it. As the first step to divorcing OBJ_OP_DISCARD, stop doing copyups and worrying about whether parent blocks are still seen after the discard. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 54 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 7f78b814d57f..87f30bf49f1f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -214,6 +214,7 @@ enum obj_operation_type { OBJ_OP_READ = 1, OBJ_OP_WRITE, OBJ_OP_DISCARD, + OBJ_OP_ZEROOUT, }; /* @@ -857,6 +858,8 @@ static char* obj_op_name(enum obj_operation_type op_type) return "write"; case OBJ_OP_DISCARD: return "discard"; + case OBJ_OP_ZEROOUT: + return "zeroout"; default: return "???"; } @@ -1419,6 +1422,7 @@ static bool rbd_img_is_write(struct rbd_img_request *img_req) return false; case OBJ_OP_WRITE: case OBJ_OP_DISCARD: + case OBJ_OP_ZEROOUT: return true; default: BUG(); @@ -1841,7 +1845,33 @@ static int rbd_obj_setup_write(struct rbd_obj_request *obj_req) return 0; } -static void __rbd_obj_setup_discard(struct rbd_obj_request *obj_req, +static u16 truncate_or_zero_opcode(struct rbd_obj_request *obj_req) +{ + return rbd_obj_is_tail(obj_req) ? CEPH_OSD_OP_TRUNCATE : + CEPH_OSD_OP_ZERO; +} + +static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req) +{ + obj_req->osd_req = rbd_osd_req_create(obj_req, 1); + if (!obj_req->osd_req) + return -ENOMEM; + + if (rbd_obj_is_entire(obj_req)) { + osd_req_op_init(obj_req->osd_req, 0, CEPH_OSD_OP_DELETE, 0); + } else { + osd_req_op_extent_init(obj_req->osd_req, 0, + truncate_or_zero_opcode(obj_req), + obj_req->ex.oe_off, obj_req->ex.oe_len, + 0, 0); + } + + obj_req->write_state = RBD_OBJ_WRITE_FLAT; + rbd_osd_req_format_write(obj_req); + return 0; +} + +static void __rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req, unsigned int which) { u16 opcode; @@ -1856,10 +1886,8 @@ static void __rbd_obj_setup_discard(struct rbd_obj_request *obj_req, CEPH_OSD_OP_DELETE, 0); opcode = 0; } - } else if (rbd_obj_is_tail(obj_req)) { - opcode = CEPH_OSD_OP_TRUNCATE; } else { - opcode = CEPH_OSD_OP_ZERO; + opcode = truncate_or_zero_opcode(obj_req); } if (opcode) @@ -1871,7 +1899,7 @@ static void __rbd_obj_setup_discard(struct rbd_obj_request *obj_req, rbd_osd_req_format_write(obj_req); } -static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req) +static int rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req) { unsigned int num_osd_ops, which = 0; int ret; @@ -1907,7 +1935,7 @@ static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req) return ret; } - __rbd_obj_setup_discard(obj_req, which); + __rbd_obj_setup_zeroout(obj_req, which); return 0; } @@ -1932,6 +1960,9 @@ static int __rbd_img_fill_request(struct rbd_img_request *img_req) case OBJ_OP_DISCARD: ret = rbd_obj_setup_discard(obj_req); break; + case OBJ_OP_ZEROOUT: + ret = rbd_obj_setup_zeroout(obj_req); + break; default: rbd_assert(0); } @@ -2392,9 +2423,9 @@ static int rbd_obj_issue_copyup(struct rbd_obj_request *obj_req, u32 bytes) case OBJ_OP_WRITE: __rbd_obj_setup_write(obj_req, 1); break; - case OBJ_OP_DISCARD: + case OBJ_OP_ZEROOUT: rbd_assert(!rbd_obj_is_entire(obj_req)); - __rbd_obj_setup_discard(obj_req, 1); + __rbd_obj_setup_zeroout(obj_req, 1); break; default: rbd_assert(0); @@ -2524,6 +2555,7 @@ static bool __rbd_obj_handle_request(struct rbd_obj_request *obj_req) case OBJ_OP_WRITE: return rbd_obj_handle_write(obj_req); case OBJ_OP_DISCARD: + case OBJ_OP_ZEROOUT: if (rbd_obj_handle_write(obj_req)) { /* * Hide -ENOENT from delete/truncate/zero -- discarding @@ -3636,9 +3668,11 @@ static void rbd_queue_workfn(struct work_struct *work) switch (req_op(rq)) { case REQ_OP_DISCARD: - case REQ_OP_WRITE_ZEROES: op_type = OBJ_OP_DISCARD; break; + case REQ_OP_WRITE_ZEROES: + op_type = OBJ_OP_ZEROOUT; + break; case REQ_OP_WRITE: op_type = OBJ_OP_WRITE; break; @@ -3718,7 +3752,7 @@ static void rbd_queue_workfn(struct work_struct *work) img_request->rq = rq; snapc = NULL; /* img_request consumes a ref */ - if (op_type == OBJ_OP_DISCARD) + if (op_type == OBJ_OP_DISCARD || op_type == OBJ_OP_ZEROOUT) result = rbd_img_fill_nodata(img_request, offset, length); else result = rbd_img_fill_from_bio(img_request, offset, length, From patchwork Tue Jan 29 15:47:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10786521 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 C2DE11390 for ; Tue, 29 Jan 2019 15:48:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B08772CADC for ; Tue, 29 Jan 2019 15:48:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4AD42CEDC; Tue, 29 Jan 2019 15:48:01 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 215E92CADC for ; Tue, 29 Jan 2019 15:48:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbfA2PsA (ORCPT ); Tue, 29 Jan 2019 10:48:00 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34312 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725846AbfA2Pr7 (ORCPT ); Tue, 29 Jan 2019 10:47:59 -0500 Received: by mail-wm1-f66.google.com with SMTP id y185so13281967wmd.1 for ; Tue, 29 Jan 2019 07:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=JELi5Y0i9mNyLhYIRHNHnX5cvRp987Geg2DWrZDJicM=; b=OcddzblE527FuBXiEpz9IsKNhDaDia0rPXBqtXh1fs5vrJyHCA12H+YZttn6fHwYh2 9h2fGPU8e78iKD2JYk6aRMDPNz0imD5Erqmbi0qBnCGsfIF+FA3yNhu6eVB66Y1Ug+Xi bOuJx4jcwiFgjPddqH+rkK9FL/CysnOhQrJzF9X6iMtTHW//i8mL5RzvnTjxawHASdqy 5PBf8O75X5/KONH/NbDMRRqwgb4awgAqR4fgTvSP99l4NTQ7+/8P/VZRfQSNDr9Wk7v4 ukVY41c3QaLGuQnnRdJSlEhUImDPYnNf8jzL3IJOcWljy6gEGY1epUlC/983HdVtLJbU pQwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JELi5Y0i9mNyLhYIRHNHnX5cvRp987Geg2DWrZDJicM=; b=PByaYd0IGchTHQ97eSasoA0dGGmYv6Vkn1WP8KpQmg/nfVKWe6pm7NVkplrKekNAQ1 EXFJZfBu4XLJcMVaAlW57PNTNUfnMEN+BOukyXZvkP59OWqriIh50Ja746F4HxlOxynY +7zuanAtFnJ0aPJXcmMth+//+Sp/4nP2XOw0M6ogPeuJeNBur66wYt0ElLmaVmvra75n 49t2Osm+yamaiw1/Vvl0T8dmDz0cho6KKUR6kMmtYpAi9bYcd8emX7qsW9IjX23wGzB5 mbXo3QD3ykpO+JE7j4369O2+ibBNNT0Elcj11HcUuGA4CgmmpoN4HSbuo7BkM2IkRWKR 0oTQ== X-Gm-Message-State: AJcUukc49/U6Tz0C7qzEzXSEgn5vP/byMhzkDMCDdyOioNfXy4VIdqIu 4ywltZvOZ9jUb7dAO4VYmKqlfGZ8 X-Google-Smtp-Source: ALg8bN7CPYGl+YiYEoSHEi0ygTNk1Bju9XciZmkobe/nemR5hUn7AomgYzbH0OfdpdmfM4KLmLil8g== X-Received: by 2002:a7b:cb86:: with SMTP id m6mr21653436wmi.61.1548776876455; Tue, 29 Jan 2019 07:47:56 -0800 (PST) Received: from orange.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g9sm3129423wmg.44.2019.01.29.07.47.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 Jan 2019 07:47:55 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Subject: [PATCH 3/3] rbd: round off and ignore discards that are too small Date: Tue, 29 Jan 2019 16:47:29 +0100 Message-Id: <20190129154729.1031-4-idryomov@gmail.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20190129154729.1031-1-idryomov@gmail.com> References: <20190129154729.1031-1-idryomov@gmail.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If, after rounding off, the discard request is smaller than alloc_size, drop it on the floor in __rbd_img_fill_request(). Default alloc_size to 64k. This should cover both HDD and SSD based bluestore OSDs and somewhat improve things for filestore. For OSDs on filestore with filestore_punch_hole = false, alloc_size is best set to object size in order to allow deletes and truncates and disallow zero op. Signed-off-by: Ilya Dryomov --- drivers/block/rbd.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 87f30bf49f1f..1f5517355af3 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -733,6 +733,7 @@ static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts) */ enum { Opt_queue_depth, + Opt_alloc_size, Opt_lock_timeout, Opt_last_int, /* int args above */ @@ -749,6 +750,7 @@ enum { static match_table_t rbd_opts_tokens = { {Opt_queue_depth, "queue_depth=%d"}, + {Opt_alloc_size, "alloc_size=%d"}, {Opt_lock_timeout, "lock_timeout=%d"}, /* int args above */ {Opt_pool_ns, "_pool_ns=%s"}, @@ -765,6 +767,7 @@ static match_table_t rbd_opts_tokens = { struct rbd_options { int queue_depth; + int alloc_size; unsigned long lock_timeout; bool read_only; bool lock_on_read; @@ -773,6 +776,7 @@ struct rbd_options { }; #define RBD_QUEUE_DEPTH_DEFAULT BLKDEV_MAX_RQ +#define RBD_ALLOC_SIZE_DEFAULT (64 * 1024) #define RBD_LOCK_TIMEOUT_DEFAULT 0 /* no timeout */ #define RBD_READ_ONLY_DEFAULT false #define RBD_LOCK_ON_READ_DEFAULT false @@ -812,6 +816,17 @@ static int parse_rbd_opts_token(char *c, void *private) } pctx->opts->queue_depth = intval; break; + case Opt_alloc_size: + if (intval < 1) { + pr_err("alloc_size out of range\n"); + return -EINVAL; + } + if (!is_power_of_2(intval)) { + pr_err("alloc_size must be a power of 2\n"); + return -EINVAL; + } + pctx->opts->alloc_size = intval; + break; case Opt_lock_timeout: /* 0 is "wait forever" (i.e. infinite timeout) */ if (intval < 0 || intval > INT_MAX / 1000) { @@ -1853,6 +1868,26 @@ static u16 truncate_or_zero_opcode(struct rbd_obj_request *obj_req) static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req) { + struct rbd_device *rbd_dev = obj_req->img_request->rbd_dev; + u64 off = obj_req->ex.oe_off; + u64 next_off = obj_req->ex.oe_off + obj_req->ex.oe_len; + + /* + * Align the range to alloc_size boundary and punt on discards + * that are too small to free up any space. + * + * alloc_size == object_size && is_tail() is a special case for + * filestore with filestore_punch_hole = false, needed to allow + * truncate (in addition to delete). + */ + if (rbd_dev->opts->alloc_size != rbd_dev->layout.object_size || + !rbd_obj_is_tail(obj_req)) { + off = round_up(off, rbd_dev->opts->alloc_size); + next_off = round_down(next_off, rbd_dev->opts->alloc_size); + if (off >= next_off) + return 1; + } + obj_req->osd_req = rbd_osd_req_create(obj_req, 1); if (!obj_req->osd_req) return -ENOMEM; @@ -1860,10 +1895,12 @@ static int rbd_obj_setup_discard(struct rbd_obj_request *obj_req) if (rbd_obj_is_entire(obj_req)) { osd_req_op_init(obj_req->osd_req, 0, CEPH_OSD_OP_DELETE, 0); } else { + dout("%s %p %llu~%llu -> %llu~%llu\n", __func__, + obj_req, obj_req->ex.oe_off, obj_req->ex.oe_len, + off, next_off - off); osd_req_op_extent_init(obj_req->osd_req, 0, truncate_or_zero_opcode(obj_req), - obj_req->ex.oe_off, obj_req->ex.oe_len, - 0, 0); + off, next_off - off, 0, 0); } obj_req->write_state = RBD_OBJ_WRITE_FLAT; @@ -1946,10 +1983,10 @@ static int rbd_obj_setup_zeroout(struct rbd_obj_request *obj_req) */ static int __rbd_img_fill_request(struct rbd_img_request *img_req) { - struct rbd_obj_request *obj_req; + struct rbd_obj_request *obj_req, *next_obj_req; int ret; - for_each_obj_request(img_req, obj_req) { + for_each_obj_request_safe(img_req, obj_req, next_obj_req) { switch (img_req->op_type) { case OBJ_OP_READ: ret = rbd_obj_setup_read(obj_req); @@ -1966,8 +2003,14 @@ static int __rbd_img_fill_request(struct rbd_img_request *img_req) default: rbd_assert(0); } - if (ret) + if (ret < 0) return ret; + if (ret > 0) { + img_req->xferred += obj_req->ex.oe_len; + img_req->pending_count--; + rbd_img_obj_request_del(img_req, obj_req); + continue; + } ret = ceph_osdc_alloc_messages(obj_req->osd_req, GFP_NOIO); if (ret) @@ -3757,7 +3800,7 @@ static void rbd_queue_workfn(struct work_struct *work) else result = rbd_img_fill_from_bio(img_request, offset, length, rq->bio); - if (result) + if (result || !img_request->pending_count) goto err_img_request; rbd_img_request_submit(img_request); @@ -5418,6 +5461,7 @@ static int rbd_add_parse_args(const char *buf, pctx.opts->read_only = RBD_READ_ONLY_DEFAULT; pctx.opts->queue_depth = RBD_QUEUE_DEPTH_DEFAULT; + pctx.opts->alloc_size = RBD_ALLOC_SIZE_DEFAULT; pctx.opts->lock_timeout = RBD_LOCK_TIMEOUT_DEFAULT; pctx.opts->lock_on_read = RBD_LOCK_ON_READ_DEFAULT; pctx.opts->exclusive = RBD_EXCLUSIVE_DEFAULT;