2023-01-12 00:09:18

by Dai Ngo

[permalink] [raw]
Subject: [PATCH 1/1] NFSD: replace delayed_work with work_struct for nfsd_client_shrinker

Since nfsd4_state_shrinker_count always calls mod_delayed_work with
0 delay, we can replace delayed_work with work_struct to save some
space and overhead.

Also add the call to cancel_work after unregister the shrinker
in nfs4_state_shutdown_net.

Signed-off-by: Dai Ngo <[email protected]>
---
fs/nfsd/netns.h | 2 +-
fs/nfsd/nfs4state.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
index 8c854ba3285b..51a4b7885cae 100644
--- a/fs/nfsd/netns.h
+++ b/fs/nfsd/netns.h
@@ -195,7 +195,7 @@ struct nfsd_net {

atomic_t nfsd_courtesy_clients;
struct shrinker nfsd_client_shrinker;
- struct delayed_work nfsd_shrinker_work;
+ struct work_struct nfsd_shrinker_work;
};

/* Simple check to find out if a given net was properly initialized */
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a7cfefd7c205..21bee33bc6dc 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4411,7 +4411,7 @@ nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc)
if (!count)
count = atomic_long_read(&num_delegations);
if (count)
- mod_delayed_work(laundry_wq, &nn->nfsd_shrinker_work, 0);
+ queue_work(laundry_wq, &nn->nfsd_shrinker_work);
return (unsigned long)count;
}

@@ -6233,8 +6233,7 @@ deleg_reaper(struct nfsd_net *nn)
static void
nfsd4_state_shrinker_worker(struct work_struct *work)
{
- struct delayed_work *dwork = to_delayed_work(work);
- struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
+ struct nfsd_net *nn = container_of(work, struct nfsd_net,
nfsd_shrinker_work);

courtesy_client_reaper(nn);
@@ -8064,7 +8063,7 @@ static int nfs4_state_create_net(struct net *net)
INIT_LIST_HEAD(&nn->blocked_locks_lru);

INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main);
- INIT_DELAYED_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
+ INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
get_net(net);

nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan;
@@ -8171,6 +8170,7 @@ nfs4_state_shutdown_net(struct net *net)
struct nfsd_net *nn = net_generic(net, nfsd_net_id);

unregister_shrinker(&nn->nfsd_client_shrinker);
+ cancel_work(&nn->nfsd_shrinker_work);
cancel_delayed_work_sync(&nn->laundromat_work);
locks_end_grace(&nn->nfsd4_manager);

--
2.9.5


2023-01-12 02:40:40

by Chuck Lever III

[permalink] [raw]
Subject: Re: [PATCH 1/1] NFSD: replace delayed_work with work_struct for nfsd_client_shrinker



> On Jan 11, 2023, at 7:06 PM, Dai Ngo <[email protected]> wrote:
>
> Since nfsd4_state_shrinker_count always calls mod_delayed_work with
> 0 delay, we can replace delayed_work with work_struct to save some
> space and overhead.
>
> Also add the call to cancel_work after unregister the shrinker
> in nfs4_state_shutdown_net.
>
> Signed-off-by: Dai Ngo <[email protected]>

The missing cancel_work seems important enough to apply to for-rc
instead of waiting for the next merge window. Thanks for the patch!


