From patchwork Mon Aug 27 15:29:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10577373 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 CD396920 for ; Mon, 27 Aug 2018 15:30:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B70A029AD7 for ; Mon, 27 Aug 2018 15:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB75C29CD8; Mon, 27 Aug 2018 15:30:07 +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,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 8B56629AD7 for ; Mon, 27 Aug 2018 15:30:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727172AbeH0TRK (ORCPT ); Mon, 27 Aug 2018 15:17:10 -0400 Received: from mail-eopbgr40117.outbound.protection.outlook.com ([40.107.4.117]:4992 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727101AbeH0TRK (ORCPT ); Mon, 27 Aug 2018 15:17:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=er6iB39TyC6kqCoTgFE4qoi35SU038dxvCaWk0F+emI=; b=PKaf+IGHdPmuBXF4MMFttzdsc0+aZKbjf5BlBFefkJb7QQdFiAFBH0To/wbjETJBm3OK1vX0bHHDKBFZ+U+1626XWZlzPP+WQsW5ixoFK0EbONVTMGemrXuIGcLIGurno3XF8aJfjACirXq5g3bBFNgwTIsDQlbTF/2vssNUG4Y= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (185.231.240.5) by DB6PR0801MB2021.eurprd08.prod.outlook.com (2603:10a6:4:76::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.17; Mon, 27 Aug 2018 15:29:58 +0000 Subject: [PATCH 6/6] fuse: Do not take fuse_conn::lock on fuse_request_send_background() From: Kirill Tkhai To: miklos@szeredi.hu, ktkhai@virtuozzo.com, linux-fsdevel@vger.kernel.org Date: Mon, 27 Aug 2018 18:29:56 +0300 Message-ID: <153538379617.18303.11871598131511120870.stgit@localhost.localdomain> In-Reply-To: <153538208536.18303.10732945923322972743.stgit@localhost.localdomain> References: <153538208536.18303.10732945923322972743.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: DB6P193CA0010.EURP193.PROD.OUTLOOK.COM (2603:10a6:6:29::20) To DB6PR0801MB2021.eurprd08.prod.outlook.com (2603:10a6:4:76::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff7aa21d-12bf-4392-1dd7-08d60c31f3b4 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:DB6PR0801MB2021; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB2021;3:pihUg+WK14othzYTNcIAAHRW1Q8ugBrKFYIXR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oG3YYRkmfA9zKj6zvfZ656Cc+bGKXkrtXOKIDyTg//DSKiZNs/2mvTLSQ7QjlOmRlVv0cdS1s1wq2JjEh7z+5MpTO25Y2NLKTixc2AfYLuA85xDQedI4zH1y4X5ssN9NeNUFYa7xVzXB7JFPuULeE9jyaomYOkCInPcAIgB3HYDdPLfJKVD4Ru24KSLmDum55HkoLSBZOgqXROEbmg4IpDEk3DSjHNIOJX2wWjGpk7ngDwBkAsgq2SA4+CkJs52xZynN40TDTLXIpg2kj0Q+dPRNmydVPeLjkYtFxU+bQkymc;4:bYbcZznMtgQ+SZ5LNEo+mptcXpCjWSkU80iJ8eu9NLOweXPtHzyJ8KVGDpZ7OY4IZIrmsepIkQEfPZ9v3RyYhwcKP9SF6h04aM+rsmzzUTiqMy40Z+XRpHZFlLH0+Sp7zqTD4/eIa9wnXNNIItGS1p7t3cqpDjKNmYWOGB3x68mkS8+4iLUmLj+6kQ6e3d0XJXKVDt/G3A9SRIJH/PbZVR1g3niZcvh66LVDDbUDdgR9ZZWnr5ofAn3SuSrJwxNRuyaZ0Ak7oTPJl9v6Xa+yYg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(201708071742011)(7699016);SRVR:DB6PR0801MB2021;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0801MB2021; X-Forefront-PRVS: 07778E4001 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(39850400004)(376002)(396003)(136003)(366004)(346002)(199004)(189003)(66066001)(97736004)(106356001)(305945005)(86362001)(61506002)(50466002)(105586002)(7736002)(25786009)(14444005)(446003)(11346002)(486006)(956004)(476003)(5660300001)(81156014)(81166006)(33896004)(58126008)(68736007)(103116003)(8676002)(7696005)(47776003)(8936002)(55016002)(230700001)(26005)(52116002)(6506007)(53936002)(386003)(6116002)(3846002)(16526019)(23676004)(2486003)(186003)(316002)(9686003)(76176011)(2906002)(478600001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0801MB2021;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BDB6PR0801MB2021=3B23=3AzcDEG?= =?utf-8?q?40fOXAJKMAtsSEyqMvkXxiohAebXYBXf0vf0smdwiv6BHEcJ21FtFUKo55l8iumRw?= =?utf-8?q?QvP/9NNPu7jWWIa0vw5gmoM9yK7VgVR3ZSlhlzWggbMgT5AzuA39jIuLTW7LUovgK?= =?utf-8?q?r/ERkviNRbOINw5W8UgeOQMHa+/7kQXHLFlFRax6y+eyCzNdVAzP3ohBkizaIJzDr?= =?utf-8?q?HLGZpwglywb9mOSf0ZTsQYxto0/Lz49rJEQCCPIPr/TgOY300YaMU5IjzZYZdD6Bk?= =?utf-8?q?iZO0/6eIFNLUSryvZgC7bhiiOiJFcscF1Ai4mW1S67mbFpxtRVyR+NWuPCpmdHSe3?= =?utf-8?q?nglV3ulNfF0qHsSiipDfbAomOtYDUrZv4nVFt4oMllXY9J0nRj/b4eFkA8e/w/TXN?= =?utf-8?q?0zWviljnqr5xUa0m9rpBI9L0Ll2pk9LyRucDXuhU5GE8S0if5yIvcP9V86inm/vB0?= =?utf-8?q?SuYdvRklGEHWcoTqCbawCQKfHUnKZZRYNiP4Ydjrjc/Gb0cLLP2+8y4EoppvGyQaG?= =?utf-8?q?kxcWlBPBAjSLodmmby5QInfNBkD3hO0Fc/EP8uzNZAmy+pWOIVuDFYki+oyNkODPi?= =?utf-8?q?q99xUq3DxOv6BDQNZtNRnym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soft-Exchange-Diagnostics: 1;DB6PR0801MB2021;6:CnzJhnMgg9RoS5yHeGXnHZyCY4/fus/XSIpzPbQQU7HV8Oz3/o/14OJfBPV7T+cYa6jkwKGmEQedd4CE/VH+GT1tMucty/EdRcJAi3VrryQjjZ1bdjzHI1gRgdp1WR5P0lpfxhiqi+e6AMw9Yk2cYnhOfZqFXcjw5CodgPh1iKWn2TVM8HVIHRzCph3dsApHsR1DtLsHxFbW/0FovAMeRrUmaFlskM4Mb0RQHRfberI8gOSL5VBksYuBHcikWaL/ysnFjug8aiIu/3/SCmpNLUCvLbRqirTe+g9biNSKVs9dVwxQyBkncC4Xcv146ElfcqddCJtfd2Kgi/k3gIzO2Jhv0JDk3aMlHlCF5ZXojYCjy3A+zCEkyRW+lr2F825HjyBH9jrfnsMEB+Jg22ISW5Ykd0JjqO7aPFZ3eALS3tA4rRHZIVn/+9W6RT1AiROqKCUt6uK2NaJTvy/htOr3XQ==;5:6S/SkWQTgWETxo7IjIjm++2LwU+hCG63jqXo/scZOHgMpAcRewYI1KD1rosvuHOE314YJ4axpVGdAlc0i5n0YYp4QyVSWsGU8nERmnteL98dfwrXinVMfLbxYXMPtJy8B4WnBte8lVoLEcFc8ot2nEx6pjiXeHODH83vOJ+NjsU=;7:4r4SubmO0XRI5e5B11oKrM8Cvw8EelM5szhDktas1lzh5tPcPgLCB8YIMNxw6/NPkINP98CUAR2F/JrxXWrix2DLRIaXDHe8Bsz6zFLbQqYH/NnBXB8sSoyuUQwWS7EWgKhQI+abd4n1sZ69hOhNAHEB6Nun2KpE/uGQkCYCtmrqVEAlcLGJDkO329mXsIqkfiJiZU3oeqmfGESVBjEBicxNhAVhF0tqx9OdKwP8czqm/Tf2y6IClTUizS382qJa SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB2021;20:zHqNlWefDAuv8x17BLMfcdKViowym5gbqslblDcWKFHiC86kll2nOsg9ih66c2SDpXD0fCKs30XeVwoTtddh5tqo6tzIuFPhPYJ8fVK4Tvds+qZ//mPOxZI+v6WAwrwSMlQOKkmO+2Ft2kWvY8y0s+meBnuRBhU9s+Nr97nENnk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2018 15:29:58.7921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ff7aa21d-12bf-4392-1dd7-08d60c31f3b4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB2021 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 Currently, we take fc->lock there only to check for fc->connected. But this flag is changed only on connection abort, which is very rare operation. Good thing looks to make fuse_request_send_background() faster, while fuse_abort_conn() slowler. So, we make fuse_request_send_background() lockless and mark (fc->connected == 1) region as RCU-protected. Abort function just uses synchronize_sched() to wait till all pending background requests is being queued, and then makes ordinary abort. Note, that synchronize_sched() is used instead of synchronize_rcu(), since we want to check for fc->connected without rcu_dereference() in fuse_request_send_background() (i.e., not to add memory barriers to this hot path). Also, note fuse_conn::aborting field is introduced. It's aimed to synchronize two sequential aborts executing in parallel: we do not want the secondly called abort finishes before the first one is done, after it sees fc->connected has already became 0. Our storage test shows performance increase on parallel read and write with the patchset (7 test runs, 300 seconds of execution of each, aio): ./io_iops --read --write --iops -u 48g -s 4k -p 24 -n 24 --aio -q 128 -t 300 -f /mnt/vstorage/file Before (iops): 25721.58203 (worst) 26179.43359 26092.58594 25789.96484 26238.63477 (best) 25985.88867 25987.66406 After (iops): 26852.27539 27547.60742 26322.29688 27643.33398 (best) 26753.10547 26157.91016 (worst) 26694.63477 All *after* runs are better than any *before* run, except of one. The best *after* run is 5% better than the best *before* run. The worst *after* run is 1.7% better then the worst *before* run. Signed-off-by: Kirill Tkhai Signed-off-by: Kirill Tkhai Signed-off-by: Miklos Szeredi --- fs/fuse/dev.c | 17 ++++++++++++----- fs/fuse/fuse_i.h | 3 +++ fs/fuse/inode.c | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 9690e7c79df7..064a65ca7283 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -575,8 +575,6 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args) } /* - * Called under fc->lock - * * fc->connected must have been checked previously */ void fuse_request_send_background_nocheck(struct fuse_conn *fc, @@ -604,12 +602,12 @@ void fuse_request_send_background_nocheck(struct fuse_conn *fc, void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req) { BUG_ON(!req->end); - spin_lock(&fc->lock); + rcu_read_lock_sched(); if (fc->connected) { fuse_request_send_background_nocheck(fc, req); - spin_unlock(&fc->lock); + rcu_read_unlock_sched(); } else { - spin_unlock(&fc->lock); + rcu_read_unlock_sched(); req->out.h.error = -ENOTCONN; req->end(fc, req); fuse_put_request(fc, req); @@ -2107,6 +2105,13 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) LIST_HEAD(to_end); fc->connected = 0; + fc->aborting = true; + spin_unlock(&fc->lock); + + /* Propagate fc->connected */ + synchronize_sched(); + + spin_lock(&fc->lock); fc->aborted = is_abort; fuse_set_initialized(fc); list_for_each_entry(fud, &fc->devices, entry) { @@ -2145,12 +2150,14 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) spin_unlock(&fiq->waitq.lock); kill_fasync(&fiq->fasync, SIGIO, POLL_IN); end_polls(fc); + fc->aborting = false; wake_up_all(&fc->blocked_waitq); spin_unlock(&fc->lock); end_requests(fc, &to_end); } else { spin_unlock(&fc->lock); + wait_event(fc->blocked_waitq, !fc->aborting); } } EXPORT_SYMBOL_GPL(fuse_abort_conn); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index b2c6a1cd1e2c..b9a991b42c88 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -523,6 +523,9 @@ struct fuse_conn { abort and device release */ unsigned connected; + /** Connection is now aborting */ + bool aborting; + /** Connection aborted via sysfs */ bool aborted; diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index a4285ec7c248..9612eb4bc609 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -624,6 +624,7 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns) fc->blocked = 0; fc->initialized = 0; fc->connected = 1; + fc->aborting = false; fc->attr_version = 1; get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); fc->pid_ns = get_pid_ns(task_active_pid_ns(current));