From patchwork Wed Sep 1 20:57:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12470323 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,URIBL_BLOCKED,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 9BD9BC43214 for ; Wed, 1 Sep 2021 20:57:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4BE9061027 for ; Wed, 1 Sep 2021 20:57:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4BE9061027 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EA13F900002; Wed, 1 Sep 2021 16:57:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E02EA940009; Wed, 1 Sep 2021 16:57:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7C7D900004; Wed, 1 Sep 2021 16:57:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id BB2BF900002 for ; Wed, 1 Sep 2021 16:57:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8324729E17 for ; Wed, 1 Sep 2021 20:57:31 +0000 (UTC) X-FDA: 78540215502.14.EE74A55 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 28FC750000A8 for ; Wed, 1 Sep 2021 20:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630529850; 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=pWrZC5R796B6AxPjLXJOHfEspvF6TQvhNiM+3hpUqTo=; b=jNuAztBmTiKaWlmyT9CavBq8w3xioiisRYhp3/WNKBPY2oF22Gd9qpLU4Bs2JdQUc4sYex fbE/Cpm9ChG3LpzqVFvO6ZXuIyHaqhLusPHeLOMcDwR69SoOWrELkUw68pKoCeN7YFlcNm HCStAbmIH1t7RIScOZ3ephJtK0pHaVY= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-253-DgkgPDblNzeO1Kfs_qxIuA-1; Wed, 01 Sep 2021 16:57:29 -0400 X-MC-Unique: DgkgPDblNzeO1Kfs_qxIuA-1 Received: by mail-qk1-f197.google.com with SMTP id e22-20020a05620a209600b003d5ff97bff7so871931qka.1 for ; Wed, 01 Sep 2021 13:57:29 -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=pWrZC5R796B6AxPjLXJOHfEspvF6TQvhNiM+3hpUqTo=; b=bqsCHFA74eYPQSU652AVYsMVMMFA/57wQLMEtYerFYSsQmQs3H1RrAtUAj+2UAsOPv 63xjudVMNDNvihQYR2w0nSnR5TnV8lCL+Dmpy3ooKdMr0J4gxSPDMuneHWePXONv8xyn vXuzGnNNxKsE+fhHJLgi+I9mMPiad6v1Fx+K22Y7Vf7ANQpu1+c2M6U5lLMkGCOl3mXH hRIa2/zhjP3h5bQ9DeO3AUHmsRvt/MdCdsKedcqhBRDyu4Yq2Tu90zoSYZG5i3+t5Vkc NibC/KStrr4s0GkG583pAsxxZrNc0bCa5S73LbwkdjT5jbi/uSWWj6HeQABhAq670pj2 18LQ== X-Gm-Message-State: AOAM53053uRSzqt7Q0GHpdCdyyVH+Jk6o7uAdq6rQ1Xzv6/lsWsgRSc4 6atlleF4EeGub4TUX0X9CEHKzwpcAr+QugezJzdE7ASCVI2WkFoJq+LY+xYZ4E5rZ77g0PpAnkk wIf9H7K8yNIA= X-Received: by 2002:a37:6c2:: with SMTP id 185mr1619298qkg.260.1630529849096; Wed, 01 Sep 2021 13:57:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAT0cwh0fiCuGBlVwkSIV+oBHm4p8ri9MOokNJ6Nf3K4EOtcbAo8KK7ymA6ffmkzusdLOapw== X-Received: by 2002:a37:6c2:: with SMTP id 185mr1619264qkg.260.1630529848869; Wed, 01 Sep 2021 13:57:28 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id h17sm562359qtu.68.2021.09.01.13.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 13:57:28 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Yang Shi , Miaohe Lin , Hugh Dickins , David Hildenbrand , peterx@redhat.com, Mike Rapoport , Andrea Arcangeli , "Kirill A . Shutemov" , Jerome Glisse , Alistair Popple Subject: [PATCH 5/5] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Wed, 1 Sep 2021 16:57:25 -0400 Message-Id: <20210901205725.7381-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901205622.6935-1-peterx@redhat.com> References: <20210901205622.6935-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jNuAztBm; spf=none (imf04.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 28FC750000A8 X-Stat-Signature: fiq7ugq71efqyeeqau3pq3tf61nj4ciw X-HE-Tag: 1630529850-535462 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 Reviewed-by: Alistair Popple 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 fcbc1c4f8e8e..f798f5e4baa5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1718,6 +1718,8 @@ extern void user_shm_unlock(size_t, struct ucounts *); /* 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. @@ -1741,6 +1743,16 @@ zap_skip_check_mapping(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 05ccacda4fe9..79957265afb4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1379,8 +1379,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)) @@ -3379,7 +3378,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;