From patchwork Thu Sep 2 20:18:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12472441 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 1D156C433F5 for ; Thu, 2 Sep 2021 20:18:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C77F86113C for ; Thu, 2 Sep 2021 20:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C77F86113C 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 69FC3900002; Thu, 2 Sep 2021 16:18:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64FDC6B0075; Thu, 2 Sep 2021 16:18:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53E98900002; Thu, 2 Sep 2021 16:18:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 459B26B0073 for ; Thu, 2 Sep 2021 16:18:26 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1318C180AD5DA for ; Thu, 2 Sep 2021 20:18:26 +0000 (UTC) X-FDA: 78543745812.20.55E8754 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf23.hostedemail.com (Postfix) with ESMTP id A0AF390000A5 for ; Thu, 2 Sep 2021 20:18:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630613905; 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=qa2t+mRnex8UWtPa+3EibP8DEZqC9c+ivTe+/7D5DBg=; b=DSuVf5+oX2SIgqr11ovEu2Ar31WQRDdtWSdarlrVP5SkPx7Eipk9DcgNg893VubwbZo+u9 E0Ae2232qrnpAIUOE13hrvr3hhrEy0cJmo6irfc/TWja/R7Ppecu6axuOVlB5KKPA4Z+Ah VORPC1ROrsme9m7roPwfoPFi6bkTXH0= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-551-umolfnXkNRq5_RNWAd4tdQ-1; Thu, 02 Sep 2021 16:18:24 -0400 X-MC-Unique: umolfnXkNRq5_RNWAd4tdQ-1 Received: by mail-qt1-f197.google.com with SMTP id m6-20020ac807c6000000b0029994381c5fso2824582qth.5 for ; Thu, 02 Sep 2021 13:18:24 -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=qa2t+mRnex8UWtPa+3EibP8DEZqC9c+ivTe+/7D5DBg=; b=WZQzJnKPJus6khxaVz5sKO99Ow4FI9jjp6pf5EGLbx7mWSWKvHOYb6UMw99GkB2Bgo GlMWl9vxqbKIOcmpnpOKoebj/p9JwqIa7lzw/khTG8/jNAm7NWKeyRlvFjB2ecO6XQtw v+t7Ty5mBlG54b2/l+gtygl/FnxVlxI9ZQkSzIJA7LVdjBfT1kG03q41duukqdC1CXMo zbfwE6mA3f5IyG+BG1/xSFXdS67gtDdng2PMCjXHaeHlbr9urIyWpA3ITgbsEg1q2MVH XxI8ECw3I0tDbNVk9k2TANPTUk1NJ8Jqz65TfakSNzH2cyVOyKKa/gHOyrMggjoxAkzH dDPA== X-Gm-Message-State: AOAM532Cfk0JVbKTuSn2490ZZYzx/vYrVeE80p644PIgT6DvLN8jyKTY GppS8YnE16D2RPkZ9ljvjWAJLVH/LHXghFn+OXXK+7Puu0sO6bgTQK1F5Oib7FAqYGEes8wD+ON q+fQiB9pThpc= X-Received: by 2002:a05:620a:9dc:: with SMTP id y28mr4818036qky.456.1630613901841; Thu, 02 Sep 2021 13:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxSSUlX72Wtt37bFhaHAG9fsAucLiqInaoLBA2qPxUGl8ambA+3CiEsyV5pXsHgu6akQvj9g== X-Received: by 2002:a05:620a:9dc:: with SMTP id y28mr4818012qky.456.1630613901634; Thu, 02 Sep 2021 13:18:21 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id x29sm1677629qtv.74.2021.09.02.13.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 13:18:21 -0700 (PDT) From: Peter Xu To: Hugh Dickins , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: "Kirill A . Shutemov" , Jerome Glisse , peterx@redhat.com, Andrea Arcangeli , Miaohe Lin , Yang Shi , Matthew Wilcox , Alistair Popple , Mike Rapoport , David Hildenbrand Subject: [PATCH v2 4/5] mm: Add zap_skip_check_mapping() helper Date: Thu, 2 Sep 2021 16:18:19 -0400 Message-Id: <20210902201819.53343-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: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DSuVf5+o; spf=none (imf23.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-Stat-Signature: cgxb47i5aybtqd67n4xca76obawwoja1 X-Rspamd-Queue-Id: A0AF390000A5 X-Rspamd-Server: rspam04 X-HE-Tag: 1630613905-390979 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: Use the helper for the checks. Rename "check_mapping" into "zap_mapping" because "check_mapping" looks like a bool but in fact it stores the mapping itself. When it's set, we check the mapping (it must be non-NULL). When it's cleared we skip the check, which works like the old way. Move the duplicated comments to the helper too. Signed-off-by: Peter Xu --- include/linux/mm.h | 15 ++++++++++++++- mm/memory.c | 29 ++++++----------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 69259229f090..81e402a5fbc9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1720,10 +1720,23 @@ extern void user_shm_unlock(size_t, struct ucounts *); * Parameter block passed down to zap_pte_range in exceptional cases. */ struct zap_details { - struct address_space *check_mapping; /* Check page->mapping if set */ + struct address_space *zap_mapping; /* Check page->mapping if set */ struct page *single_page; /* Locked page to be unmapped */ }; +/* + * We set details->zap_mappings when we want to unmap shared but keep private + * pages. Return true if skip zapping this page, false otherwise. + */ +static inline bool +zap_skip_check_mapping(struct zap_details *details, struct page *page) +{ + if (!details || !page) + return false; + + return details->zap_mapping != page_rmapping(page); +} + 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 6bba3b9fef7c..e5ee8399d270 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1333,16 +1333,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, struct page *page; page = vm_normal_page(vma, addr, ptent); - if (unlikely(details) && page) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping && - details->check_mapping != page_rmapping(page)) - continue; - } + if (unlikely(zap_skip_check_mapping(details, page))) + continue; ptent = ptep_get_and_clear_full(mm, addr, pte, tlb->fullmm); tlb_remove_tlb_entry(tlb, pte, addr); @@ -1375,17 +1367,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, is_device_exclusive_entry(entry)) { struct page *page = pfn_swap_entry_to_page(entry); - if (unlikely(details && details->check_mapping)) { - /* - * unmap_shared_mapping_pages() wants to - * invalidate cache without truncating: - * unmap shared but keep private pages. - */ - if (details->check_mapping != - page_rmapping(page)) - continue; - } - + if (unlikely(zap_skip_check_mapping(details, page))) + continue; pte_clear_not_present_full(mm, addr, pte, tlb->fullmm); rss[mm_counter(page)]--; @@ -3368,7 +3351,7 @@ void unmap_mapping_page(struct page *page) first_index = page->index; last_index = page->index + thp_nr_pages(page) - 1; - details.check_mapping = mapping; + details.zap_mapping = mapping; details.single_page = page; i_mmap_lock_write(mapping); @@ -3396,7 +3379,7 @@ void unmap_mapping_pages(struct address_space *mapping, pgoff_t start, pgoff_t first_index = start, last_index = start + nr - 1; struct zap_details details = { }; - details.check_mapping = even_cows ? NULL : mapping; + details.zap_mapping = even_cows ? NULL : mapping; if (last_index < first_index) last_index = ULONG_MAX;