From patchwork Tue Mar 23 00:48:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12156491 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 7F67CC433C1 for ; Tue, 23 Mar 2021 00:49:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 009D16196C for ; Tue, 23 Mar 2021 00:49:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 009D16196C 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 8645E6B0124; Mon, 22 Mar 2021 20:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C6D06B0125; Mon, 22 Mar 2021 20:49:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CBC66B0127; Mon, 22 Mar 2021 20:49:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 27C466B0125 for ; Mon, 22 Mar 2021 20:49:31 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D7E44180226ED for ; Tue, 23 Mar 2021 00:49:30 +0000 (UTC) X-FDA: 77949305700.03.A9965A9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf06.hostedemail.com (Postfix) with ESMTP id ED255C0007CA for ; Tue, 23 Mar 2021 00:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616460569; 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=t66g/F9+6bLvOsk6XEcPT7bVSiazBzgvig/355lAXQE=; b=fazX2JDx6zjlqrJNQmADyFAJxboycQAnfAUgs3Cx5lW0BynMTchcub5VH4z5XezL4bQwvf yfAz0qWWXf+7jRb8pPmfaWxh3/eeynAaJRR/T78wGv970tUnTSpz7di+Cns8LSaZwAYGvQ wGCt0oo0zKr7fqhBm8Xig4qBvRNmVZ8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-w0aEHrBXOLiwUnaEsz6zJw-1; Mon, 22 Mar 2021 20:49:28 -0400 X-MC-Unique: w0aEHrBXOLiwUnaEsz6zJw-1 Received: by mail-qt1-f200.google.com with SMTP id d11so413529qth.3 for ; Mon, 22 Mar 2021 17:49:28 -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=t66g/F9+6bLvOsk6XEcPT7bVSiazBzgvig/355lAXQE=; b=FRGSfQy7zUlcIRJEOO7xTW8s2ihNbixU/O4/tJZH7/3YFR8s3WDf27xenoxAtHjb6P 169OFyGByrWB2OQidSRLphgbwSiuwdTUYo3N/5pkinvs2Ss4npgW5iKx2GUmoLLcAyaY mzwKf4v+605Z5VvBPLBf3GFtpVM6f4EQoL6e9qPch4lcBrEkxCevgg6Tk/0ffKVpjm1l TuROgmA0BUkPztQ/r/z/nbAXorSkaho/MfQBOK3u6oOMydEsn8W7tFEkipgb6+NaMkNF uFE+2uezVqukmCKq+wVE3ajj5lzIyBmpmkL1jeD+0prsr/OYjvxOTNCwfFJbw1jHu22i FjvQ== X-Gm-Message-State: AOAM5331jFch8lfuourkVoqSOwEauIC75Rns6J0xpsP90wG7jd64cekH LA9pFQJGxvTioH8f1ZeMOveQLh41+n2vpgEERvyZzeGri8f34hV4koZ828dGHI2jV7AAaOU4UgO hjE7ENvBu7gY= X-Received: by 2002:ac8:520d:: with SMTP id r13mr2445788qtn.38.1616460567842; Mon, 22 Mar 2021 17:49:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQ3OkZpVOpbW4WMpnPVKmwjNCxNhfbWMLukWj6w5MQB4ZMF7sL7y6kqxbDNBAVeG3FmEY40Q== X-Received: by 2002:ac8:520d:: with SMTP id r13mr2445775qtn.38.1616460567535; Mon, 22 Mar 2021 17:49:27 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-82-174-91-135-175.dsl.bell.ca. [174.91.135.175]) by smtp.gmail.com with ESMTPSA id n6sm5031793qtx.22.2021.03.22.17.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 17:49:26 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Kirill A . Shutemov" , Jerome Glisse , Mike Kravetz , Matthew Wilcox , Andrew Morton , Axel Rasmussen , Hugh Dickins , peterx@redhat.com, Nadav Amit , Andrea Arcangeli , Mike Rapoport Subject: [PATCH 08/23] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Mon, 22 Mar 2021 20:48:57 -0400 Message-Id: <20210323004912.35132-9-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210323004912.35132-1-peterx@redhat.com> References: <20210323004912.35132-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-Stat-Signature: 456djc51juten4yfn5gytkz3x19ng8pu X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: ED255C0007CA Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616460569-128890 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: Firstly, the comment in zap_pte_range() is misleading because it checks against details rather than check_mappings, so it's against what the code did. Meanwhile, it's confusing too on not explaining why passing in the details pointer would mean to skip all swap entries. New user of zap_details could very possibly miss this fact if they don't read deep until zap_pte_range() because there's no comment at zap_details talking about it at all, so swap entries could be errornously skipped without being noticed. This partly reverts 3e8715fdc03e ("mm: drop zap_details::check_swap_entries"), but introduce ZAP_FLAG_SKIP_SWAP flag, which means the opposite of previous "details" parameter: the caller should explicitly set this to skip swap entries, otherwise swap entries will always be considered (which is still the major case here). Cc: Kirill A. Shutemov Signed-off-by: Peter Xu --- include/linux/mm.h | 12 ++++++++++++ mm/memory.c | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index bb513a346beb..c11fbce0d557 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1704,6 +1704,8 @@ extern void user_shm_unlock(size_t, struct user_struct *); /* Whether to check page->mapping when zapping */ #define ZAP_FLAG_CHECK_MAPPING BIT(0) +/* Whether to skip zapping swap entries */ +#define ZAP_FLAG_SKIP_SWAP BIT(1) /* * Parameter block passed down to zap_pte_range in exceptional cases. @@ -1726,6 +1728,16 @@ zap_check_mapping_skip(struct zap_details *details, struct page *page) return details->zap_mapping != page_rmapping(page); } +/* Return true if skip swap entries, false otherwise */ +static inline bool +zap_skip_swap(struct zap_details *details) +{ + if (!details) + return false; + + return details->zap_flags & ZAP_FLAG_SKIP_SWAP; +} + 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 2e540b315481..a02c4d851cd4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1284,8 +1284,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, continue; } - /* If details->check_mapping, we leave swap entries. */ - if (unlikely(details)) + if (unlikely(zap_skip_swap(details))) continue; if (!non_swap_entry(entry)) @@ -3225,7 +3224,10 @@ 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 = { .zap_mapping = mapping }; + struct zap_details details = { + .zap_mapping = mapping, + .zap_flags = ZAP_FLAG_SKIP_SWAP, + }; if (!even_cows) details.zap_flags |= ZAP_FLAG_CHECK_MAPPING;