All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Arendt <admin-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
To: Ryusuke Konishi <ryusuke-sG5X7nlA6pw@public.gmane.org>
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: cleaner: run one cleaning pass based on minimum free space
Date: Wed, 17 Mar 2010 20:04:35 +0100	[thread overview]
Message-ID: <4BA127C3.9060008@prnet.org> (raw)
In-Reply-To: <20100318.031108.204325310.ryusuke-sG5X7nlA6pw@public.gmane.org>

Hi,

I have changed cleanerd.c to use cleanerd->c_running instead of sleeping.

Here the changed function for review. I will post a new complete patch
after receiving your comments.

static int nilfs_cleanerd_clean_loop(struct nilfs_cleanerd *cleanerd)
{
    struct nilfs_sustat sustat;
    __u64 prev_nongc_ctime = 0, prottime = 0, oldest = 0;
    __u64 segnums[NILFS_CLDCONFIG_NSEGMENTS_PER_CLEAN_MAX];
    struct timespec timeout;
    sigset_t sigset;
    int ns, ret;

    sigemptyset(&sigset);
    if (sigprocmask(SIG_SETMASK, &sigset, NULL) < 0) {
        syslog(LOG_ERR, "cannot set signal mask: %m");
        return -1;
    }
    sigaddset(&sigset, SIGHUP);

    if (set_sigterm_handler() < 0) {
        syslog(LOG_ERR, "cannot set SIGTERM signal handler: %m");
        return -1;
    }
    if (set_sighup_handler() < 0) {
        syslog(LOG_ERR, "cannot set SIGHUP signal handler: %m");
        return -1;
    }

    nilfs_cleanerd_reload_config = 0;

    ret = nilfs_cleanerd_init_interval(cleanerd);
    if (ret < 0)
        return -1;

    cleanerd->c_ncleansegs = cleanerd->c_config.cf_nsegments_per_clean;

    if (cleanerd->c_config.cf_min_clean_segments > 0) {
        syslog(LOG_INFO, "cleaner paused");
        cleanerd->c_running = 0;
        timeout.tv_sec = cleanerd->c_config.cf_clean_check_interval;
        timeout.tv_nsec = 0;
    }
    else
      cleanerd->c_running = 1;

    while (1) {
        if (sigprocmask(SIG_BLOCK, &sigset, NULL) < 0) {
            syslog(LOG_ERR, "cannot set signal mask: %m");
            return -1;
        }

        if (nilfs_cleanerd_reload_config) {
            if (nilfs_cleanerd_reconfig(cleanerd)) {
                syslog(LOG_ERR, "cannot configure: %m");
                return -1;
            }
            nilfs_cleanerd_reload_config = 0;
            syslog(LOG_INFO, "configuration file reloaded");
        }

        if (nilfs_get_sustat(cleanerd->c_nilfs, &sustat) < 0) {
            syslog(LOG_ERR, "cannot get segment usage stat: %m");
            return -1;
        }

        if (cleanerd->c_config.cf_min_clean_segments > 0) {
            if (cleanerd->c_running) {
                if (sustat.ss_ncleansegs >
cleanerd->c_config.cf_max_clean_segments) {
                    syslog(LOG_INFO, "cleaner paused");
                    cleanerd->c_running = 0;
                    timeout.tv_sec =
cleanerd->c_config.cf_clean_check_interval;
                    timeout.tv_nsec = 0;
                    goto sleep;
                }
            }
            else {
                if (sustat.ss_ncleansegs <
cleanerd->c_config.cf_min_clean_segments) {
                    syslog(LOG_INFO, "cleaner resumed");
                    cleanerd->c_running = 1;
                }
                else
                    goto sleep;
            }
        }

        if (sustat.ss_nongc_ctime != prev_nongc_ctime) {
            cleanerd->c_running = 1;
            prev_nongc_ctime = sustat.ss_nongc_ctime;
        }

        if (!cleanerd->c_running)
            goto sleep;

        syslog(LOG_DEBUG, "ncleansegs = %llu",
               (unsigned long long)sustat.ss_ncleansegs);

        ns = nilfs_cleanerd_select_segments(
            cleanerd, &sustat, segnums, &prottime, &oldest);
        if (ns < 0) {
            syslog(LOG_ERR, "cannot select segments: %m");
            return -1;
        }
        syslog(LOG_DEBUG, "%d segment%s selected to be cleaned",
               ns, (ns <= 1) ? "" : "s");
        if (ns > 0) {
            ret = nilfs_cleanerd_clean_segments(
                cleanerd, &sustat, segnums, ns, prottime);
            if (ret < 0)
                return -1;
        }

        ret = nilfs_cleanerd_recalc_interval(
            cleanerd, ns, prottime, oldest, &timeout);
        if (ret < 0)
            return -1;
        else if (ret > 0)
            continue;
 sleep:
        if (sigprocmask(SIG_UNBLOCK, &sigset, NULL) < 0) {
            syslog(LOG_ERR, "cannot set signal mask: %m");
            return -1;
        }

        ret = nilfs_cleanerd_sleep(cleanerd, &timeout);
        if (ret < 0)
            return -1;
    }
}

