From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755751AbdGXQzZ (ORCPT ); Mon, 24 Jul 2017 12:55:25 -0400 Received: from mga05.intel.com ([192.55.52.43]:35809 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932731AbdGXQzK (ORCPT ); Mon, 24 Jul 2017 12:55:10 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,408,1496127600"; d="scan'208";a="290689135" Subject: Re: [PATCH 2/2] mm/swap: Remove lock_initialized flag from swap_slots_cache To: "Huang, Ying" Cc: Andrew Morton , Wenwei Tao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Rik van Riel , Andrea Arcangeli , Johannes Weiner , Michal Hocko , Hillf Danton References: <65a9d0f133f63e66bba37b53b2fd0464b7cae771.1500677066.git.tim.c.chen@linux.intel.com> <867d1fb070644e6d5f0ac7780f63e75259b82cc3.1500677066.git.tim.c.chen@linux.intel.com> <878tjeh96m.fsf@yhuang-dev.intel.com> From: Tim Chen Message-ID: Date: Mon, 24 Jul 2017 09:54:50 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: <878tjeh96m.fsf@yhuang-dev.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/23/2017 07:15 PM, Huang, Ying wrote: > Hi, Tim, > > Tim Chen writes: > >> We will only reach the lock initialization code >> in alloc_swap_slot_cache when the cpu's swap_slots_cache's slots >> have not been allocated and swap_slots_cache has not been initialized >> previously. So the lock_initialized check is redundant and unnecessary. >> Remove lock_initialized flag from swap_slots_cache to save memory. > > Is there a race condition with CPU offline/online when preempt is enabled? > > CPU A CPU B > ----- ----- > get_swap_page() > get cache[B], cache[B]->slots != NULL > preempted and moved to CPU A > be offlined > be onlined > alloc_swap_slot_cache() > mutex_lock(cache[B]->alloc_lock) > mutex_init(cache[B]->alloc_lock) !!! > > The cache[B]->alloc_lock will be reinitialized when it is still held. Looks like for this case the lock_initialized flag is still needed to prevent such races and prevent re-initialization of taken locks. Okay, let's scrap patch 2. Thanks. Tim