From patchwork Wed Jul 14 22:21:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12377955 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 D5BCDC47E4B for ; Wed, 14 Jul 2021 22:21:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88DB3613C5 for ; Wed, 14 Jul 2021 22:21:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88DB3613C5 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 4CEDB6B00B6; Wed, 14 Jul 2021 18:21:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 425326B00B7; Wed, 14 Jul 2021 18:21:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 057CF8D0003; Wed, 14 Jul 2021 18:21:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id A454F6B00B6 for ; Wed, 14 Jul 2021 18:21:40 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 979C4160AF for ; Wed, 14 Jul 2021 22:21:39 +0000 (UTC) X-FDA: 78362616318.30.7E0182F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 4864930001A1 for ; Wed, 14 Jul 2021 22:21:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626301298; 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=DnKyw7yDWXQofeLoBv2gn06czfrlb3UiiX/R37cvmsE=; b=Yb3mKJqumFFmNQvUL253S9DMdmhKMn14rUGB83ooosN/meVWiidXJryrOgeq19UzUi+mCf h+LCImI5ETWbpLIY0cjnzbc6GRF1aEjj99P49gyKoVy7kjvV9KmXQkH9RoF2DhC4qZ0sXP tszdyWt356L0w4JNlwwwTiRymDL2g68= 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-49-gzy_dZTRMjK4leikx6cj3Q-1; Wed, 14 Jul 2021 18:21:37 -0400 X-MC-Unique: gzy_dZTRMjK4leikx6cj3Q-1 Received: by mail-qk1-f200.google.com with SMTP id t144-20020a3746960000b02903ad9c5e94baso2290260qka.16 for ; Wed, 14 Jul 2021 15:21:37 -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=DnKyw7yDWXQofeLoBv2gn06czfrlb3UiiX/R37cvmsE=; b=Z8goZrdaWujO99oTjKaGSbbJoyzt8LbHxgJTJ/Lq0weacV+QwF3f0jJE8SLrxsF5gR yqGhHvGqzom5R2+ALIQ7EZfsf4L+4xt3mTX89Af0AGmVJoHYWZMrDpW379XhKehQJlym jWpDdLc19oM1sWx1W25lDSVe8Nv4voVySj9ZQJjF1EyeUj03K5xmMxlIe3cGnVf/OA/+ NKx8hhDV4FAZg2HUti/S64myr0coiWJWtytwvTJ1zjeK81zEt4Qhds4UOvKQv06WtRQb vxVewk669FqYCMHd6LTAeijn4ulCiypPkZhlSZU6qhVNgX/s6j6SYpvbelKIrauyExUE rq5w== X-Gm-Message-State: AOAM533zZugYnr6J709WBH9UWhSIJIEPUEyLY7xO4gDMzo0gRREwn75I DyaKiRrg6o27hDdoJrcsS3doLp0qRZyIWLVZX1FW1Xkz/d0yZsClmvNJ14rZLfMPuynuFw11Fc7 7hhKlw/bAF2w= X-Received: by 2002:ae9:e911:: with SMTP id x17mr189375qkf.371.1626301296700; Wed, 14 Jul 2021 15:21:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3A2Wvg6inICIbbeHBjb+ttmIrgQi5IfcXgb8Oye1uuRPIVOvrfqGI3ZbgjTSbv8g+Jmw2JA== X-Received: by 2002:ae9:e911:: with SMTP id x17mr189360qkf.371.1626301296471; Wed, 14 Jul 2021 15:21:36 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id b25sm1625854qka.123.2021.07.14.15.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 15:21:35 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Jason Gunthorpe , peterx@redhat.com, Matthew Wilcox , Andrew Morton , Axel Rasmussen , Nadav Amit , Jerome Glisse , Mike Rapoport , Miaohe Lin , Hugh Dickins , Alistair Popple , Andrea Arcangeli , Mike Kravetz , "Kirill A . Shutemov" , David Hildenbrand Subject: [PATCH v4 09/26] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Wed, 14 Jul 2021 18:21:00 -0400 Message-Id: <20210714222117.47648-10-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210714222117.47648-1-peterx@redhat.com> References: <20210714222117.47648-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4864930001A1 X-Stat-Signature: 94gczef5awrrjkdccqmbak95c8wdmx3a Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Yb3mKJqu; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf03.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1626301299-650341 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 26088174daab..62a75e4414e3 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1717,6 +1717,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. @@ -1740,6 +1742,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 2a5a6650f069..d6b1adbf29e4 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;