From patchwork Thu Jul 15 20:14:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12380941 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 DFE7BC636CA for ; Thu, 15 Jul 2021 20:14:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 89C6D613BB for ; Thu, 15 Jul 2021 20:14:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89C6D613BB 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 A7AD88D0106; Thu, 15 Jul 2021 16:14:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A53E78D00EC; Thu, 15 Jul 2021 16:14:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 857878D0106; Thu, 15 Jul 2021 16:14:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 659C38D00EC for ; Thu, 15 Jul 2021 16:14:47 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 47B1726DF6 for ; Thu, 15 Jul 2021 20:14:46 +0000 (UTC) X-FDA: 78365925372.23.246256E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id ED8FC300018B for ; Thu, 15 Jul 2021 20:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626380085; 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=A0wmBb+iBLmLelB7/ZbSyznDkHRfOIQfLeof4K2KV8Po2PHBAXd7ynL9Q0A+iuVheT5tsj qov0Cc3eG2aPEvBRSQ1QEq4y/OvuiN4Nj4dNVG6djsS8VATtFcCtaPbAVW2fKNP/rHp1CE sWYiaEZpp1/QLdE7Um606/7w9AD6M5s= 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-392-f5IUesPMMP-62ty3TcIEXg-1; Thu, 15 Jul 2021 16:14:44 -0400 X-MC-Unique: f5IUesPMMP-62ty3TcIEXg-1 Received: by mail-qk1-f199.google.com with SMTP id r190-20020a375dc70000b02903acea04c19fso4690319qkb.8 for ; Thu, 15 Jul 2021 13:14:44 -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=M1nasYCq90774Z3p+Ba0dNvPy0WrbV6D7C1prDj9XP+s009zcR0Y8Sr0S8OrGvI8ci D9JRdL8VxHybMkjkTDYVVGWw9I01EIaa2ck7y2grqoCv+jJNXh1jk1MM8S07MJ4c1vOv fJ2WM7qpUxPXFOkx+86lq/02eg0TF361j5QyPJa/1+y0vKU5b/HVgVxQ+AAl1Esr22D9 9uJTK2d2q6iuUjPogVEj7qnLa1rhCqs4P1UjQgRjGpRA/yYqyVt24HpJkr8ADwza+RVZ NQQ1GQhMxXgOfboPXGAYO5JZhyUgnxvscpVJl32RKrPjs3QFWck+XjgGKDtqGwalybck a9RQ== X-Gm-Message-State: AOAM530HlAFiiDQyEHtjnPSuZVmCJVm9FQBR/4IDFwpye47+V5XOiJcw A/cyLxWM1t5fKGGvKjV4Gyovf9+Y2Dgv3za29t4Z9UF4OZl26rLmUFySL4hdfzWn045CabDbFDK nXY9EUhJthX6hN7dcRoQGLd82GepZ2KwlVxw3Fedum1gdMRkRaT0TiFGGJasD X-Received: by 2002:ac8:7e82:: with SMTP id w2mr5685692qtj.224.1626380083685; Thu, 15 Jul 2021 13:14:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmWCnHPdO+ZKQ8xVoo7D6usAgQbxNiauGFsJ1ILQyT59bSS4zu7gt2/U/wvfy323F7yD1UAQ== X-Received: by 2002:ac8:7e82:: with SMTP id w2mr5685646qtj.224.1626380083343; Thu, 15 Jul 2021 13:14:43 -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 p64sm2915206qka.114.2021.07.15.13.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 13:14:42 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jason Gunthorpe , Mike Kravetz , David Hildenbrand , Alistair Popple , Matthew Wilcox , "Kirill A . Shutemov" , Hugh Dickins , Tiberiu Georgescu , Andrea Arcangeli , Axel Rasmussen , Nadav Amit , Mike Rapoport , Jerome Glisse , Andrew Morton , Miaohe Lin , peterx@redhat.com Subject: [PATCH v5 09/26] mm: Introduce ZAP_FLAG_SKIP_SWAP Date: Thu, 15 Jul 2021 16:14:05 -0400 Message-Id: <20210715201422.211004-10-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715201422.211004-1-peterx@redhat.com> References: <20210715201422.211004-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A0wmBb+i; spf=none (imf03.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam02 X-Stat-Signature: 5p66sn3m6h3qpnqfckt94moas8yyjbgr X-Rspamd-Queue-Id: ED8FC300018B X-HE-Tag: 1626380085-89252 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;