Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp680129pxb; Wed, 16 Feb 2022 01:50:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHqrBpcSCYiLlzlJnYp0kCneOw8+g9ILBnmZSPCDaapIXrCWESST23tqWqQ3n8eVTlhZ4Q X-Received: by 2002:a17:90b:3607:b0:1b8:efe5:9008 with SMTP id ml7-20020a17090b360700b001b8efe59008mr756032pjb.163.1645005041879; Wed, 16 Feb 2022 01:50:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645005041; cv=none; d=google.com; s=arc-20160816; b=BqVZD/avNisv55D9cS3Xt3bljCs/4AdRZmfO1TV9iIS5kQYO7+4FhSerQRUCGlBK7N WlG/TMA1R+Xr3qu0ToD+m9jaY3XDp1h6d0I/UpJU8/7J9PjxAGPDb1Vs1xamSnFJpHPK oE3ddwmOM48qic39wWO3nl3cOciEWcTC8rImoWJ/BfqDQfVOB2Ezo2HFXnqHlRqJFvGF Mpjz6zZ8nYL4kJEVh6vsdNNBPdEaasd6nbM4o5m0nVe4rPujx4VYWOz45TJq/1Llf+5E PgjK5wse6HMeG8Hlk2WSYdNhsUFMcvuDFcXnosVPzv0Ie0xO28vYou0vspCVFg6oSUDs nivA== 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=oZfOtFEoi6jPUWDy50tF9fEsGXQRQqyIANlBUu6Ts5c=; b=Tj/Zqm2smCQ6LW1tHM8bGLvzMmzZVj/D3VzRGXJ6ZCvb5xgcopxdhK4dx9pF2c0vF+ 5Pko2N64MUH/C7G1a97DLqeXD7JytinoBlwSdq5v2B6ZozlS7z7YaabWWHxXdNVQ8lMU 83oAcdvTG4uW6U62U/R2lxBkJEwCfejb66A0E0BTe0gzlryjGjMg4UNH3KVfmncVvVrq D1udJwaiyOefzXNlr0y40Zr3aYu7HmNtCM8QYt7EwdDBpHLDpo9s+oBC4lqbGXbAh8Qz Fhcd8HZhIFAY2dzSQCX9meEo5wzQmvJWKZlnDfEbMQ8IIOPZSzl81ySQC/k2bUNa71Bk gjmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=faA21TKR; 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 q77si8634718pfc.250.2022.02.16.01.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 01:50:41 -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=faA21TKR; 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 AAD732B2C4B; Wed, 16 Feb 2022 01:50:06 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232464AbiBPJtk (ORCPT + 99 others); Wed, 16 Feb 2022 04:49:40 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232430AbiBPJtd (ORCPT ); Wed, 16 Feb 2022 04:49:33 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9A37E2B4072 for ; Wed, 16 Feb 2022 01:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645004960; 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=oZfOtFEoi6jPUWDy50tF9fEsGXQRQqyIANlBUu6Ts5c=; b=faA21TKRiY+fR9ZiteElUmfmuHrq+1s40BNwUyotMovb6BNvWP4IaGgmJ/9TBQEUi0qAiR c/kHst1yVKPBgFPD0KOROw0roAgXoHW4MDBL5yVrWwTOG+kvJaClXKqveA0LfRgEgTBMqR UnJtR9MsGXmg0ddrZz7JDGgS5OTpD4I= 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-616-eLwqPexkMZy7DyX59K8Rqg-1; Wed, 16 Feb 2022 04:49:19 -0500 X-MC-Unique: eLwqPexkMZy7DyX59K8Rqg-1 Received: by mail-pf1-f199.google.com with SMTP id h3-20020a628303000000b004e12f44a262so1172826pfe.21 for ; Wed, 16 Feb 2022 01:49:19 -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=oZfOtFEoi6jPUWDy50tF9fEsGXQRQqyIANlBUu6Ts5c=; b=KuMdRYelMC5t5yvwL54xWSskemp4qe0h1Sw85Cd9l0vq86PMk+SlBPAsRwu5I7Gg2j WWwEFylPrtl7B1LLfxlVM+Ahr2PiaSQnnxTGutfQuhTA14ZTjNzjx7nqSjZVHb596SHW m4oKTc6k1OZRLmXZHzd2qqSOAByszxk1WeKm1vxf2F4a5Vb8DUAi8NGMWJ+BeljTHWYw b/6klyVcIxObGjnC13a5s/X3+hxlhLo0IxbJTk6N07712VSCq5Sv8L+L5NR+JzW0YwkV Bo60IRXnQLycOTz81VShyWU3tQHN5lRsnVXc4A5uytH6uUWbjO9Srz3ZHkR3KCIm8R2q dk0A== X-Gm-Message-State: AOAM530igqjvrg/ASC9W4+99/PKT58gO9+CA0DCkHo3fWHHLijf/6f0G UdvvH3FPS+PF2aWWs7G0xnaJ8sqvJbc6GvqJ0qMjE/AevOawKzcoEjj7NRSOCH8uhPTudy951X1 43Gfbt/GJfuaZqTkDWnHz7alB4l306Q1GBez7ce/bC4k/tEsKhzQem0iwqTnG++IZuTtLHU4i6w == X-Received: by 2002:a17:90a:e7ca:b0:1b9:66c8:982c with SMTP id kb10-20020a17090ae7ca00b001b966c8982cmr784818pjb.30.1645004958385; Wed, 16 Feb 2022 01:49:18 -0800 (PST) X-Received: by 2002:a17:90a:e7ca:b0:1b9:66c8:982c with SMTP id kb10-20020a17090ae7ca00b001b966c8982cmr784784pjb.30.1645004958039; Wed, 16 Feb 2022 01:49:18 -0800 (PST) Received: from localhost.localdomain ([64.64.123.81]) by smtp.gmail.com with ESMTPSA id qe7sm11567835pjb.25.2022.02.16.01.49.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 16 Feb 2022 01:49:17 -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 3/4] mm: Change zap_details.zap_mapping into even_cows Date: Wed, 16 Feb 2022 17:48:09 +0800 Message-Id: <20220216094810.60572-4-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 Currently we have a zap_mapping pointer maintained in zap_details, when it is specified we only want to zap the pages that has the same mapping with what the caller has specified. But what we want to do is actually simpler: we want to skip zapping private (COW-ed) pages in some cases. We can refer to unmap_mapping_pages() callers where we could have passed in different even_cows values. The other user is unmap_mapping_folio() where we always want to skip private pages. According to Hugh, we used a mapping pointer for historical reason, as explained here: https://lore.kernel.org/lkml/391aa58d-ce84-9d4-d68d-d98a9c533255@google.com/ Quoting partly from Hugh: Which raises the question again of why I did not just use a boolean flag there originally: aah, I think I've found why. In those days there was a horrible "optimization", for better performance on some benchmark I guess, which when you read from /dev/zero into a private mapping, would map the zero page there (look up read_zero_pagealigned() and zeromap_page_range() if you dare). So there was another category of page to be skipped along with the anon COWs, and I didn't want multiple tests in the zap loop, so checking check_mapping against page->mapping did both. I think nowadays you could do it by checking for PageAnon page (or genuine swap entry) instead. This patch replaced the zap_details.zap_mapping pointer into the even_cows boolean, then we check it against PageAnon. Suggested-by: Hugh Dickins Signed-off-by: Peter Xu --- mm/memory.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 14d8428ff4db..ffa8c7dfe9ad 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1309,8 +1309,8 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { - struct address_space *zap_mapping; /* Check page->mapping if set */ struct folio *single_folio; /* Locked folio to be unmapped */ + bool even_cows; /* Zap COWed private pages too? */ }; /* Whether we should zap all COWed (private) pages too */ @@ -1321,13 +1321,10 @@ static inline bool should_zap_cows(struct zap_details *details) return true; /* Or, we zap COWed pages only if the caller wants to */ - return !details->zap_mapping; + return details->even_cows; } -/* - * We set details->zap_mapping when we want to unmap shared but keep private - * pages. Return true if we should zap this page, false otherwise. - */ +/* Decides whether we should zap this page with the page pointer specified */ static inline bool should_zap_page(struct zap_details *details, struct page *page) { /* If we can make a decision without *page.. */ @@ -1338,7 +1335,8 @@ static inline bool should_zap_page(struct zap_details *details, struct page *pag if (!page) return true; - return details->zap_mapping == page_rmapping(page); + /* Otherwise we should only zap non-anon pages */ + return !PageAnon(page); } static unsigned long zap_pte_range(struct mmu_gather *tlb, @@ -3403,7 +3401,7 @@ void unmap_mapping_folio(struct folio *folio) first_index = folio->index; last_index = folio->index + folio_nr_pages(folio) - 1; - details.zap_mapping = mapping; + details.even_cows = false; details.single_folio = folio; i_mmap_lock_write(mapping); @@ -3432,7 +3430,7 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t first_index = start; pgoff_t last_index = start + nr - 1; - details.zap_mapping = even_cows ? NULL : mapping; + details.even_cows = even_cows; if (last_index < first_index) last_index = ULONG_MAX; -- 2.32.0