> ---
> fs/nfsd/netns.h | 2 +-
> fs/nfsd/nfs4state.c | 8 ++++----
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
> index 8c854ba3285b..51a4b7885cae 100644
> --- a/fs/nfsd/netns.h
> +++ b/fs/nfsd/netns.h
> @@ -195,7 +195,7 @@ struct nfsd_net {
>
> atomic_t nfsd_courtesy_clients;
> struct shrinker nfsd_client_shrinker;
> - struct delayed_work nfsd_shrinker_work;
> + struct work_struct nfsd_shrinker_work;
> };
>
> /* Simple check to find out if a given net was properly initialized */
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index a7cfefd7c205..21bee33bc6dc 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -4411,7 +4411,7 @@ nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc)
> if (!count)
> count = atomic_long_read(&num_delegations);
> if (count)
> - mod_delayed_work(laundry_wq, &nn->nfsd_shrinker_work, 0);
> + queue_work(laundry_wq, &nn->nfsd_shrinker_work);
> return (unsigned long)count;
> }
>
> @@ -6233,8 +6233,7 @@ deleg_reaper(struct nfsd_net *nn)
> static void
> nfsd4_state_shrinker_worker(struct work_struct *work)
> {
> - struct delayed_work *dwork = to_delayed_work(work);
> - struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
> + struct nfsd_net *nn = container_of(work, struct nfsd_net,
> nfsd_shrinker_work);
>
> courtesy_client_reaper(nn);
> @@ -8064,7 +8063,7 @@ static int nfs4_state_create_net(struct net *net)
> INIT_LIST_HEAD(&nn->blocked_locks_lru);
>
> INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main);
> - INIT_DELAYED_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
> + INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
> get_net(net);
>
> nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan;
> @@ -8171,6 +8170,7 @@ nfs4_state_shutdown_net(struct net *net)
> struct nfsd_net *nn = net_generic(net, nfsd_net_id);
>
> unregister_shrinker(&nn->nfsd_client_shrinker);
> + cancel_work(&nn->nfsd_shrinker_work);
> cancel_delayed_work_sync(&nn->laundromat_work);
> locks_end_grace(&nn->nfsd4_manager);
>
> --
> 2.9.5
>

--
Chuck Lever



2023-01-12 10:32:09

by Jeff Layton

[permalink] [raw]
Subject: Re: [PATCH 1/1] NFSD: replace delayed_work with work_struct for nfsd_client_shrinker

On Wed, 2023-01-11 at 16:06 -0800, Dai Ngo wrote:
> Since nfsd4_state_shrinker_count always calls mod_delayed_work with
> 0 delay, we can replace delayed_work with work_struct to save some
> space and overhead.
>
> Also add the call to cancel_work after unregister the shrinker
> in nfs4_state_shutdown_net.
>
> Signed-off-by: Dai Ngo <[email protected]>
> ---
> fs/nfsd/netns.h | 2 +-
> fs/nfsd/nfs4state.c | 8 ++++----
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
> index 8c854ba3285b..51a4b7885cae 100644
> --- a/fs/nfsd/netns.h
> +++ b/fs/nfsd/netns.h
> @@ -195,7 +195,7 @@ struct nfsd_net {
>
> atomic_t nfsd_courtesy_clients;
> struct shrinker nfsd_client_shrinker;
> - struct delayed_work nfsd_shrinker_work;
> + struct work_struct nfsd_shrinker_work;
> };
>
> /* Simple check to find out if a given net was properly initialized */
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index a7cfefd7c205..21bee33bc6dc 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -4411,7 +4411,7 @@ nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc)
> if (!count)
> count = atomic_long_read(&num_delegations);
> if (count)
> - mod_delayed_work(laundry_wq, &nn->nfsd_shrinker_work, 0);
> + queue_work(laundry_wq, &nn->nfsd_shrinker_work);
> return (unsigned long)count;
> }
>
> @@ -6233,8 +6233,7 @@ deleg_reaper(struct nfsd_net *nn)
> static void
> nfsd4_state_shrinker_worker(struct work_struct *work)
> {
> - struct delayed_work *dwork = to_delayed_work(work);
> - struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
> + struct nfsd_net *nn = container_of(work, struct nfsd_net,
> nfsd_shrinker_work);
>
> courtesy_client_reaper(nn);
> @@ -8064,7 +8063,7 @@ static int nfs4_state_create_net(struct net *net)
> INIT_LIST_HEAD(&nn->blocked_locks_lru);
>
> INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main);
> - INIT_DELAYED_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
> + INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker);
> get_net(net);
>
> nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan;
> @@ -8171,6 +8170,7 @@ nfs4_state_shutdown_net(struct net *net)
> struct nfsd_net *nn = net_generic(net, nfsd_net_id);
>
> unregister_shrinker(&nn->nfsd_client_shrinker);
> + cancel_work(&nn->nfsd_shrinker_work);
> cancel_delayed_work_sync(&nn->laundromat_work);
> locks_end_grace(&nn->nfsd4_manager);
>

Reviewed-by: Jeff Layton <[email protected]>