From patchwork Tue Apr 27 16:13:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12226881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80471C433ED for ; Tue, 27 Apr 2021 16:13:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09B5D613E8 for ; Tue, 27 Apr 2021 16:13:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09B5D613E8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A5BAE6B0078; Tue, 27 Apr 2021 12:13:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A32386B007B; Tue, 27 Apr 2021 12:13:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85EFF6B007E; Tue, 27 Apr 2021 12:13:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 575A46B0078 for ; Tue, 27 Apr 2021 12:13:41 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8FE258249980 for ; Tue, 27 Apr 2021 16:13:39 +0000 (UTC) X-FDA: 78078642558.32.9C97911 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 70BE1E00012F for ; Tue, 27 Apr 2021 16:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619540018; 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=79hgS/3VF19uL8B1KnbV12ieWH4dDf98xJSUkbEku0E=; b=QWiyHIpQeU9yUDtlnPOQLS6smhXN6QzTOyZtpgBIEt39m3cKw9G+C9Crk5BeUi1K/GvWEP e6unBfNeJzeGKx0X0jlqUvhlT/t9yaJ+EopM1eUrPVsKXRCaOXLXqCZJ6myYvRJB1TniH3 08x6+mr00L7XlFUmVvp7Ugs/qslaqCc= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-238-2NesJNj5OviC8soMrO_G3Q-1; Tue, 27 Apr 2021 12:13:35 -0400 X-MC-Unique: 2NesJNj5OviC8soMrO_G3Q-1 Received: by mail-qv1-f70.google.com with SMTP id r18-20020a0ccc120000b02901a21aadacfcso24128738qvk.5 for ; Tue, 27 Apr 2021 09:13:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=79hgS/3VF19uL8B1KnbV12ieWH4dDf98xJSUkbEku0E=; b=DEeHc2p0ep91/hOFuw1JEwnXZAqjyMcRovBwj15aK5T8e5OOGYdxOW3g55Nspk/GJ4 Y0OTTvns/UVVtktH+Mhn72qBpn6nA2dVJas15uTf/f+/1uy9s0CqzcFZ5XIZyh91MFNB TKiuNrzzEWBGlZc504jUxMjyVMsgIbN3axgoak0qyogTqtbVnuhY+DTF+ts/xG7E35gV Cn/HKw/5jgT4RVOf3j1jybvyRAA08a9CVP2FAq2cdv84Ditu9TBh1+XQsALNaI2jQ13o Olrmeuf2vynP2z4TgpFUPx5pYt5s0nny5nYFMKVCIWJUbn42Q2/o/eVENmbAAq0w8URT CFKA== X-Gm-Message-State: AOAM531HZe8I1zekwinWL7zekQJTMwvRqHjanxTyEc0jw2N13hRFSGvp Z50umSo7lNUPIySoQwHc83CDXPaKiAc94Au/pbmbNrtEmXo2ULiMUS9agi8tazK1W7h1fQQ6UBa PZQZKv7qfjdSUF620VKz/90fDjWigKrUqk3YGUhFCmEErhTqSD0a7+v5lQVf4 X-Received: by 2002:a0c:ab12:: with SMTP id h18mr11741098qvb.33.1619540013536; Tue, 27 Apr 2021 09:13:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuSIgswcmVwkMNc/apUchEgjfSAXm6CbKvjAhSKPYH54HMTCmY99nS8hMUF9WgKkHBYwHOQw== X-Received: by 2002:a0c:ab12:: with SMTP id h18mr11741039qvb.33.1619540013117; Tue, 27 Apr 2021 09:13:33 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id v66sm3103621qkd.113.2021.04.27.09.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 09:13:32 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Miaohe Lin , Mike Rapoport , Andrea Arcangeli , Hugh Dickins , peterx@redhat.com, Jerome Glisse , Mike Kravetz , Jason Gunthorpe , Matthew Wilcox , Andrew Morton , Axel Rasmussen , "Kirill A . Shutemov" Subject: [PATCH v2 07/24] mm: Introduce zap_details.zap_flags Date: Tue, 27 Apr 2021 12:13:00 -0400 Message-Id: <20210427161317.50682-8-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210427161317.50682-1-peterx@redhat.com> References: <20210427161317.50682-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 70BE1E00012F X-Stat-Signature: dkbt9dj3zctgfx8fif6rxhh4ea6wbt3u X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619540011-502515 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: Instead of trying to introduce one variable for every new zap_details fields, let's introduce a flag so that it can start to encode true/false informations. Let's start to use this flag first to clean up the only check_mapping variable. Firstly, the name "check_mapping" implies this is a "boolean", but actually it stores the mapping inside, just in a way that it won't be set if we don't want to check the mapping. To make things clearer, introduce the 1st zap flag ZAP_FLAG_CHECK_MAPPING, so that we only check against the mapping if this bit set. At the same time, we can rename check_mapping into zap_mapping and set it always. Since at it, introduce another helper zap_check_mapping_skip() and use it in zap_pte_range() properly. Some old comments have been removed in zap_pte_range() because they're duplicated, and since now we're with ZAP_FLAG_CHECK_MAPPING flag, it'll be very easy to grep this information by simply grepping the flag. It'll also make life easier when we want to e.g. pass in zap_flags into the callers like unmap_mapping_pages() (instead of adding new booleans besides the even_cows parameter). Signed-off-by: Peter Xu --- include/linux/mm.h | 19 ++++++++++++++++++- mm/memory.c | 31 ++++++++----------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9060b497f4d5c..39c944bf7ed3a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1702,13 +1702,30 @@ static inline bool can_do_mlock(void) { return false; } extern int user_shm_lock(size_t, struct user_struct *); extern void user_shm_unlock(size_t, struct user_struct *); +/* Whether to check page->mapping when zapping */ +#define ZAP_FLAG_CHECK_MAPPING BIT(0) + /* * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { - struct address_space *check_mapping; /* Check page->mapping if set */ + struct address_space *zap_mapping; + unsigned long zap_flags; }; +/* Return true if skip zapping this page, false otherwise */ +static inline bool +zap_check_mapping_skip(struct zap_details *details, struct page *page) +{ + if (!details || !page) + return false; + + if (!(details->zap_flags & ZAP_FLAG_CHECK_MAPPING)) + return false; + + return details->zap_mapping != page_rmapping(page); +} + struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr, pte_t pte); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr, diff --git a/mm/memory.c b/mm/memory.c index bcbce803e6850..94954436544f7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1242,16 +1242,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, struct page *page; page = vm_normal_page(vma, addr, ptent); - if (unlikely(details) && page) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping && - details->check_mapping != page_rmapping(page)) - continue; - } + if (unlikely(zap_check_mapping_skip(details, page))) + continue; ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); tlb_remove_tlb_entry(tlb, pte, addr); @@ -1283,17 +1275,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (is_device_private_entry(entry)) { struct page *page = device_private_entry_to_page(entry); - if (unlikely(details && details->check_mapping)) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping != - page_rmapping(page)) - continue; - } - + if (unlikely(zap_check_mapping_skip(details, page))) + continue; pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); rss[mm_counter(page)]--; page_remove_rmap(page, false); @@ -3253,9 +3236,11 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t nr, bool even_cows) { pgoff_t first_index = start, last_index = start + nr - 1; - struct zap_details details = { }; + struct zap_details details = { .zap_mapping = mapping }; + + if (!even_cows) + details.zap_flags |= ZAP_FLAG_CHECK_MAPPING; - details.check_mapping = even_cows ? NULL : mapping; if (last_index < first_index) last_index = ULONG_MAX;