Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp680116pxb; Wed, 16 Feb 2022 01:50:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvbf2lsWZs5ewsgN9yijzXnhlIxqz1xPBVRJv/J4M6z8Gct01ZvXbwjBM2ytiKuj8ntoBd X-Received: by 2002:a17:902:7442:b0:14e:e5b2:6af6 with SMTP id e2-20020a170902744200b0014ee5b26af6mr1744069plt.136.1645005040461; Wed, 16 Feb 2022 01:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645005040; cv=none; d=google.com; s=arc-20160816; b=LxtI9jWjaYtSp9yAQ0nRxfHwwvGmbl8jV1iiUNv4riHC6wnaGmNMYvHcNSVDSWYKHj zOdte0i/EsbvdC5cGoeaLig0yw6aXxefu6ETv1n5unvp7YBSuRe6wvySoLa7lc6FrGfZ mEWQM/9yuDTY6Xt+LpDDl1aZJpNKirHW8yA6pwLD0ezFeE6vjhrqmEpX0t0K3LOh7DEI vLZRXHZrEGp2cUTpf+cSoQSWLBLehJP0I4aK6zqKdxGkEfP9cBv08oAPGaMvCifKtJTm OXL3DGEvh4b9GNHfYHIo1tWD/3LwPxPqC68H3WZe+2pGKq5Wubud4eHe0MMIJ2QqGW9T 3+Qg== 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=rxjE8nQUBN11kwzcRplXdSY7IFspDWL4Rd9u3ETZvZU=; b=Wj5pzaVWXUqD+li6n2v3VozFZNjg7gNhDzBc6NU1mVybgIL0Ovh05oLHjuO/PsYUOj OxRsi4vI7ADeKbZY5KbSdrvcBt1NkwZTUT+2YRuD4+kc7mvHBAm95mx1V6fdmolCNbNb Ekj6v+3eEKLgiKI7NNnKSD6xXlNXgGLrOBDuovSzPwbnUrHZbiWgIKBClE8ba0lu3T+F 9ArtKHDOJmT7toqackOs8+aQNgA2nkJZ3/k142KfcyW0K1qVXzUus9DWHndOn7VKvpKA 5o7eyF/vtX/mvxJkWQEeOsxwSZU54ih+c6gf1DQNUyR+gN1qn4U+9fQ9qGXhA/QgTimN Bbqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ir615H0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ot12si10940145pjb.66.2022.02.16.01.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 01:50:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ir615H0R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AD36327AA1D; Wed, 16 Feb 2022 01:49:50 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232458AbiBPJt4 (ORCPT + 99 others); Wed, 16 Feb 2022 04:49:56 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:40804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232492AbiBPJtw (ORCPT ); Wed, 16 Feb 2022 04:49:52 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 681582B4D86 for ; Wed, 16 Feb 2022 01:49:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645004976; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rxjE8nQUBN11kwzcRplXdSY7IFspDWL4Rd9u3ETZvZU=; b=Ir615H0RNSiExfYgbPzQlwbLcyQDK1T2Ef/yh/wVID4o1voW+93/gqpEJiDVtjHIzrYI98 a5tjEcD3Qszr5dTkFzoxRJgSmXfawvbWeYYADkXaAgV/jBL6BNErKjwUPo9kKqPxcOy67n Jrxm/C6UPdZfSZpnnZK6CWlIdUKNSvk= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-H7wICrN8P6SCSHgk5fLM7Q-1; Wed, 16 Feb 2022 04:49:35 -0500 X-MC-Unique: H7wICrN8P6SCSHgk5fLM7Q-1 Received: by mail-pf1-f199.google.com with SMTP id y28-20020aa793dc000000b004e160274e3eso1179448pff.18 for ; Wed, 16 Feb 2022 01:49:35 -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=rxjE8nQUBN11kwzcRplXdSY7IFspDWL4Rd9u3ETZvZU=; b=MhlfvKAfylQPcEwTjxEGlfwNT2p5jTjFgkqhpy3BEqlTpKcAYPWvxdd54ysWKdT1Ne YyW4gutPXP/OZPb1gSF/33F4y2rm+RhAMsQ9nUu08w3ON2dJBKrHWx0fHwR2dd/O6UBs EiXHw7RypY4wCEBH/v960x4n1R0YIA7tYjjJch0fcvX0RCRonJxfHmW5v0ejKD+c/gnO KWYa7CSzequfs+yffTy9eyx/m+ouTHyZsbH5980uBPIa1dkMn8SWSFKwG6wNJHbiTTm/ hYvG8Ww0JJhyZpxXSdRF/Kankl1EsoBl48Z/0dJByQdy4N4cpUze4NLlGZjqfruE3nRU chTw== X-Gm-Message-State: AOAM531hPVx6Zz5R/QbNv5IIGD7THn4Ac+VS1F9FMBdEJX219QCJuYDd bxck2lsDDiwWTjR2Ef8s3mQ4USzaBlucmhUfW5q5LBXy3sAy0EoL0kPRPGNG+QY4ALbqVr/NF7l nDL840EhGWZeUgPkGyNbu80WWM5K0Fe4VtA5n0veDeI0JzMKvPT+o2WBGXHRQOSxrR9nmKSYDQA == X-Received: by 2002:a17:902:7892:b0:14e:c520:e47d with SMTP id q18-20020a170902789200b0014ec520e47dmr1620168pll.105.1645004973437; Wed, 16 Feb 2022 01:49:33 -0800 (PST) X-Received: by 2002:a17:902:7892:b0:14e:c520:e47d with SMTP id q18-20020a170902789200b0014ec520e47dmr1620133pll.105.1645004973050; Wed, 16 Feb 2022 01:49:33 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id qe7sm11567835pjb.25.2022.02.16.01.49.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 16 Feb 2022 01:49:32 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , "Kirill A . Shutemov" , Matthew Wilcox , Yang Shi , Andrea Arcangeli , peterx@redhat.com, John Hubbard , Alistair Popple , David Hildenbrand , Vlastimil Babka , Hugh Dickins Subject: [PATCH v4 4/4] mm: Rework swap handling of zap_pte_range Date: Wed, 16 Feb 2022 17:48:10 +0800 Message-Id: <20220216094810.60572-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220216094810.60572-1-peterx@redhat.com> References: <20220216094810.60572-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 ffa8c7dfe9ad..cade96024349 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,21 +1403,14 @@ 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)) { /* * If this is a genuine swap entry, then it must be an * private anon page. If the caller wants to skip @@ -1426,9 +1419,9 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, 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; @@ -1441,8 +1434,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); -- 2.32.0