From mboxrd@z Thu Jan 1 00:00:00 1970 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 3CAF4C433FE for ; Tue, 8 Dec 2020 02:50:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC9E923976 for ; Tue, 8 Dec 2020 02:50:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC9E923976 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 627F58D0010; Mon, 7 Dec 2020 21:50:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AFDD8D0001; Mon, 7 Dec 2020 21:50:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47AF58D0010; Mon, 7 Dec 2020 21:50:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 2C6BB8D0001 for ; Mon, 7 Dec 2020 21:50:32 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E76471EE6 for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) X-FDA: 77568586662.20.berry51_0502511273e3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C2E2A180C0609 for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) X-HE-Tag: berry51_0502511273e3 X-Filterd-Recvd-Size: 6532 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 02:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607395830; 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=y3Z2K8nRRfGkaf6Txv+p5jeGljoBTJFR0t93dd3Zx9U=; b=OravxRtp7sJzKPslssZdgNiRssCvpkub//k0LRYGTozhFXM7QAC8PJiwo6nGpZ73DzrAMW A/AnaT5VgCWIe3YWpqXUZ9viacfuyII3AMueGs6CK/RrAQkadjPd1odeEDfFqTS8kY7tgw I63hyyDHDTygUXCm+st7K0l/XmlQiNE= 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-268-2fPEp6UEN0O54d6c1rjmEQ-1; Mon, 07 Dec 2020 21:50:29 -0500 X-MC-Unique: 2fPEp6UEN0O54d6c1rjmEQ-1 Received: by mail-qk1-f197.google.com with SMTP id q206so14246874qka.14 for ; Mon, 07 Dec 2020 18:50:29 -0800 (PST) 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=y3Z2K8nRRfGkaf6Txv+p5jeGljoBTJFR0t93dd3Zx9U=; b=iohFhze2/pm8nQIjcIa8c+J4zwrAkmsDQigPcejBBk0BWskgIMSU9bRR4xCsNQ4LdJ J+4ugyuPCCs1Mn/We90EmwH3emM745hn8khCTQzKJ4rELJ4f9ii9MB3xHAfCnoRjWFCR 7QE0p5lpboZVKqwZuJpOvNkjq+2lLWSAeH2DTqfk1dEQlpE1wfo6drI7+GKmLYsS+Ce4 6ujST/AQLT3egNZlxqxEZm5NEUcRLa/EsuzZfiFGyraVJgAW54sSkMVQemHbhK9yDFIl BQ+PWxGHLqKp5uIlZOozCmv2RFlShN2s8YFpDdzid08EqA2XGd7KYG4/1ySjV6lRUn82 Qrzw== X-Gm-Message-State: AOAM532+/76n54QmwQTAc8eat7WDoQvdPBvDKhypBZDxBQ0Vq/wCu+vB BaNpR6O2yRs/cN9d7NPfrsOW1AtSB28v2CWDKskNIFJNF079Zu4gvAbvtMnzMlzPuGpSASwsT5g n2s73QqU+LPI= X-Received: by 2002:a0c:c405:: with SMTP id r5mr16720984qvi.4.1607395828946; Mon, 07 Dec 2020 18:50:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHzUEslTZ1FZEWzJNu0W0qlP5gzOXXVxFImV3fi6ypeqsM2vcqg63+0O0dcsbZ71OFP2qwyQ== X-Received: by 2002:a0c:c405:: with SMTP id r5mr16720969qvi.4.1607395828714; Mon, 07 Dec 2020 18:50:28 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id a28sm2632766qtm.80.2020.12.07.18.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 18:50:28 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrea Arcangeli , peterx@redhat.com, "Kirill A . Shutemov" , Andrew Morton Subject: [PATCH 3/3] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Mon, 7 Dec 2020 21:50:22 -0500 Message-Id: <20201208025022.8234-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201208025022.8234-1-peterx@redhat.com> References: <20201208025022.8234-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 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable 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 a= gainst 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 detail= s pointer would mean to skip all swap entries. New user of zap_details cou= ld 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 swa= p entries could be errornously skipped without being noticed. This partly reverts 3e8715fdc03e ("mm: drop zap_details::check_swap_entri= es"), but introduce ZAP_FLAG_SKIP_SWAP flag, which means the opposite of previo= us "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 7ed4352ec84f..16631ee5eb9d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1622,6 +1622,8 @@ extern void user_shm_unlock(size_t, struct user_str= uct *); =20 /* 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) =20 /* * Parameter block passed down to zap_pte_range in exceptional cases. @@ -1644,6 +1646,16 @@ zap_check_mapping_skip(struct zap_details *details= , struct page *page) return details->zap_mapping !=3D page_rmapping(page); } =20 +/* 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 ad= dr, pte_t pte); struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned lon= g addr, diff --git a/mm/memory.c b/mm/memory.c index 20a8ba05c334..c9945f3c374d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1262,8 +1262,7 @@ static unsigned long zap_pte_range(struct mmu_gathe= r *tlb, continue; } =20 - /* If details->check_mapping, we leave swap entries. */ - if (unlikely(details)) + if (unlikely(zap_skip_swap(details))) continue; =20 if (!non_swap_entry(entry)) @@ -3159,7 +3158,10 @@ void unmap_mapping_pages(struct address_space *map= ping, pgoff_t start, pgoff_t nr, bool even_cows) { pgoff_t first_index =3D start, last_index =3D start + nr - 1; - struct zap_details details =3D { .zap_mapping =3D mapping }; + struct zap_details details =3D { + .zap_mapping =3D mapping, + .zap_flags =3D ZAP_FLAG_SKIP_SWAP, + }; =20 if (!even_cows) details.zap_flags |=3D ZAP_FLAG_CHECK_MAPPING; --=20 2.26.2