xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH] xen/balloon: use a kernel thread instead a workqueue
Date: Wed, 8 Sep 2021 17:11:36 +0200	[thread overview]
Message-ID: <9d1edc4e-b2b5-c620-17c6-31d238c2c417@suse.com> (raw)
In-Reply-To: <8b13525b-0075-f4c1-8900-1be151e85e3e@oracle.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 1588 bytes --]

On 08.09.21 16:47, Boris Ostrovsky wrote:
> 
> On 8/27/21 8:32 AM, Juergen Gross wrote:
>> +static bool balloon_thread_cond(enum bp_state state, long credit)
>> +{
>> +	if (state != BP_EAGAIN)
>> +		credit = 0;
>> +
>> +	return current_credit() != credit || kthread_should_stop();
>> +}
>> +
>> +/*
>> + * As this is a kthread it is guaranteed to run as a single instance only.
>>    * We may of course race updates of the target counts (which are protected
>>    * by the balloon lock), or with changes to the Xen hard limit, but we will
>>    * recover from these in time.
>>    */
>> -static void balloon_process(struct work_struct *work)
>> +static int balloon_thread(void *unused)
>>   {
>>   	enum bp_state state = BP_DONE;
>>   	long credit;
>> +	unsigned long timeout;
>> +
>> +	set_freezable();
>> +	for (;;) {
>> +		if (state == BP_EAGAIN)
>> +			timeout = balloon_stats.schedule_delay * HZ;
>> +		else
>> +			timeout = 3600 * HZ;
>> +		credit = current_credit();
>>   
>> +		wait_event_interruptible_timeout(balloon_thread_wq,
>> +				 balloon_thread_cond(state, credit), timeout);
> 
> 
> Given that wait_event_interruptible_timeout() is a bunch of nested macros do we need to worry here about overly aggressive compiler optimizing out 'credit = current_credit()'?

I don't think so. current_credit() is reading from balloon_stats, which
is a global variable. So the compiler shouldn't assume the contents
won't change.

But I can add a barrier() after 'credit = current_credit()' in case
you'd feel uneasy without it.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2021-09-08 15:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-27 12:32 [PATCH] xen/balloon: use a kernel thread instead a workqueue Juergen Gross
2021-09-08 14:47 ` Boris Ostrovsky
2021-09-08 15:11   ` Juergen Gross [this message]
2021-09-08 16:05     ` Boris Ostrovsky

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=9d1edc4e-b2b5-c620-17c6-31d238c2c417@suse.com \
    --to=jgross@suse.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jbeulich@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).