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.5 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 D9CC3C4707F for ; Thu, 27 May 2021 20:21:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7FC5661360 for ; Thu, 27 May 2021 20:21:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FC5661360 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 1A2F06B0074; Thu, 27 May 2021 16:21:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1790D6B0075; Thu, 27 May 2021 16:21:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 019B96B0078; Thu, 27 May 2021 16:21:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id BF2006B0074 for ; Thu, 27 May 2021 16:21:42 -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 5E22D181AF5C7 for ; Thu, 27 May 2021 20:21:42 +0000 (UTC) X-FDA: 78188131644.03.B7AFBBE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 0EC03E005F0D for ; Thu, 27 May 2021 20:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622146901; 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=tgZ4fuz9b2G4xHW7EB/zzIIXBN4xHF3mPH57XGKakgk=; b=UK1SKT3ejs9E3Bzk00tjoj1EH0StJ1hD+e/klfrInLSYskdgrpGB08C/HIBYPYAi7yrqOL 14z3cPil8YS56XJakTJQ8VWjS8/7svhGcmktopOnYRUq/0krxO7DnwBzZHJlsrQ8vBl5ga HKhJVrhCNdouhDtV1LFeVhifI9F2fyU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-146-Yh_kq4W4N-SOTLFT9DDBZg-1; Thu, 27 May 2021 16:21:40 -0400 X-MC-Unique: Yh_kq4W4N-SOTLFT9DDBZg-1 Received: by mail-qk1-f200.google.com with SMTP id e8-20020a05620a2088b02903a5edeec4d6so1323064qka.11 for ; Thu, 27 May 2021 13:21:40 -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=tgZ4fuz9b2G4xHW7EB/zzIIXBN4xHF3mPH57XGKakgk=; b=pCdbexw6kOUfLVHKdjBAlhlo5icpdTWieMiN/p960vn0l8jDiYy0MKOYTLrCXL0Tuk FiBGRAguP6kVV0fwTH8vCoK7StjHFfbFIWOva1OsQEPPI2m5D/aMF7oHf3RyX81Heuka 8KyQ0i8e/4uyfnNkkE4PjMMEwNNfLe8ye8aeuOY03rbtA2uOtUjk1RL2bjSZeLhQvfl3 RnjYXuszYaOBfFkQkdwUoz9dbYwZAyNvRl4bnFQG3SDxEjiSZ7EzW2DjjxlOYBa1QRaB BtnPrnIsyM1HQm9EwycEW4RwGvtbZm9MuUZIRdxD2xrRmHSjBw0Kcb/wlBnqB4oxWRJe KVPg== X-Gm-Message-State: AOAM533cNNbNb+5Sl7vGrGOSrMoeXmSvDuz1Namf2/WbDar/hxhxt40u wYxd6cRhmGFQrR62BMFEhyEnJUk5gJNOJgP2j3h649BGaWbW4tLqc/eQmOD63lDl+qaFURzepRu +EwqilTP8w9SPYcPpBOrCOdtmdsZSGKtnXIpxmhBfLs7aC1d0fDceIaDenOEk X-Received: by 2002:a37:a45:: with SMTP id 66mr355758qkk.138.1622146899140; Thu, 27 May 2021 13:21:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWc8f/UGUmyATH0FVxTT8Qc+Z0pWOiLKfvX0NL7phglOJRhpW7nCQYZyntRo/3ZjxrKn8Cbg== X-Received: by 2002:a37:a45:: with SMTP id 66mr355721qkk.138.1622146898781; Thu, 27 May 2021 13:21:38 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id a68sm2038889qkd.51.2021.05.27.13.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 13:21:38 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrea Arcangeli , "Kirill A . Shutemov" , Axel Rasmussen , Nadav Amit , Hugh Dickins , Jerome Glisse , Jason Gunthorpe , peterx@redhat.com, Andrew Morton , Miaohe Lin , Mike Rapoport , Matthew Wilcox , Mike Kravetz Subject: [PATCH v3 09/27] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Thu, 27 May 2021 16:21:35 -0400 Message-Id: <20210527202135.30890-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210527201927.29586-1-peterx@redhat.com> References: <20210527201927.29586-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" X-Rspamd-Queue-Id: 0EC03E005F0D Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UK1SKT3e; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf30.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Stat-Signature: woy16b3qeytp1gferbqpt1omma91hqkn X-HE-Tag: 1622146895-951187 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 52d3ef2ed753..1adf313a01fe 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1723,6 +1723,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. @@ -1745,6 +1747,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 c9dc4e9e05b5..8a3751be87ba 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1376,8 +1376,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)) @@ -3328,7 +3327,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.31.1