From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E399C7EE2A for ; Fri, 2 Jun 2023 06:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233731AbjFBGIz (ORCPT ); Fri, 2 Jun 2023 02:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233709AbjFBGIu (ORCPT ); Fri, 2 Jun 2023 02:08:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77FBD1AD for ; Thu, 1 Jun 2023 23:08:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1067636FB for ; Fri, 2 Jun 2023 06:08:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C70ABC433D2; Fri, 2 Jun 2023 06:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685686126; bh=/8Fx5MgOM8Y3VrkJfY+HxO7JcKDJ80iHzD29KFbu03k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pb8Ubp3R6tgB8H6vTQGgCH3tzWuD6oyOcOcf3ttcPYGj23huLTU0fHliTjPjmoDmF S4sDcA7+EXMHvkpmS2kTOOaf7woygcNK+jA12+b7X5QQn0szOwPe7nv1VasWWku++E UaXf2nCcQW9R7RPcQCvN+Vl2ItI34SvfzRqE7Oz6PN2Z6HAMyHFwrLD3Mre4s+HI5V i5geif2esZ7rlS9IwLkVV4zoMMyWTSJpV2EgoMIPRVWak7g5haPUTAw13YWgILQsnE cXzWowOFTIyJeUX6ayuvHs7T7t38btPgaZnC8Dvls9o7WHVEcOeh5hS/530SQ4Z5NX c+w75go6yxWew== Date: Thu, 1 Jun 2023 23:08:43 -0700 From: Chris Li To: Huang Ying Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Minchan Kim , Tim Chen , Yang Shi , Yu Zhao Subject: Re: [PATCH -V3 4/5] swap: remove get/put_swap_device() in __swap_duplicate() Message-ID: References: <20230529061355.125791-1-ying.huang@intel.com> <20230529061355.125791-5-ying.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230529061355.125791-5-ying.huang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 29, 2023 at 02:13:54PM +0800, Huang Ying wrote: > __swap_duplicate() is called by > > - swap_shmem_alloc(): the folio in swap cache is locked. > > - copy_nonpresent_pte() -> swap_duplicate() and try_to_unmap_one() -> > swap_duplicate(): the page table lock is held. > > - __read_swap_cache_async() -> swapcache_prepare(): enclosed with > get/put_swap_device() in __read_swap_cache_async() already. > > So, it's safe to remove get/put_swap_device() in __swap_duplicate(). > > Signed-off-by: "Huang, Ying" > Reviewed-by: Yosry Ahmed > Cc: David Hildenbrand > Cc: Hugh Dickins > Cc: Johannes Weiner > Cc: Matthew Wilcox > Cc: Michal Hocko > Cc: Minchan Kim > Cc: Tim Chen > Cc: Yang Shi > Cc: Yu Zhao > Cc: Chris Li > --- > mm/swapfile.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index e9cce775fb25..4dbaea64635d 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3264,9 +3264,7 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) > unsigned char has_cache; > int err; > > - p = get_swap_device(entry); > - if (!p) > - return -EINVAL; > + p = swp_swap_info(entry); > > offset = swp_offset(entry); > ci = lock_cluster_or_swap_info(p, offset); > @@ -3313,7 +3311,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) > > unlock_out: > unlock_cluster_or_swap_info(p, ci); > - put_swap_device(p); > return err; > } > > -- > 2.39.2 > Reviewed-by: Chris Li (Google) Chris