Message ID | 20230522070905.16773-2-ying.huang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1269117vqo; Mon, 22 May 2023 00:36:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XQUzeoZo9Fsf8DdMzYcT9SQ+6MNco1C1WvlOwfPSgQCQ3bNHR4OkVl2Aj65XIKwvWwQ6T X-Received: by 2002:a05:6a20:a58f:b0:104:2200:8933 with SMTP id bc15-20020a056a20a58f00b0010422008933mr10846755pzb.62.1684740960308; Mon, 22 May 2023 00:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684740960; cv=none; d=google.com; s=arc-20160816; b=obZ5MlYsKDqmjRAE9kWRwd+Z2AqAORQJKEPlGR5/81UoSxM/CV5+xSn2KypwXNjYGS skDcYMrDWvjiyVtgyGCxTNjUbXXYKNWEKSc3u0fEbcMu8coWcqC7pHCIvgUziWAiYdhU miYNpvebRWaiS0iuYsUpJQKvh0COShjCAkctjyXahHAZE/uzju/5w3cb7sdhzp75GZuG 9WUWphAj8uzZD2ppfaOHM2xG2eYShnRAOUq+zKey2Akxjqebus+r2hPzRrT7vps2ytco HHeY8a0tLFIZPPA1pz6+2PJeBRa1r9ZCBsUz2jG2uqNDKpx1E67oXbvB+IPwFS8aCfz4 gRWQ== 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=AL/AHAqtFJKsPwKJ9HgR1WU6kXa6VgMjAHwiDhHscpI=; b=P7I9kQycFm19jsR1ExC4P76E7kGII/vuc6WcDjqtiKELtShTFf1Xh01lXtgkkcG7pC EE9EGsVDUN0jhgsuDE7zlHbnbpw9bIlIbFjapTRdDA/L9bCJlT7lsH92THvwHGvSR5yF /ILh8iWPaydbJZJp4Ar3CaoLvSJkl+OXcHjXdPb4pq8NKc+Wmx+/ZjtrM7U9DXVGmnnW kv4MZHkJgr4JAtW3P8/TQbOrfdUMC/GwqJa72SVYvSIPE8n3DW7tIj+eRjGM1xn7R/LW 4FnpOljNSqV0BisWHc6cuGoDjHcny1Pxy1FsCH+MdVraJK8W4PAGndJr9KcVIqnl+QQU Yvkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jQ7kzQqN; 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 x26-20020aa7941a000000b0063b76333d9asi4339888pfo.217.2023.05.22.00.35.48; Mon, 22 May 2023 00:36:00 -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=jQ7kzQqN; 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 S232408AbjEVHLF (ORCPT <rfc822;cscallsign@gmail.com> + 99 others); Mon, 22 May 2023 03:11:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232457AbjEVHJ7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 03:09:59 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81675129 for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 00:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1684739375; x=1716275375; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CAvLy4/ErwSMMyC1M2gR5vND9soNKvGVJOF+Oh8rPBI=; b=jQ7kzQqNSlMe8jzZScES1iN5M7sHDn2IentIcu0hBl/1rAre/gNE7EJz qyEN+e1EcjZ2s2CfIEFpUcpSw+hNHZ+g3IZEiYvtbgfypMHWI45qCcv3r X0oX5LXcc4ry3oo5KeQ2xoQAjkQAsISucPjYIJgVjOEwYNRnWfxJhlnm+ nitOjbh9tuk8fWrsxnN+2xHmHHE8Uwl2uE65TFkAVvTXhUMnqWoIsW4+R 9c9PCzAsD7iUsJwjDIYXre0tp4351VB4iffcMJqfpM5ZA4B3tG9luGEMA 0CKsxzS+Y/LWj5C+tjF2TneOlWlzCXEDAV7mXMLCnmmMiDq/YCMNMq4SP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="337436974" X-IronPort-AV: E=Sophos;i="6.00,183,1681196400"; d="scan'208";a="337436974" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 00:09:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10717"; a="773212678" X-IronPort-AV: E=Sophos;i="6.00,183,1681196400"; d="scan'208";a="773212678" Received: from yhuang6-mobl2.sh.intel.com ([10.238.5.152]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2023 00:09:22 -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>, 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> Subject: [PATCH -V2 1/5] swap: Remove get/put_swap_device() in __swap_count() Date: Mon, 22 May 2023 15:09:01 +0800 Message-Id: <20230522070905.16773-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230522070905.16773-1-ying.huang@intel.com> References: <20230522070905.16773-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1766578937295719510?= X-GMAIL-MSGID: =?utf-8?q?1766578937295719510?= |
Series |
swap: cleanup get/put_swap_device() usage
|
|
Commit Message
Huang, Ying
May 22, 2023, 7:09 a.m. UTC
__swap_count() is called in do_swap_page() only, which encloses the
call site with get/put_swap_device() already.
Signed-off-by: "Huang, Ying" <ying.huang@intel.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>
---
mm/swapfile.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
Comments
On 22.05.23 09:09, Huang Ying wrote: > __swap_count() is called in do_swap_page() only, which encloses the > call site with get/put_swap_device() already. > > Signed-off-by: "Huang, Ying" <ying.huang@intel.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> > --- > mm/swapfile.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 274bbf797480..8419cba9c192 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) > > int __swap_count(swp_entry_t entry) > { > - struct swap_info_struct *si; > + struct swap_info_struct *si = swp_swap_info(entry); > pgoff_t offset = swp_offset(entry); > - int count = 0; > > - si = get_swap_device(entry); > - if (si) { > - count = swap_count(si->swap_map[offset]); > - put_swap_device(si); > - } > - return count; > + return swap_count(si->swap_map[offset]); > } > > /* That locking was added in eb085574a752 ("mm, swap: fix race between swapoff and some swap operations"). Before 2799e77529c ("swap: fix do_swap_page() race with swapoff") added the get_swap_device() to do_swap_page(). Reviewed-by: David Hildenbrand <david@redhat.com>
On Mon, May 22, 2023 at 12:09 AM Huang Ying <ying.huang@intel.com> wrote: > > __swap_count() is called in do_swap_page() only, which encloses the > call site with get/put_swap_device() already. > > Signed-off-by: "Huang, Ying" <ying.huang@intel.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> > --- > mm/swapfile.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index 274bbf797480..8419cba9c192 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) > nit: I would add a comment here that the caller needs get/put_swap_device(). Reviewed-by: Yosry Ahmed <yosryahmed@google.com> > int __swap_count(swp_entry_t entry) > { > - struct swap_info_struct *si; > + struct swap_info_struct *si = swp_swap_info(entry); > pgoff_t offset = swp_offset(entry); > - int count = 0; > > - si = get_swap_device(entry); > - if (si) { > - count = swap_count(si->swap_map[offset]); > - put_swap_device(si); > - } > - return count; > + return swap_count(si->swap_map[offset]); > } > > /* > -- > 2.39.2 > >
Yosry Ahmed <yosryahmed@google.com> writes: > On Mon, May 22, 2023 at 12:09 AM Huang Ying <ying.huang@intel.com> wrote: >> >> __swap_count() is called in do_swap_page() only, which encloses the >> call site with get/put_swap_device() already. >> >> Signed-off-by: "Huang, Ying" <ying.huang@intel.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> >> --- >> mm/swapfile.c | 10 ++-------- >> 1 file changed, 2 insertions(+), 8 deletions(-) >> >> diff --git a/mm/swapfile.c b/mm/swapfile.c >> index 274bbf797480..8419cba9c192 100644 >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c >> @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) >> > > nit: I would add a comment here that the caller needs get/put_swap_device(). It's default behavior to call get/put_swap_device() in the caller for all almost all swap functions. I would rather comment the swap functions needn't to do that, as the comments for read_swap_cache_async() in [2/5]. > Reviewed-by: Yosry Ahmed <yosryahmed@google.com> Thanks! >> int __swap_count(swp_entry_t entry) >> { >> - struct swap_info_struct *si; >> + struct swap_info_struct *si = swp_swap_info(entry); >> pgoff_t offset = swp_offset(entry); >> - int count = 0; >> >> - si = get_swap_device(entry); >> - if (si) { >> - count = swap_count(si->swap_map[offset]); >> - put_swap_device(si); >> - } >> - return count; >> + return swap_count(si->swap_map[offset]); >> } >> >> /* Best Regards, Huang, Ying
On Mon, May 22, 2023 at 6:48 PM Huang, Ying <ying.huang@intel.com> wrote: > > Yosry Ahmed <yosryahmed@google.com> writes: > > > On Mon, May 22, 2023 at 12:09 AM Huang Ying <ying.huang@intel.com> wrote: > >> > >> __swap_count() is called in do_swap_page() only, which encloses the > >> call site with get/put_swap_device() already. > >> > >> Signed-off-by: "Huang, Ying" <ying.huang@intel.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> > >> --- > >> mm/swapfile.c | 10 ++-------- > >> 1 file changed, 2 insertions(+), 8 deletions(-) > >> > >> diff --git a/mm/swapfile.c b/mm/swapfile.c > >> index 274bbf797480..8419cba9c192 100644 > >> --- a/mm/swapfile.c > >> +++ b/mm/swapfile.c > >> @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) > >> > > > > nit: I would add a comment here that the caller needs get/put_swap_device(). > > It's default behavior to call get/put_swap_device() in the caller for > all almost all swap functions. I would rather comment the swap > functions needn't to do that, as the comments for > read_swap_cache_async() in [2/5]. Fair enough. The comment that you added above get_swap_device() states that all swap-related functions should have some sort of protection against swapoff, so I guess that's sufficient. My concern is that sometimes people don't know where to look, and having a comment above the function might be helpful. I do agree though that having a comment above ~all swap-related functions pointing to the comment above get_swap_device() is too much. > > > Reviewed-by: Yosry Ahmed <yosryahmed@google.com> > > Thanks! > > >> int __swap_count(swp_entry_t entry) > >> { > >> - struct swap_info_struct *si; > >> + struct swap_info_struct *si = swp_swap_info(entry); > >> pgoff_t offset = swp_offset(entry); > >> - int count = 0; > >> > >> - si = get_swap_device(entry); > >> - if (si) { > >> - count = swap_count(si->swap_map[offset]); > >> - put_swap_device(si); > >> - } > >> - return count; > >> + return swap_count(si->swap_map[offset]); > >> } > >> > >> /* > > Best Regards, > Huang, Ying
diff --git a/mm/swapfile.c b/mm/swapfile.c index 274bbf797480..8419cba9c192 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1432,16 +1432,10 @@ void swapcache_free_entries(swp_entry_t *entries, int n) int __swap_count(swp_entry_t entry) { - struct swap_info_struct *si; + struct swap_info_struct *si = swp_swap_info(entry); pgoff_t offset = swp_offset(entry); - int count = 0; - si = get_swap_device(entry); - if (si) { - count = swap_count(si->swap_map[offset]); - put_swap_device(si); - } - return count; + return swap_count(si->swap_map[offset]); } /*