From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933305AbdDFArk (ORCPT ); Wed, 5 Apr 2017 20:47:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:38436 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755451AbdDFArd (ORCPT ); Wed, 5 Apr 2017 20:47:33 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,281,1488873600"; d="scan'208";a="83697159" From: "Huang\, Ying" To: Rik van Riel Cc: "Huang\, Ying" , Andrew Morton , , , Hugh Dickins , Shaohua Li , Minchan Kim Subject: Re: [PATCH -mm -v2] mm, swap: Sort swap entries before free References: <20170405071041.24469-1-ying.huang@intel.com> <1491403231.16856.11.camel@redhat.com> Date: Thu, 06 Apr 2017 08:47:30 +0800 In-Reply-To: <1491403231.16856.11.camel@redhat.com> (Rik van Riel's message of "Wed, 5 Apr 2017 10:40:31 -0400") Message-ID: <87k26ye50d.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rik van Riel writes: > On Wed, 2017-04-05 at 15:10 +0800, Huang, Ying wrote: >> To solve the issue, the per-CPU buffer is sorted according to the >> swap >> device before freeing the swap entries.  Test shows that the time >> spent by swapcache_free_entries() could be reduced after the patch. > > That makes a lot of sense. > >> @@ -1075,6 +1083,8 @@ void swapcache_free_entries(swp_entry_t >> *entries, int n) >>   >>   prev = NULL; >>   p = NULL; >> + if (nr_swapfiles > 1) >> + sort(entries, n, sizeof(entries[0]), swp_entry_cmp, >> NULL); > > But it really wants a comment in the code, so people > reading the code a few years from now can see why > we are sorting things we are about to free. > > Maybe something like: >         /* Sort swap entries by swap device, so each lock is only taken > once. */ Good suggestion! I will add it in the next version. Best Regards, Huang, Ying >>   for (i = 0; i < n; ++i) { >>   p = swap_info_get_cont(entries[i], prev); >>   if (p)