From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Teigland Date: Tue, 25 Aug 2009 10:35:03 -0500 Subject: [Cluster-devel] Re: [RFC]Drop unused plock resource when no other plock request comes In-Reply-To: References: <20090824143128.GA25798@redhat.com> Message-ID: <20090825153503.GA24475@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Tue, Aug 25, 2009 at 11:10:03AM +0800, Jiaju Zhang wrote: > On Mon, Aug 24, 2009 at 10:31 PM, David Teigland wrote: > > > > > You're correct; yes the daemon could easily be changed to drop resources > > when > > there's no locking activity. We'd just set a poll timeout when > > plock_resources is non-empty and call drop_resources() if it times out. > > > > (If you simply want to work around this, you can write a little program to > > lock a file on the fs to trigger the drop.) > > > > Dave > > > Many thanks for your guidance :-) > So I write a patch to try to fix this. Review and comments are welcome. Thanks, that looks like it would do the job, but the code is a little complicated. Here's a simpler patch, I've not tried it so it may not work :) Dave diff --git a/group/dlm_controld/dlm_daemon.h b/group/dlm_controld/dlm_daemon.h index df2e148..18479d7 100644 --- a/group/dlm_controld/dlm_daemon.h +++ b/group/dlm_controld/dlm_daemon.h @@ -73,6 +73,7 @@ extern int poll_fencing; extern int poll_quorum; extern int poll_fs; extern int poll_ignore_plock; +extern int poll_drop_plock; extern int plock_fd; extern int plock_ci; extern struct list_head lockspaces; @@ -296,6 +297,7 @@ void process_netlink(int ci); int setup_plocks(void); void close_plocks(void); void process_plocks(int ci); +void drop_resources_all(void); int limit_plocks(void); void receive_plock(struct lockspace *ls, struct dlm_header *hd, int len); void receive_own(struct lockspace *ls, struct dlm_header *hd, int len); diff --git a/group/dlm_controld/main.c b/group/dlm_controld/main.c index 93b40f8..75ee55d 100644 --- a/group/dlm_controld/main.c +++ b/group/dlm_controld/main.c @@ -1011,6 +1011,13 @@ static void loop(void) } poll_timeout = 1000; } + + if (poll_drop_plock) { + drop_resources_all(); + if (poll_drop_plock) + poll_timeout = 1000; + } + query_unlock(); } out: @@ -1310,6 +1317,7 @@ int poll_fencing; int poll_quorum; int poll_fs; int poll_ignore_plock; +int poll_drop_plock; int plock_fd; int plock_ci; struct list_head lockspaces; diff --git a/group/dlm_controld/plock.c b/group/dlm_controld/plock.c index 3d4431e..197b15c 100644 --- a/group/dlm_controld/plock.c +++ b/group/dlm_controld/plock.c @@ -1351,8 +1351,20 @@ static int drop_resources(struct lockspace *ls) struct timeval now; int count = 0; + if (!cfgd_plock_ownership) + return 0; + + if (list_empty(&ls->plock_resources)) + return 0; + gettimeofday(&now, NULL); + if (time_diff_ms(&ls->drop_resources_last, &now) < + cfgd_drop_resources_time) + return 1; + + ls->drop_resources_last = now; + /* try to drop the oldest, unused resources */ list_for_each_entry_reverse(r, &ls->plock_resources, list) { @@ -1376,7 +1388,21 @@ static int drop_resources(struct lockspace *ls) } } - return 0; + return 1; +} + +void drop_resources_all(void) +{ + struct lockspace *ls; + int rv = 0; + + poll_drop_plock = 0; + + list_for_each_entry(ls, &lockspaces, list) { + rv = drop_resources(ls); + if (rv) + poll_drop_plock = 1; + } } int limit_plocks(void) @@ -1495,13 +1521,8 @@ void process_plocks(int ci) save_pending_plock(ls, r, &info); } - if (cfgd_plock_ownership && - time_diff_ms(&ls->drop_resources_last, &now) >= - cfgd_drop_resources_time) { - ls->drop_resources_last = now; - drop_resources(ls); - } - + if (cfgd_plock_ownership && !list_empty(&ls->plock_resources)) + poll_drop_plock = 1; return; fail: