From patchwork Thu Feb 17 06:07:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12749422 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82FFCC433F5 for ; Thu, 17 Feb 2022 06:08:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0448B6B007D; Thu, 17 Feb 2022 01:08:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE6066B007E; Thu, 17 Feb 2022 01:08:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D604C6B0080; Thu, 17 Feb 2022 01:08:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0167.hostedemail.com [216.40.44.167]) by kanga.kvack.org (Postfix) with ESMTP id C68C46B007D for ; Thu, 17 Feb 2022 01:08:19 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8146818108638 for ; Thu, 17 Feb 2022 06:08:19 +0000 (UTC) X-FDA: 79151241918.16.092488C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id EE24A120008 for ; Thu, 17 Feb 2022 06:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645078098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Iw+/fHKv6eLf6uybneXrBCZa8a9WBXNMPZFyFhXGnU=; b=hnrFThXaZ7tiyraKlfvOsSbYHvOzHgd1gxr59YfaEZBoJgVYY30BH4tq/R8DDYSZs5UuBI bCik27U9zxTbbFO0vmI093rhBg4GxHEo/h57uORDt+vEJRkxCrX46uf3aJVwS38d3zDOcD ULw70c/b4p7/OPn0auukQQ2xMIZw+No= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-84-fZ9mjwQAMIeBywyOFirOVQ-1; Thu, 17 Feb 2022 01:08:17 -0500 X-MC-Unique: fZ9mjwQAMIeBywyOFirOVQ-1 Received: by mail-pj1-f69.google.com with SMTP id fa22-20020a17090af0d600b001bb93310b41so1648622pjb.3 for ; Wed, 16 Feb 2022 22:08:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Iw+/fHKv6eLf6uybneXrBCZa8a9WBXNMPZFyFhXGnU=; b=5hY8RaFOB5onTKTfabWhb+ugy4w+VyqCVV6948e3eXYx6429ett6djy5M4jlfYcwvT bf2oQxTxqQoG+bbregyl9dnx7wJ8RdA83LhTvYZA9TJl7mfOJUE+ipvJv5nECwInm1tC uht6cLJYHKFHI2RzOvpDjzls5pkPL0zTaLulmsJ2QdOn4e1vKsbY6i9rtpJ6NML82V9g mS9FAjXKtK8sKl2WawChzphIRfRzQMCAavHwXlgAnLvwX0oWXHK6kT4YkHyTViIuGcmk +83l0smwt0A1aKSvctIG6BIYc3SLMbgliiuwpqI/SRYAw6i0X2CWOtEPJ59/IDwybiTP 0tYA== X-Gm-Message-State: AOAM532o0xQFIEzK+4295DC4lhroR4RXZouBpbuYFLnmbv0ePtPI9HVg dUq7uCTwZstEB08Jp5xZ+Si9jVJNSnMBKEFc0NLKhIilNGQtD8szk9rb+CearEUWTJzuUYWXlF1 9WicTpsQ+51BbiUGKGj+4yGhw2OtrtDvx8wmxOIbqU9obat8hHCTDQMqpzqqO X-Received: by 2002:a05:6a00:8c5:b0:4c7:f9a5:ebc6 with SMTP id s5-20020a056a0008c500b004c7f9a5ebc6mr1690190pfu.34.1645078096197; Wed, 16 Feb 2022 22:08:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJq01ZMuxcXHBVvWHdhve6h2WPzO7RXn4GgLcncsq4yBWdeLBav4ZSIjD78cJP8QrYAxhIEQ== X-Received: by 2002:a05:6a00:8c5:b0:4c7:f9a5:ebc6 with SMTP id s5-20020a056a0008c500b004c7f9a5ebc6mr1690157pfu.34.1645078095837; Wed, 16 Feb 2022 22:08:15 -0800 (PST) Received: from localhost.localdomain ([94.177.118.126]) by smtp.gmail.com with ESMTPSA id j8sm224230pjc.11.2022.02.16.22.08.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 16 Feb 2022 22:08:15 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Alistair Popple , Matthew Wilcox , peterx@redhat.com, David Hildenbrand , Andrea Arcangeli , Hugh Dickins , Yang Shi , Vlastimil Babka , John Hubbard , Andrew Morton , "Kirill A . Shutemov" Subject: [PATCH v5 4/4] mm: Rework swap handling of zap_pte_range Date: Thu, 17 Feb 2022 14:07:46 +0800 Message-Id: <20220217060746.71256-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220217060746.71256-1-peterx@redhat.com> References: <20220217060746.71256-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: EE24A120008 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hnrFThXa; spf=none (imf29.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: kzoh8rgqbirdg5ugi7heutgwd35mxgrb X-Rspamd-Server: rspam03 X-HE-Tag: 1645078098-688752 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: Clean the code up by merging the device private/exclusive swap entry handling with the rest, then we merge the pte clear operation too. struct* page is defined in multiple places in the function, move it upward. free_swap_and_cache() is only useful for !non_swap_entry() case, put it into the condition. No functional change intended. Reviewed-by: John Hubbard Signed-off-by: Peter Xu --- mm/memory.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c2defe8a1472..6aa51ee2a307 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1361,6 +1361,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, arch_enter_lazy_mmu_mode(); do { pte_t ptent = *pte; + struct page *page; + if (pte_none(ptent)) continue; @@ -1368,8 +1370,6 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, break; if (pte_present(ptent)) { - struct page *page; - page = vm_normal_page(vma, addr, ptent); if (unlikely(!should_zap_page(details, page))) continue; @@ -1403,28 +1403,21 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, entry = pte_to_swp_entry(ptent); if (is_device_private_entry(entry) || is_device_exclusive_entry(entry)) { - struct page *page = pfn_swap_entry_to_page(entry); - + page = pfn_swap_entry_to_page(entry); if (unlikely(!should_zap_page(details, page))) continue; - pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); rss[mm_counter(page)]--; - if (is_device_private_entry(entry)) page_remove_rmap(page, false); - put_page(page); - continue; - } - - if (!non_swap_entry(entry)) { + } else if (!non_swap_entry(entry)) { /* Genuine swap entry, hence a private anon page */ if (!should_zap_cows(details)) continue; rss[MM_SWAPENTS]--; + if (unlikely(!free_swap_and_cache(entry))) + print_bad_pte(vma, addr, ptent, NULL); } else if (is_migration_entry(entry)) { - struct page *page; - page = pfn_swap_entry_to_page(entry); if (!should_zap_page(details, page)) continue; @@ -1436,8 +1429,6 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, /* We should have covered all the swap entry types */ WARN_ON_ONCE(1); } - if (unlikely(!free_swap_and_cache(entry))) - print_bad_pte(vma, addr, ptent, NULL); pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); } while (pte++, addr += PAGE_SIZE, addr != end);