From patchwork Thu Aug 11 06:02:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 12941168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB482C19F2D for ; Thu, 11 Aug 2022 06:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbiHKGCV (ORCPT ); Thu, 11 Aug 2022 02:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233681AbiHKGCT (ORCPT ); Thu, 11 Aug 2022 02:02:19 -0400 Received: from mail-vs1-xe29.google.com (mail-vs1-xe29.google.com [IPv6:2607:f8b0:4864:20::e29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0993E7392F for ; Wed, 10 Aug 2022 23:02:16 -0700 (PDT) Received: by mail-vs1-xe29.google.com with SMTP id b124so17290395vsc.9 for ; Wed, 10 Aug 2022 23:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc; bh=GkGNUgbYRqRZabnfX0pk4rZzwlULD0+LXWt8GFOT9bw=; b=ITZDf7c1uSXKGB4qna1Kj2zTsgm37lV/vZ7rWSrecGfrro2rgHKb85JWdygadA8//1 6oSWv7Dn99RaBj+YLflAYgiLEG+uymEC0Bx951A4O9rGLBzNvJxfSD4PxVTi6tRA89Og 1ASMJj4PXCs3Em9Iyefv9nC2qSr3InUjh5XoJsSks363cKuiIEoqyDnZVksO0r4gxqAm VJYVcLhsrEueiHXomfnIopfdr8Dv/jrc/1ENFn2bCg3aWx9+Eo4c1Uq4VgIxuBCoZesJ BHVAmEqq9hhS1nQ665tnOUXM6XtWK0h5PKm8kn+1lGuRJoQynS5e1HSknn5SoOtsCPej OIfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=GkGNUgbYRqRZabnfX0pk4rZzwlULD0+LXWt8GFOT9bw=; b=YiPwa5UWgSpj6j4/8xI37hLIRptmaqM0pphR5L375W65NN8rJOURG1BXPi8lvgybKB /AD0ase7hVtQFEaBpfQxSDX46qEosIHdY6wNTDcsUDZv3h7PHxCJ7uBBtD2UQW2qznhW dFQrRej8RG1VVknvGOgrE6Ag4F+VCkSFjvdyuT8OWWYa2+EpjlKihxJ858K00c81fAmB 49jXacYVQF2Fuz02Mu+CLANpY5Gta5H90dHtjx1jwp5pMSoQf3uQhfmFODZwHMBz4Vp9 wh8F0bc/81uM7sHzREYa3b0W80msX2XJOC8kcButRlIa/QicNqKjncyzeWwiuZWWI1pm zDhA== X-Gm-Message-State: ACgBeo22tvA54m7/qXb3ulUKxGB5GD+hW1mk4Ijm/xr39vJvLdeX47F4 eL7Q5nd/vljZHV+Wlum8QqgrIMWevYxAGbEyDFFa2SK0ut2Z9w== X-Google-Smtp-Source: AA6agR792SaEyMyBu2O6lN05VfglAMLwPyAhmxrMWrECU1OTAAXUIW7monLNNGcihucBhYWuOcwcnVmuOdkXC1fn7CI= X-Received: by 2002:a67:fc06:0:b0:388:955d:2535 with SMTP id o6-20020a67fc06000000b00388955d2535mr9809797vsq.6.1660197734860; Wed, 10 Aug 2022 23:02:14 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Thu, 11 Aug 2022 01:02:03 -0500 Message-ID: Subject: [PATCH][SMB3 client] allow deferred close timeout to be configurable To: CIFS Cc: rohiths msft , Shyam Prasad N Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Deferred close can be a very useful feature for very safely allowing caching data for read, and for minimizing the number of reopens needed for a file that is repeatedly opened and close but there are workloads where its default (1 second, similar to actimeo/acregmax) is too small. Allow the user to configure the amount of time we can defer sending the final smb3 close when we have a handle lease on the file (rather than forcing it to depend on 1 second or actimeo which is often unrelated). Adds new mount parameter "closetime=" which is the maximum number of seconds we can wait before sending an SMB3 close when we have a handle lease for it. Default value is unchanged at 1 second. From 464efd4fec1eed5d34a0953c23dea951b9f528b1 Mon Sep 17 00:00:00 2001 From: Steve French Date: Thu, 11 Aug 2022 00:53:00 -0500 Subject: [PATCH] smb3: allow deferred close timeout to be configurable Deferred close can be a very useful feature for allowing caching data for read, and for minimizing the number of reopens needed for a file that is repeatedly opened and close but there are workloads where its default (1 second, similar to actimeo/acregmax) is too small. Allow the user to configure the amount of time we can defer sending the final smb3 close when we have a handle lease on the file (rather than forcing it to depend on 1 second or actimeo which is often unrelated). Adds new mount parameter "closetime=" which is the maximum number of seconds we can wait before sending an SMB3 close when we have a handle lease for it. Default value is unchanged at 1 second. Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 2 ++ fs/cifs/connect.c | 2 ++ fs/cifs/file.c | 4 ++-- fs/cifs/fs_context.c | 9 +++++++++ fs/cifs/fs_context.h | 3 +++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 945fb083cea7..af6114e17fb5 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -693,6 +693,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) seq_printf(s, ",acdirmax=%lu", cifs_sb->ctx->acdirmax / HZ); seq_printf(s, ",acregmax=%lu", cifs_sb->ctx->acregmax / HZ); } + if (cifs_sb->ctx->closetimeo != cifs_sb->ctx->acregmax) + seq_printf(s, ",closetimeo=%lu", cifs_sb->ctx->closetimeo / HZ); if (tcon->ses->chan_max > 1) seq_printf(s, ",multichannel,max_channels=%zu", diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 7f205a9a2de4..9111c025bcb8 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2681,6 +2681,8 @@ compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data) return 0; if (old->ctx->acdirmax != new->ctx->acdirmax) return 0; + if (old->ctx->closetimeo != new->ctx->closetimeo) + return 0; return 1; } diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 42f2639a1a66..2c5eae7d31f4 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -964,12 +964,12 @@ int cifs_close(struct inode *inode, struct file *file) * So, Increase the ref count to avoid use-after-free. */ if (!mod_delayed_work(deferredclose_wq, - &cfile->deferred, cifs_sb->ctx->acregmax)) + &cfile->deferred, cifs_sb->ctx->closetimeo)) cifsFileInfo_get(cfile); } else { /* Deferred close for files */ queue_delayed_work(deferredclose_wq, - &cfile->deferred, cifs_sb->ctx->acregmax); + &cfile->deferred, cifs_sb->ctx->closetimeo); cfile->deferred_close_scheduled = true; spin_unlock(&cinode->deferred_lock); return 0; diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c index 8dc0d923ef6a..28a339c57beb 100644 --- a/fs/cifs/fs_context.c +++ b/fs/cifs/fs_context.c @@ -147,6 +147,7 @@ const struct fs_parameter_spec smb3_fs_parameters[] = { fsparam_u32("actimeo", Opt_actimeo), fsparam_u32("acdirmax", Opt_acdirmax), fsparam_u32("acregmax", Opt_acregmax), + fsparam_u32("closetimeo", Opt_closetimeo), fsparam_u32("echo_interval", Opt_echo_interval), fsparam_u32("max_credits", Opt_max_credits), fsparam_u32("handletimeout", Opt_handletimeout), @@ -1074,6 +1075,13 @@ static int smb3_fs_context_parse_param(struct fs_context *fc, } ctx->acdirmax = ctx->acregmax = HZ * result.uint_32; break; + case Opt_closetimeo: + ctx->closetimeo = HZ * result.uint_32; + if (ctx->closetimeo > CIFS_MAX_ACTIMEO) { + cifs_errorf(fc, "closetimeo too large\n"); + goto cifs_parse_mount_err; + } + break; case Opt_echo_interval: ctx->echo_interval = result.uint_32; break; @@ -1521,6 +1529,7 @@ int smb3_init_fs_context(struct fs_context *fc) ctx->acregmax = CIFS_DEF_ACTIMEO; ctx->acdirmax = CIFS_DEF_ACTIMEO; + ctx->closetimeo = CIFS_DEF_ACTIMEO; /* Most clients set timeout to 0, allows server to use its default */ ctx->handle_timeout = 0; /* See MS-SMB2 spec section 2.2.14.2.12 */ diff --git a/fs/cifs/fs_context.h b/fs/cifs/fs_context.h index 5f093cb7e9b9..927a5f2f9919 100644 --- a/fs/cifs/fs_context.h +++ b/fs/cifs/fs_context.h @@ -125,6 +125,7 @@ enum cifs_param { Opt_actimeo, Opt_acdirmax, Opt_acregmax, + Opt_closetimeo, Opt_echo_interval, Opt_max_credits, Opt_snapshot, @@ -247,6 +248,8 @@ struct smb3_fs_context { /* attribute cache timemout for files and directories in jiffies */ unsigned long acregmax; unsigned long acdirmax; + /* timeout for deferred close of files in jiffies */ + unsigned long closetimeo; struct smb_version_operations *ops; struct smb_version_values *vals; char *prepath; -- 2.34.1