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,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 BCA3BC433E0 for ; Fri, 15 Jan 2021 17:09:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6D84C2333E for ; Fri, 15 Jan 2021 17:09:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D84C2333E 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 11A258D01A5; Fri, 15 Jan 2021 12:09:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0CC9D8D01A4; Fri, 15 Jan 2021 12:09:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0E8C8D01A5; Fri, 15 Jan 2021 12:09:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id C82098D01A4 for ; Fri, 15 Jan 2021 12:09:37 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 72A171818FCD3 for ; Fri, 15 Jan 2021 17:09:37 +0000 (UTC) X-FDA: 77708645994.17.fifth69_4105d4027531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 3E99818103F2A for ; Fri, 15 Jan 2021 17:09:37 +0000 (UTC) X-HE-Tag: fifth69_4105d4027531 X-Filterd-Recvd-Size: 6823 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 17:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730576; 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=zJk71zqOOD6fILHtrWgSqq8ioKD+WcJBLRfGm+Kflhs=; b=UBYtPL2O2mK8ODK1gWMvLIz0nybOPg4LlPdtGbquO9QD5e3PgCdc7f6Qt2H17ZUHwSQ8Jx NsirZ1hhvq0BunFlQT7OlEe4Y8XyVI83NttG/HxXOtrEVe/gTMAwNbaa9ovN8zezaFIiXs gNQmSlT7QkYN0oK+uEUxyi/4ki6uUXI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-XKfV1pzWMGi4C1e_XCEXjA-1; Fri, 15 Jan 2021 12:09:32 -0500 X-MC-Unique: XKfV1pzWMGi4C1e_XCEXjA-1 Received: by mail-qk1-f199.google.com with SMTP id 189so8626585qko.1 for ; Fri, 15 Jan 2021 09:09:32 -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=zJk71zqOOD6fILHtrWgSqq8ioKD+WcJBLRfGm+Kflhs=; b=W0NbDyBJjwf12d+jswLFT6Lx3cFWT19grxccAQy+M0Oh/mNiWApvujTVSdAou6RG/M GcQVrDMv2sRODDuLHN/A72yg5zM4/cshf2uPr2yUTEzGP8YvMuKvwPk2r0IX4k40h5ed nyjh67a7eVKqC8at9NngjisTC8S5GPZchioOT12aT5k6+mZ4FdD5iT2jQVogIUWIjcxE WWica+HRYXwImhCtOQSu7tzwHaLoKg33LRuH0VRez0c/1j4M6rkJ1jHaFbFVStIS41ib fvRoIk8Mk/L7npAoRVDRpwGWAF669/omv+GQ5+ZMLXN3CjSY5S6NpB9p4BNoxlkwN1RG Piyg== X-Gm-Message-State: AOAM5322yy5cMVLavxxXxBo4HYFndebjJkkGuUJr1LKHWJvi6UvgGdo/ oK9Ft5qyQ/IIHynvakIrRUAs/UZWKLIKO7egpIZsjMiZ0O33x2z//JisK4dbYMhLdwyfwFqMki/ NJLDHceE2iZ0= X-Received: by 2002:ad4:58c2:: with SMTP id dh2mr13333735qvb.4.1610730571897; Fri, 15 Jan 2021 09:09:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/ZGLVCHpITAQmxUytH5fcvrbscIS0jfSoJpLhoJN9VFYKioBq4OLm6JnuowYdUKczUKfJBw== X-Received: by 2002:ad4:58c2:: with SMTP id dh2mr13333709qvb.4.1610730571685; Fri, 15 Jan 2021 09:09:31 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d123sm5187840qke.95.2021.01.15.09.09.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:09:30 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport , Mike Kravetz , peterx@redhat.com, Jerome Glisse , "Kirill A . Shutemov" , Hugh Dickins , Axel Rasmussen , Matthew Wilcox , Andrew Morton , Andrea Arcangeli , Nadav Amit Subject: [PATCH RFC 11/30] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Fri, 15 Jan 2021 12:08:48 -0500 Message-Id: <20210115170907.24498-12-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115170907.24498-1-peterx@redhat.com> References: <20210115170907.24498-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 2380e1df6a49..0b1d04404275 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1632,6 +1632,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. @@ -1654,6 +1656,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 43d8641dbe18..873b2515e187 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1268,8 +1268,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)) @@ -3168,7 +3167,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