Thanks in advance
Bye,
David Arendt



On 03/17/10 19:11, Ryusuke Konishi wrote:
> Hi,
> On Mon, 15 Mar 2010 22:24:28 +0100, David Arendt wrote:
>   
>> Hi,
>>
>> Well I didn't know that a few days can pass as fast :-)
>>
>> I have attached the patch to this mail.
>>
>> Until now the patch has only been shortly tested on a loop device, so it
>> might contain bugs and destroy your data.
>>     
> Thank you for posting the patch!
>
> The patch looks rougly ok to me.
> I'll comment on it later.
>
> At first glance, I felt it would be nice if cleanerd->c_running is
> nicely used instead of adding a local variable "sleeping".
>
> Thanks,
> Ryusuke Konishi
>  
>   
>> If you decide to apply it, please change the default values to the ones
>> you find the most appropriate.
>>
>> Thanks in advance,
>> Bye,
>> David Arendt
>>
>> On 03/15/10 16:58, Ryusuke Konishi wrote:
>>     
>>> Hi,
>>> On Mon, 15 Mar 2010 00:03:45 +0100, David Arendt wrote:
>>>   
>>>       
>>>> Hi,
>>>>
>>>> I am posting this again to the correct mailing list as I cc'ed it to the
>>>> old inactive one.
>>>>
>>>> Maybe I am understanding something wrong, but if I would use the count
>>>> of reclaimed segments, how could I determine if one cleaning pass has
>>>> finished as I don't know in advance how many segments could be reclaimed ?
>>>>     
>>>>         
>>> For example, how about this?
>>>
>>>  nmax = (number of segments) - (number of clean segments)
>>>  nblk = (max_clean_segments - (number of clean segments)) *
>>>             (number of blocks per segment)
>>>
>>>  * If (number of clean segments) < min_clean_segments, then start reclamation
>>>  * Try to reclaim nmax segments (at a maximum).
>>>  * When the cleaner found and freed nblk blocks during the
>>>    reclamation, then end one cleaning pass.
>>>
>>>   
>>>       
>>>> Another approach would be not basing cleaning on a whole cleaning pass
>>>> but instead creating these addtional configfile options:
>>>>
>>>> # start cleaning if less than 100 free segments
>>>> min_clean_segments 100
>>>>
>>>> # stop cleaning if more than 200 free segments
>>>> max_clean_segments 200
>>>>
>>>> # check free space once an hour
>>>> segment_check_interval 3600
>>>>
>>>> Basically in this example if less than 800mb are free cleaner is run
>>>> until 1600mb are free. If min_clean_segments is 0, the cleaner would do
>>>> normal operation.
>>>>     
>>>>         
>>> The first two parameters look Ok.
>>> (I've already referred to these in the above example.)
>>>
>>> We may well be able to make segment_check_interval more frequent.
>>> or do you have something in mind? 
>>>
>>> Do you mean interval of cleaning passes ?
>>>
>>>   
>>>       
>>>> For this solution only changes in configfile loading and
>>>> nilfs_cleanerd_clean_loop would be necessary which would lower the risk
>>>> of introducing new bugs.
>>>>
>>>> If this solution is ok for you, I will implement it this way and send
>>>> you the patch in a few days. Also tell me if the names I have choosen
>>>> for the options are ok for you or if you would prefer other ones.
>>>>     
>>>>         
>>> The option names look fine to me.
>>> Or should we use percentage for them?
>>> (number of segments is device dependent)
>>>
>>> Is there anything else that isn't clear?
>>>
>>>   
>>>       
>>>> Thanks in advance
>>>> Bye,
>>>> David Arendt
>>>>     
>>>>         
>>> Thanks,
>>> Ryusuke Konishi 
>>>
>>>   
>>>       
>>>> On 03/14/10 15:28, Ryusuke Konishi wrote:
>>>>     
>>>>         
>>>>> Hi,
>>>>> On Sun, 14 Mar 2010 14:00:19 +0100, admin-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org wrote:
>>>>>   
>>>>>       
>>>>>           
>>>>>> Hi,
>>>>>>
>>>>>> I will try to implement this myself then. Concerning the
>>>>>> nilfs_cleanerd_select segments function I was unclear in my post. In
>>>>>> fact I did not mean the return value but the first element from the
>>>>>> segnums array.
>>>>>>     
>>>>>>         
>>>>>>             
>>>>> Ok. So you thought of determining termination of one cleaning pass by
>>>>> the segment number stored preliminarily.
>>>>>
>>>>> Why not just use count of processed (i.e. reclaimed) segments?
>>>>>
>>>>> Note that it's not guranteed that segments are selected in the order
>>>>> of segment number though this premise looks almost right.
>>>>>
>>>>> It depends on the behavior of segment allocator and the current
>>>>> "Select-oldest" algorithm used behind
>>>>> nilfs_cleanerd_select_segments().  Nilfs log writer occasionally
>>>>> behaves differently and disturbs this order.
>>>>>
>>>>> I think you can ignore the exceptional behavior of the segment
>>>>> allocator, and rotate target segments with skipping free or mostly
>>>>> in-use ones.  In that case, nilfs_cleanerd_select_segments() should be
>>>>> modified to select segments in the order of segment number.
>>>>>
>>>>> Cheers,
>>>>> Ryusuke Konishi
>>>>>
>>>>>   
>>>>>       
>>>>>           
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
>>>> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>>>     
>>>>         
>>     

--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2010-03-17 19:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-14 13:00 cleaner: run one cleaning pass based on minimum free space admin-/LHdS3kC8BfYtjvyW6yDsg
     [not found] ` <hSSjxhQnnRB5.kxy725KN-GG6YVgmNXeLOQU1ULcgDhA@public.gmane.org>
2010-03-14 14:28   ` Ryusuke Konishi
     [not found]     ` <20100314.232838.05854811.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-14 23:03       ` David Arendt
     [not found]         ` <4B9D6B51.5010202-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-15 15:58           ` Ryusuke Konishi
     [not found]             ` <20100316.005815.140047502.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-15 17:09               ` David Arendt
     [not found]                 ` <4B9E69D2.4030803-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-17 17:26                   ` Ryusuke Konishi
2010-03-15 21:24               ` David Arendt
     [not found]                 ` <4B9EA58C.1080402-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-17 18:11                   ` Ryusuke Konishi
     [not found]                     ` <20100318.031108.204325310.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-17 19:04                       ` David Arendt [this message]
2010-03-24  5:35                       ` David Arendt
     [not found]                         ` <4BA9A484.20809-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-27 17:48                           ` Ryusuke Konishi
     [not found]                             ` <20100328.024853.37589748.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-27 18:32                               ` David Arendt
2010-03-27 20:00                               ` David Arendt
     [not found]                                 ` <4BAE63F4.1040404-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-28  1:55                                   ` Ryusuke Konishi
     [not found]                                     ` <20100328.105542.258871713.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-28 12:17                                       ` David Arendt
     [not found]                                         ` <4BAF48BC.8060505-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-28 15:26                                           ` Ryusuke Konishi
     [not found]                                             ` <20100329.002619.67908494.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-28 21:52                                               ` David Arendt
     [not found]                                                 ` <4BAFCFB4.5050401-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-29  3:59                                                   ` Ryusuke Konishi
     [not found]                                                     ` <20100329.125908.56566467.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-29  4:35                                                       ` David Arendt
     [not found]                                                         ` <4BB02E0F.90001-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-29  7:39                                                           ` Ryusuke Konishi
     [not found]                                                             ` <20100329.163902.263795283.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-05  3:02                                                               ` Ryusuke Konishi
     [not found]                                                                 ` <20100405.120226.98047309.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-05  7:50                                                                   ` David Arendt
     [not found]                                                                     ` <4BB99633.1030701-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-04-05 11:34                                                                       ` Ryusuke Konishi
     [not found]                                                                         ` <20100405.203450.56374807.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-05 13:35                                                                           ` David Arendt
     [not found]                                                                             ` <4BB9E726.8020407-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-04-06 16:06                                                                               ` Ryusuke Konishi
     [not found]                                                                                 ` <20100407.010609.179957904.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-06 17:41                                                                                   ` David Arendt
     [not found]                                                                                     ` <4BBB724D.6040207-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-04-06 18:04                                                                                       ` Ryusuke Konishi
     [not found]                                                                                         ` <20100407.030446.52169610.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-07 10:39                                                                                           ` admin-/LHdS3kC8BfYtjvyW6yDsg
     [not found]                                                                                             ` <0f70f9c8a2d58971d6d6af5104c73066.squirrel-YfwCgBv0H3oBXFe83j6qeQ@public.gmane.org>
2010-04-08  5:12                                                                                               ` Ryusuke Konishi
     [not found]                                                                                                 ` <20100408.141218.179775797.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-04-08 10:54                                                                                                   ` admin-/LHdS3kC8BfYtjvyW6yDsg
2010-04-06 16:12                                                                           ` Ryusuke Konishi
     [not found]                                                                     ` <y2gee5afd761004050430gd8c60707s9505a0d680345fe6@mail.gmail.com>
     [not found]                                                                       ` <y2gee5afd761004050430gd8c60707s9505a0d680345fe6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-05 12:35                                                                         ` Jan de Kruyf
     [not found]                                                                           ` <l2wee5afd761004050535l6214e37dja6f20737865dd856-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-04-06 17:56                                                                             ` Ryusuke Konishi
2010-03-16 11:17               ` admin-/LHdS3kC8BfYtjvyW6yDsg
     [not found]                 ` <08886d8962faeee94a5ab900a2a78ad2.squirrel-YfwCgBv0H3oBXFe83j6qeQ@public.gmane.org>
2010-03-17 18:32                   ` Ryusuke Konishi
     [not found]                     ` <20100318.033237.203922438.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-17 19:12                       ` David Arendt
  -- strict thread matches above, loose matches on Subject: below --
2010-03-13 20:49 David Arendt
     [not found] ` <4B9BFA67.1010501-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-14  5:26   ` Ryusuke Konishi
     [not found]     ` <20100314.142634.172547823.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-03-14  8:47       ` David Arendt
     [not found]         ` <4B9CA2BB.6000907-/LHdS3kC8BfYtjvyW6yDsg@public.gmane.org>
2010-03-14 11:59           ` Ryusuke Konishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BA127C3.9060008@prnet.org \
    --to=admin-/lhds3kc8bfytjvyw6ydsg@public.gmane.org \
    --cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=ryusuke-sG5X7nlA6pw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.