OSDN Git Service

mm: swap_ratio: bail out if there aren't any other swap device
authorVinayak Menon <vinmenon@codeaurora.org>
Tue, 22 Mar 2016 09:11:57 +0000 (14:41 +0530)
committerKyle Yan <kyan@codeaurora.org>
Tue, 31 May 2016 22:23:38 +0000 (15:23 -0700)
commit350c68c1244f3ca8129770e7d707e64f1621bfae
tree88714ec45a125ce6b8f1659faafe4f617c941f98
parent44bd107fc9cdb2d3b195e01611b074f609b97f1a
mm: swap_ratio: bail out if there aren't any other swap device

It is pointless to calculate the swap ratio when there is only
one swap device in the group. Moreover the existing code would
result in a spinlock recursion because of not taking this into
consideration. Interestingly, this check is already performed
in swap_ratio_slow by this piece of code

if (&(*si)->avail_list == plist_last(&swap_avail_head)) {
/* just to make skip work */
n = *si;
ret = -ENODEV;
goto skip;
}

But there is window where we drop the swap_avail_lock before
invoking swap_ratio() and take it back again in swap_ratio_slow.
In this period the si can get removed from swap_avail_head,
resulting in the failure of above logic. So recheck again.

Similarly, bail out from swap_ratio() if the sysctl is disabled,
and thus avoiding overhead of taking unnecessary locks.

Change-Id: I81a9dd61d24b7da55d5341c48a1f71d2b4b1978d
Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
mm/swap_ratio.c