All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: Re: [RFC PATCH 5/5] module: Remove stop_machine from module unloading
Date: Tue, 21 Oct 2014 19:34:13 +0900	[thread overview]
Message-ID: <544636A5.1080204@hitachi.com> (raw)
In-Reply-To: <87ppdweg5g.fsf@rustcorp.com.au>

(2014/10/13 13:40), Rusty Russell wrote:
> Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> writes:
>> Remove stop_machine from module unloading by replacing module_ref
>> with atomic_t. Note that this can cause a performance regression
>> on big-SMP machine by direct memory access. For those machines,
>> you can lockdwon all modules. Since the lockdown skips reference
>> counting, it'll be more scalable than per-cpu module_ref counters.
> 
> Sorry for the delay; I didn't get to this before I left, and then
> I was away for 3 weeks vacation.
> 
> First, I agree you should drop the MODULE_STATE_LOCKUP patch.  While I
> can't audit every try_module_get() call, I did put an mdelay(100) in
> there and did a quick boot for any obvious slowdown.

OK, I might be thinking too much about performance. I'll drop it :)

> Second, this patch should be split into two parts.  The first would
> simply replace module_ref with atomic_t (a significant simplification),
> the second would get rid of stop machine.

OK, I'll do that.

> 
>> +/*
>> + * MODULE_REF_BASE must be 1, since we use atomic_inc_not_zero() for
>> + * recovering refcnt (see try_release_module_ref() ).
>> + */
>> +#define MODULE_REF_BASE	1
> 
> True, but we could use atomic_add_unless() instead, and make this
> completely generic, right?

Would you mean just replacing atomic_inc_not_zero() with atomic_add_unless()?

> 
>> +
>>  /* Init the unload section of the module. */
>>  static int module_unload_init(struct module *mod)
>>  {
>> -	mod->refptr = alloc_percpu(struct module_ref);
>> -	if (!mod->refptr)
>> -		return -ENOMEM;
>> +	/*
>> +	 * Initialize reference counter to MODULE_REF_BASE.
>> +	 * refcnt == 0 means module is going.
>> +	 */
>> +	atomic_set(&mod->refcnt, MODULE_REF_BASE);
>>  
>>  	INIT_LIST_HEAD(&mod->source_list);
>>  	INIT_LIST_HEAD(&mod->target_list);
>>  
>>  	/* Hold reference count during initialization. */
>> -	raw_cpu_write(mod->refptr->incs, 1);
>> +	atomic_inc(&mod->refcnt);
>>  
>>  	return 0;
>>  }
>> @@ -721,8 +728,6 @@ static void module_unload_free(struct module *mod)
>>  		kfree(use);
>>  	}
>>  	mutex_unlock(&module_mutex);
>> -
>> -	free_percpu(mod->refptr);
>>  }
>>  
>>  #ifdef CONFIG_MODULE_FORCE_UNLOAD
>> @@ -740,60 +745,38 @@ static inline int try_force_unload(unsigned int flags)
>>  }
>>  #endif /* CONFIG_MODULE_FORCE_UNLOAD */
>>  
>> -struct stopref
>> +/* Try to release refcount of module, 0 means success. */
>> +static int try_release_module_ref(struct module *mod)
>>  {
>> -	struct module *mod;
>> -	int flags;
>> -	int *forced;
>> -};
>> +	int ret;
>>  
>> -/* Whole machine is stopped with interrupts off when this runs. */
>> -static int __try_stop_module(void *_sref)
>> -{
>> -	struct stopref *sref = _sref;
>> +	/* Try to decrement refcnt which we set at loading */
>> +	ret = atomic_sub_return(MODULE_REF_BASE, &mod->refcnt);
>> +	if (ret)
>> +		/* Someone can put this right now, recover with checking */
>> +		ret = atomic_inc_not_zero(&mod->refcnt);
>> +
>> +	return ret;
>> +}
> 
> This is very clever!  I really like it.

Thanks!

-- 
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



  reply	other threads:[~2014-10-21 10:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-25 10:55 [RFC PATCH 0/5] module: Remove stop_machine from module unloading Masami Hiramatsu
2014-08-25 10:55 ` [RFC PATCH 1/5] module: Wait for RCU synchronizing before releasing a module Masami Hiramatsu
2014-08-25 10:55 ` [RFC PATCH 2/5] module: Unlink module with RCU synchronizing instead of stop_machine Masami Hiramatsu
2014-08-25 10:55 ` [RFC PATCH 3/5] lib/bug: Use RCU list ops for module_bug_list Masami Hiramatsu
2014-08-25 10:55 ` [RFC PATCH 4/5] module: Lock up a module when loading with a LOCLUP flag Masami Hiramatsu
2014-08-26  5:30   ` Lucas De Marchi
2014-08-26  9:26     ` Masami Hiramatsu
2014-08-26 12:04       ` [RFC PATCH 0/2] kmod: Support lockup option to make module un-removable Masami Hiramatsu
2014-08-26 12:04         ` [RFC PATCH 1/2] libkmod: support lockup module option Masami Hiramatsu
2014-08-26 12:04         ` [RFC PATCH 2/2] modprobe: Add --lockup option to make module unremovable Masami Hiramatsu
2014-09-01 22:17         ` [RFC PATCH 0/2] kmod: Support lockup option to make module un-removable Lucas De Marchi
2014-10-13  4:41           ` Rusty Russell
2014-08-25 10:55 ` [RFC PATCH 5/5] module: Remove stop_machine from module unloading Masami Hiramatsu
2014-10-13  4:40   ` Rusty Russell
2014-10-21 10:34     ` Masami Hiramatsu [this message]
2014-10-22  4:25       ` Rusty Russell
2014-10-21 11:27     ` Masami Hiramatsu
2014-09-03  3:11 ` [RFC PATCH 0/5] " Masami Hiramatsu

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=544636A5.1080204@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=rusty@rustcorp.com.au \
    /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.