From patchwork Thu Sep 2 20:18:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12472443 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 66D16C433F5 for ; Thu, 2 Sep 2021 20:18:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1333961131 for ; Thu, 2 Sep 2021 20:18:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1333961131 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B338E8D0001; Thu, 2 Sep 2021 16:18:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE48E6B0072; Thu, 2 Sep 2021 16:18:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D45E8D0001; Thu, 2 Sep 2021 16:18:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 8D69B6B0071 for ; Thu, 2 Sep 2021 16:18:41 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 50C652922E for ; Thu, 2 Sep 2021 20:18:41 +0000 (UTC) X-FDA: 78543746442.37.BF09298 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf19.hostedemail.com (Postfix) with ESMTP id E7394B000093 for ; Thu, 2 Sep 2021 20:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630613920; 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=TOAJdCsxdWRdNb0ovj0EkYvPsElPPpeSCrnOTkOMPhM=; b=eynOuJ1S0pLU1CHJ8Ll4IzlJgv1hHyi6gvrQ9ahWvdanBFGGRR+VYX0mZCwW6CzCKtMqtt 3IneTl8jgRUkAoTH65Rv9ouzr5oUFLOj8knHyRghqwKxk74qYUuDc0IvNNSyB7fbP37/Oh /q7kRrTVU7G+MQwYhxRERPh0/CTfQAk= 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-487-x3dnSdzFPYmh0XXPFmoWzQ-1; Thu, 02 Sep 2021 16:18:39 -0400 X-MC-Unique: x3dnSdzFPYmh0XXPFmoWzQ-1 Received: by mail-qk1-f200.google.com with SMTP id 70-20020a370b49000000b003d2f5f0dcc6so3490813qkl.9 for ; Thu, 02 Sep 2021 13:18:39 -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=TOAJdCsxdWRdNb0ovj0EkYvPsElPPpeSCrnOTkOMPhM=; b=eRiMMJOg4DzNxZW66sgWNeBZcun0xxQPFJL3A6/621NnxgjKNPHAD1vfWdy1B7jTcK vlf1y0GehbWprg9CK4cN+tMXxuAxh+hqPhklBTEnvo2rkl1JkJps4nmyvZpjDmrQn1pX t1cPg61DKa+tK8nHHfwdJEBj7HEb5XfLGn8R5Mjf5g/W79LJ22VC1uFhhyuD1zf2JUVx ZOBsoPG7ogOo2C4ZsLWYbNZNubnoBZfeebokTKDS5J44rFqOemcXQtjCUSx9woUBo/e+ QLckhQtUdTTome7b/pZejxGEzyCdGcC6Tw7V7NaqPuIfJ0D4cv96oZn1ybbngtX4CTd9 +TCQ== X-Gm-Message-State: AOAM530Ynr71wp77zDREAXRVRD8d/CLy7scKM90V+STonZ6CtLJ3syd8 mbS1wnnNIh7SEuKWeARrJTU8+ImthRVOKNReFAwaNPIPIHUaiE6VSndBEUVzrL1Yk6UPeWQArbU vW+f6UxkEFhCBpYg3++mrosAsoC407GCl+zJ1u7/oaq0z3bxhhTLMlXwej9/G X-Received: by 2002:ac8:6601:: with SMTP id c1mr143881qtp.179.1630613918644; Thu, 02 Sep 2021 13:18:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx++efQTIvasHbdh2PP0MzWi88Mh6mwdgtTP9JqFrJvmkxBs6mFuxVsRBJhqxz9qndbwxPGvg== X-Received: by 2002:ac8:6601:: with SMTP id c1mr143838qtp.179.1630613918342; Thu, 02 Sep 2021 13:18:38 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id c4sm2381805qkf.122.2021.09.02.13.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 13:18:37 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, Hugh Dickins , Andrew Morton , linux-kernel@vger.kernel.org Cc: Miaohe Lin , Matthew Wilcox , David Hildenbrand , Yang Shi , "Kirill A . Shutemov" , peterx@redhat.com, Jerome Glisse , Alistair Popple , Andrea Arcangeli , Mike Rapoport Subject: [PATCH v2 5/5] mm: Add ZAP_FLAG_SKIP_SWAP and zap_flags Date: Thu, 2 Sep 2021 16:18:36 -0400 Message-Id: <20210902201836.53605-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902201721.52796-1-peterx@redhat.com> References: <20210902201721.52796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eynOuJ1S; spf=none (imf19.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E7394B000093 X-Stat-Signature: ttgqjm9c1nfowq91ge3k5f55k6cpwis7 X-HE-Tag: 1630613920-860489 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. Actually very recently we introduced unmap_mapping_page() in 22061a1ffabd, I think that should also look into swap entries. Add a comment there. IOW, this patch will be a functional change to unmap_mapping_page() but hopefully in the right way to do it. 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 should still be the major case here). Cc: Kirill A. Shutemov Cc: Hugh Dickins Signed-off-by: Peter Xu --- include/linux/mm.h | 16 ++++++++++++++++ mm/memory.c | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 81e402a5fbc9..a7bcdb2ec956 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1716,12 +1716,18 @@ static inline bool can_do_mlock(void) { return false; } extern int user_shm_lock(size_t, struct ucounts *); extern void user_shm_unlock(size_t, struct ucounts *); +typedef unsigned int __bitwise zap_flags_t; + +/* Whether to skip zapping swap entries */ +#define ZAP_FLAG_SKIP_SWAP ((__force zap_flags_t) BIT(0)) + /* * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { struct address_space *zap_mapping; /* Check page->mapping if set */ struct page *single_page; /* Locked page to be unmapped */ + zap_flags_t zap_flags; /* Extra flags for zapping */ }; /* @@ -1737,6 +1743,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 e5ee8399d270..4cb269ca8249 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)) @@ -3351,6 +3350,7 @@ void unmap_mapping_page(struct page *page) first_index = page->index; last_index = page->index + thp_nr_pages(page) - 1; + /* Keep ZAP_FLAG_SKIP_SWAP cleared because we're truncating */ details.zap_mapping = mapping; details.single_page = page; @@ -3377,7 +3377,7 @@ 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 = { }; + struct zap_details details = { .zap_flags = ZAP_FLAG_SKIP_SWAP }; details.zap_mapping = even_cows ? NULL : mapping; if (last_index < first_index)