mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: daijunbing <daijunbing@vivo.com>
To: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>, Theodore Ts'o <tytso@mit.edu>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-ext4@vger.kernel.org, opensource.kernel@vivo.com
Subject: Re: [PATCH v1 5/5] jbd2: Add TASK_FREEZABLE to kjournald2 thread
Date: Fri, 8 Aug 2025 10:12:53 +0800	[thread overview]
Message-ID: <2cf7ebe5-db81-4aca-9c70-65e712f69835@vivo.com> (raw)
In-Reply-To: <uj22sykbnhfsbk7abj3rdul46uko5vvhq425kdbtkzsw5l5kqa@ixs245eozsfe>



在 2025/7/30 18:52, Jan Kara 写道:
> On Wed 30-07-25 09:47:06, Dai Junbing wrote:
>> Set the TASK_FREEZABLE flag when the kjournald2 kernel thread sleeps
>> during journal commit operations. This prevents premature wakeups
>> during system suspend/resume cycles, avoiding unnecessary CPU wakeups
>> and power consumption.
>>
>> in this case, the original code:
>>
>> 	prepare_to_wait(&journal->j_wait_commit, &wait,
>>                 	 TASK_INTERRUPTIBLE);
>> 	if (journal->j_commit_sequence != journal->j_commit_request)
>>          	should_sleep = 0;
>>
>> 	transaction = journal->j_running_transaction;
>> 	if (transaction && time_after_eq(jiffies, transaction->t_expires))
>>          	should_sleep = 0;
>> 	......
>> 	......
>> 	if (should_sleep) {
>>          	write_unlock(&journal->j_state_lock);
>>          	schedule();
>>          	write_lock(&journal->j_state_lock);
>> 	}
>>
>> is functionally equivalent to the more concise:
>>
>> 	write_unlock(&journal->j_state_lock);
>> 	wait_event_freezable_exclusive(&journal->j_wait_commit,
>>          	journal->j_commit_sequence == journal->j_commit_request ||
>>          	(journal->j_running_transaction &&
>>           	time_after_eq(jiffies, transaction->t_expires)) ||
>>          	(journal->j_flags & JBD2_UNMOUNT));
>> 	write_lock(&journal->j_state_lock);
> 
> This would be actually wrong because you cannot safely do some of the
> dereferences without holding j_state_lock. Luckily you didn't modify the
> existing code in the patch, just the changelog is bogus so please fix it.

Thank you for pointing this out. I'll make the corresponding changelog 
updates.

> 
>> Signed-off-by: Dai Junbing <daijunbing@vivo.com>
>> ---
>>   fs/jbd2/journal.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
>> index d480b94117cd..9a1def9f730b 100644
>> --- a/fs/jbd2/journal.c
>> +++ b/fs/jbd2/journal.c
>> @@ -222,7 +222,7 @@ static int kjournald2(void *arg)
>>   		DEFINE_WAIT(wait);
>>   
>>   		prepare_to_wait(&journal->j_wait_commit, &wait,
>> -				TASK_INTERRUPTIBLE);
>> +				TASK_INTERRUPTIBLE | TASK_FREEZABLE);
> 
> So this looks fine but I have one question. There's code like:
> 
>          if (freezing(current)) {
>                  /*
>                   * The simpler the better. Flushing journal isn't a
>                   * good idea, because that depends on threads that may
>                   * be already stopped.
>                   */
>                  jbd2_debug(1, "Now suspending kjournald2\n");
>                  write_unlock(&journal->j_state_lock);
>                  try_to_freeze();
>                  write_lock(&journal->j_state_lock);
> 
> a few lines above. Is it still needed after your change? I guess that
> probably yes (e.g. when the freeze attempt happens while kjournald still
> performs some work then the later schedule in TASK_FREEZABLE state doesn't
> necessarily freeze the kthread). But getting a confirmation would be nice.

I agree with your perspective.
While cleaner implementations may exist,I haven't made changes due to 
uncertainty about the alternatives>
> 								Honza
> 
>>   		transaction = journal->j_running_transaction;
>>   		if (transaction == NULL ||
>>   		    time_before(jiffies, transaction->t_expires)) {
>> -- 
>> 2.25.1
>>


      reply	other threads:[~2025-08-08  2:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-30  1:47 [PATCH v1 0/5] PM: Reduce spurious wakeups Dai Junbing
2025-07-30  1:47 ` [PATCH v1 1/5] epoll: Make epoll_wait sleep freezable Dai Junbing
2025-07-30  1:47 ` [PATCH v1 2/5] select/poll: Make " Dai Junbing
2025-07-30 12:46   ` Jan Kara
2025-07-30  1:47 ` [PATCH v1 3/5] pipe: Add TASK_FREEZABLE to read and open sleeps Dai Junbing
2025-07-30  1:47 ` [PATCH v1 4/5] fuse: Add TASK_FREEZABLE to device read operations Dai Junbing
2025-07-30  1:47 ` [PATCH v1 5/5] jbd2: Add TASK_FREEZABLE to kjournald2 thread Dai Junbing
2025-07-30 10:52   ` Jan Kara
2025-08-08  2:12     ` daijunbing [this message]

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=2cf7ebe5-db81-4aca-9c70-65e712f69835@vivo.com \
    --to=daijunbing@vivo.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=opensource.kernel@vivo.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®