From: Cesar Eduardo Barros <cesarb@cesarb.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Dan Magenheimer <dan.magenheimer@oracle.com>,
Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@redhat.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH 1/2] mm: refactor reinsert of swap_info in sys_swapoff
Date: Tue, 30 Oct 2012 20:48:46 -0200 [thread overview]
Message-ID: <5090594E.7050401@cesarb.net> (raw)
In-Reply-To: <20121030140417.988c2437.akpm@linux-foundation.org>
Em 30-10-2012 19:04, Andrew Morton escreveu:
> Your patch doesn't change this, but... it is very unusual for any
> subsystem's ->init method to be called under a spinlock. Because it is
> highly likely that such a method will wish to do things such as memory
> allocation.
>
> It is rare and unlikely for an ->init() method to *need* such external
> locking, because all the objects it is dealing with cannot be looked up
> by other threads because nothing has been registered anywhere yet.
The frontswap_init() method is being passed the swap_info_struct's
->type, which it uses to get back the swap_info_struct itself, which it
then uses to check if the frontswap_map allocation succeeded. As noted
by the commit message for commit 38b5faf (mm: frontswap: core swap
subsystem hooks and headers), that allocation can fail, which will do
nothing more than not enable frontswap for that swap area.
The same parameter is then passed down to the ->init() method, which
proceeds to sumarily ignore it on the three in-tree implementations I
looked at.
Yeah, it looks like a violation of YAGNI to me, and doing things in a
more roundabount way than is justified. Why pass the ->type and then get
the pointer from it instead of just passing the pointer in the first
place? Or better yet, why not pass the frontswap_map pointer? Even
better, why not a boolean saying whether it worked? Even better, *why
not just put the conditional inside enable_swap_info* and pass no
parameter at all?
> So either frontswap is doing something wrong here or there's some
> subtlety which escapes me. If the former then we should try to get
> that ->init call to happen outside swap_lock.
I believe the swap_lock is protecting the poolid. It is possible that
other things in the frontswap code are being called before the first
swapon with a successful frontswap_map allocation (which is when the
poolid would get allocated).
A quick look suggests the poolid only gets set on an initcall or in the
->init() method; perhaps a local mutex (to prevent double allocation)
and an atomic update of the poolid would be enough to move it outside
the lock (and also outside the swapon_mutex).
But that would work only if no out-of-tree frontswap module needs it
within the swap_lock.
> And if we can do that, perhaps we can fix the regrettable GFP_ATOMIC
> in zcache_new_pool().
--
Cesar Eduardo Barros
cesarb@cesarb.net
cesar.barros@gmail.com
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-10-30 22:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-27 21:20 [PATCH 0/2] mm: do not call frontswap_init() during swapoff Cesar Eduardo Barros
2012-10-27 21:20 ` [PATCH 1/2] mm: refactor reinsert of swap_info in sys_swapoff Cesar Eduardo Barros
2012-10-30 21:04 ` Andrew Morton
2012-10-30 22:48 ` Cesar Eduardo Barros [this message]
2012-10-30 23:12 ` [PATCH RFC] mm: simplify frontswap_init() Cesar Eduardo Barros
2012-10-31 13:42 ` Konrad Rzeszutek Wilk
2012-10-31 13:45 ` [PATCH 1/2] mm: refactor reinsert of swap_info in sys_swapoff Konrad Rzeszutek Wilk
2012-10-27 21:20 ` [PATCH 2/2] mm: do not call frontswap_init() during swapoff Cesar Eduardo Barros
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=5090594E.7050401@cesarb.net \
--to=cesarb@cesarb.net \
--cc=akpm@linux-foundation.org \
--cc=dan.magenheimer@oracle.com \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=riel@redhat.com \
/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