From patchwork Tue Mar 31 08:46:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 11466971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2EC514B4 for ; Tue, 31 Mar 2020 08:46:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C954120848 for ; Tue, 31 Mar 2020 08:46:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C954120848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 01EA36B0032; Tue, 31 Mar 2020 04:46:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F10FA6B0037; Tue, 31 Mar 2020 04:46:36 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFF8A6B006C; Tue, 31 Mar 2020 04:46:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id C550F6B0032 for ; Tue, 31 Mar 2020 04:46:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 79D97824805A for ; Tue, 31 Mar 2020 08:46:36 +0000 (UTC) X-FDA: 76655026392.01.look58_39a3d75d65754 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,ying.huang@intel.com,,RULES_HIT:30003:30012:30025:30054:30064:30070,0,RBL:134.134.136.65:@intel.com:.lbl8.mailshell.net-62.18.0.100 64.95.201.95,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: look58_39a3d75d65754 X-Filterd-Recvd-Size: 3469 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 31 Mar 2020 08:46:35 +0000 (UTC) IronPort-SDR: zuNyAQmChf+zl3FCLBk4WcO+IiFrBsGHhun0d0wzxzf79K1tpw39GMWlfTjNPAVRlCYPoH3x2R TlLiYs9qsJ2g== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Mar 2020 01:46:28 -0700 IronPort-SDR: f7rPsaBapnpRYt+jaYUbJlG+PrJWci/MRaj4t6k8fAtPtK0vZ9u+M3+ew0AAsh/+whCDaAI2qx EjJ458LOzUPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,327,1580803200"; d="scan'208";a="294864861" Received: from yhuang-dev.sh.intel.com ([10.239.159.23]) by FMSMGA003.fm.intel.com with ESMTP; 31 Mar 2020 01:46:24 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Michal Hocko , Minchan Kim , Hugh Dickins , Rik van Riel Subject: [PATCH] mm, trivial: Simplify swap related code in try_to_unmap_one() Date: Tue, 31 Mar 2020 16:46:13 +0800 Message-Id: <20200331084613.1258555-1-ying.huang@intel.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Huang Ying Because PageSwapCache() will always return false if PageSwapBacked() returns false, and PageSwapBacked() will be check for MADV_FREE pages in try_to_unmap_one(). The swap related code in try_to_unmap_one() can be simplified to improve the readability. Signed-off-by: "Huang, Ying" Cc: Michal Hocko Cc: Minchan Kim Cc: Hugh Dickins Cc: Rik van Riel --- mm/rmap.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 2126fd4a254b..cd3c406aeac7 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1613,19 +1613,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, } else if (PageAnon(page)) { swp_entry_t entry = { .val = page_private(subpage) }; pte_t swp_pte; - /* - * Store the swap location in the pte. - * See handle_pte_fault() ... - */ - if (unlikely(PageSwapBacked(page) != PageSwapCache(page))) { - WARN_ON_ONCE(1); - ret = false; - /* We have to invalidate as we cleared the pte */ - mmu_notifier_invalidate_range(mm, address, - address + PAGE_SIZE); - page_vma_mapped_walk_done(&pvmw); - break; - } /* MADV_FREE page check */ if (!PageSwapBacked(page)) { @@ -1648,6 +1635,20 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, break; } + /* + * Store the swap location in the pte. + * See handle_pte_fault() ... + */ + if (unlikely(!PageSwapCache(page))) { + WARN_ON_ONCE(1); + ret = false; + /* We have to invalidate as we cleared the pte */ + mmu_notifier_invalidate_range(mm, address, + address + PAGE_SIZE); + page_vma_mapped_walk_done(&pvmw); + break; + } + if (swap_duplicate(entry) < 0) { set_pte_at(mm, address, pvmw.pte, pteval); ret = false;