Message ID | 20230529061355.125791-5-ying.huang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1309562vqr; Sun, 28 May 2023 23:22:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4c69NEFTmwxFiFKY+jpDKjqbFTCZiXsqk79KHvS04QZcJHZi1O4UXdNvpqWqM6QTgiRfsR X-Received: by 2002:a17:90b:84:b0:24d:e296:659b with SMTP id bb4-20020a17090b008400b0024de296659bmr7272596pjb.22.1685341347257; Sun, 28 May 2023 23:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685341347; cv=none; d=google.com; s=arc-20160816; b=JlL5rbRzTKlirt/ldNyT2ZoooRpB+MxkqNmK9bsS/ZE1HXeYAxzkkcEe1PdNe6jT6n yyiLw0enRdzXpN8cUIy71xWFwbwmyq1Uq67EtikvC+GovemYkTLkjz8kP6/oCzMxL4e2 PW48TOlSFoGj2ECOFnU09TE6JWnvRewj5YzaIY4zcZ3upyjcKCZKs1RMTAj1gepyner9 Tt70IQZr2v2lBmdrDEX7ZhelB4B3HiSKXZspCMlx/X8+dl59i2VrEc6T49bbGuU3txzp a6ksr2ndtgr9daMHSoGokKE7bLUnhMrACdRi+o85mBOseoTWTD7b8PB+zhhoZ5o8z7in MIew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OXQpXUyD3R4+lamxgQGM0SaoDtlSH6lRmsX6AawfPEk=; b=PQmIN089FCeSEY7btRzho0EvUQu/KELECNJClC1dJBlU/F9ge64169+/faU0/KuoFh 0o7JLv4lr0Xl0nZkEXhub7mk+U/Bqnu0NCG0WM0vjiOdqOAzOCsc238JVQRp0qRJEH9F TiufnGVUJR31W9Rze49WFCL6tiLCv0byvj7he3okDUQDAlu1CB5f01bkbuiSyGbpnW/Z +oMoZL6R+XHbIIMsS57alGs/WSVsAwNFCqR0uRKfStRdINJuk3lpsCPMigkRHY7KAdl5 DGJgSURIQUOF6/cV+7NYzLHO/l3NdqvqtYwA8yodJPoSsCiueCpsJNJ1ZpI0aI/XubkX X8HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cJxrFtlC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt14-20020a17090af2ce00b002502c10bdb4si2241501pjb.91.2023.05.28.23.22.13; Sun, 28 May 2023 23:22:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cJxrFtlC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230427AbjE2GOl (ORCPT <rfc822;callmefire3@gmail.com> + 99 others); Mon, 29 May 2023 02:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbjE2GOd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 29 May 2023 02:14:33 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70F8EF1 for <linux-kernel@vger.kernel.org>; Sun, 28 May 2023 23:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685340869; x=1716876869; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BU9rFfysv4elNLJ2GHzqi2liUatC3EzDYJWAUuFdw+0=; b=cJxrFtlCwIuI2Qjv4t0svwIYrYf8UN4laXVC3qIsq+xZpAtNS+1bPG4V w2QJ0pcsaEAY83MpX20jynYcuQx85NV01amjXU4pw5N6Wce5yK3+ICZco 41D0VgIKfZ9U9tBkRoE7eoSFx7zxvflNl4lFRqZMY45WpwvyXiKECzKYT elWTHgSozyruFTewpFqcuPxnm6cR/8d9Em19AQ7PGiPVR9H9wt/F3wPRA 2g10+RcObIGDHtdXWDAVaetUpmjRsxIdChk2PtJOWHZ0/DvM+vgpYAjU6 bVaEpse+rgKHOv+FqDZRH/c4SEyvpOKupgPB0uKd3jBU92DGtOy9Zzq3I A==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="357881854" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="357881854" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 23:14:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="1036080010" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="1036080010" Received: from azhao3-mobl1.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.126]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 23:14:25 -0700 From: Huang Ying <ying.huang@intel.com> To: Andrew Morton <akpm@linux-foundation.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying <ying.huang@intel.com>, Yosry Ahmed <yosryahmed@google.com>, David Hildenbrand <david@redhat.com>, Hugh Dickins <hughd@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Matthew Wilcox <willy@infradead.org>, Michal Hocko <mhocko@suse.com>, Minchan Kim <minchan@kernel.org>, Tim Chen <tim.c.chen@linux.intel.com>, Yang Shi <shy828301@gmail.com>, Yu Zhao <yuzhao@google.com>, Chris Li <chrisl@kernel.org> Subject: [PATCH -V3 4/5] swap: remove get/put_swap_device() in __swap_duplicate() Date: Mon, 29 May 2023 14:13:54 +0800 Message-Id: <20230529061355.125791-5-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230529061355.125791-1-ying.huang@intel.com> References: <20230529061355.125791-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767208488422666285?= X-GMAIL-MSGID: =?utf-8?q?1767208488422666285?= |
Series |
swap: cleanup get/put_swap_device() usage
|
|
Commit Message
Huang, Ying
May 29, 2023, 6:13 a.m. UTC
__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" <ying.huang@intel.com> Reviewed-by: Yosry Ahmed <yosryahmed@google.com> Cc: David Hildenbrand <david@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Tim Chen <tim.c.chen@linux.intel.com> Cc: Yang Shi <shy828301@gmail.com> Cc: Yu Zhao <yuzhao@google.com> Cc: Chris Li <chrisl@kernel.org> --- mm/swapfile.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
Comments
On 29.05.23 08:13, 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" <ying.huang@intel.com> > Reviewed-by: Yosry Ahmed <yosryahmed@google.com> > Cc: David Hildenbrand <david@redhat.com> > Cc: Hugh Dickins <hughd@google.com> > Cc: Johannes Weiner <hannes@cmpxchg.org> > Cc: Matthew Wilcox <willy@infradead.org> > Cc: Michal Hocko <mhocko@suse.com> > Cc: Minchan Kim <minchan@kernel.org> > Cc: Tim Chen <tim.c.chen@linux.intel.com> > Cc: Yang Shi <shy828301@gmail.com> > Cc: Yu Zhao <yuzhao@google.com> > Cc: Chris Li <chrisl@kernel.org> > --- Reviewed-by: David Hildenbrand <david@redhat.com>
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" <ying.huang@intel.com> > Reviewed-by: Yosry Ahmed <yosryahmed@google.com> > Cc: David Hildenbrand <david@redhat.com> > Cc: Hugh Dickins <hughd@google.com> > Cc: Johannes Weiner <hannes@cmpxchg.org> > Cc: Matthew Wilcox <willy@infradead.org> > Cc: Michal Hocko <mhocko@suse.com> > Cc: Minchan Kim <minchan@kernel.org> > Cc: Tim Chen <tim.c.chen@linux.intel.com> > Cc: Yang Shi <shy828301@gmail.com> > Cc: Yu Zhao <yuzhao@google.com> > Cc: Chris Li <chrisl@kernel.org> > --- > 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) <chrisl@kernel.org> Chris
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; }