From patchwork Thu Oct 17 09:47:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13839731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AC85D21269 for ; Thu, 17 Oct 2024 09:48:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D5516B009B; Thu, 17 Oct 2024 05:48:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1867C6B009C; Thu, 17 Oct 2024 05:48:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 026A46B009D; Thu, 17 Oct 2024 05:48:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D6E146B009B for ; Thu, 17 Oct 2024 05:48:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BB921120EC4 for ; Thu, 17 Oct 2024 09:48:05 +0000 (UTC) X-FDA: 82682618466.28.281F0C0 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf19.hostedemail.com (Postfix) with ESMTP id B75AC1A0012 for ; Thu, 17 Oct 2024 09:48:01 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DQoB3fEo; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729158420; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Dj3ri9p71nmuCZf/HvkLHVU1fpbThKpmsfMSEQvNK9I=; b=L0aeIJZZJMerkfojuuwwwTn8funmzNwA3Jkken7qpVYkNQeCBmT3xZ+fauNw5onBXkdoYa A67MTXJtndR18ZpARvKd5yPVWfX2s5ObNXEqjNV442KDThZwKVRapjNXlRjCwpUqYw15ZE ag72os08OTgAZjQPb+hr7GeAeYqs1AM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DQoB3fEo; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729158420; a=rsa-sha256; cv=none; b=mIc+YJ65NiUkgTF97GlHxlOiWd2rfGSCaQ69dRsLc/UlgHQs87jquXpa7WjUrJ/zSuq9aF fqffgIeCm1MpMA2heidQSXmyLBrrsAFx0qUYVPw0Qw3HnC+ikI7rzy+N6h+ldT0JAvgy8D Mij75LwSCOAooKb02/37RJ6P9n3vu/A= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7e6ed072cdaso475855a12.0 for ; Thu, 17 Oct 2024 02:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729158492; x=1729763292; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dj3ri9p71nmuCZf/HvkLHVU1fpbThKpmsfMSEQvNK9I=; b=DQoB3fEoActmu+68iR00ELe5IObAwhnaSRTE1TOxowgAsiIH0FZ3j9DvbEtUjII3tk 9EuNrcwBwlZass8dIFJpF6sFOyGpg02oMa+6btv9/xR177ZUIxWC30aLv+2FBHUmH9pu oa1FYiLH/o7gb0zZsjTSz3hC98f5fZDIzCuEyRVLy0JRI3ykBRrU9ZKGwy9yOQvQWBiA w1q0LTyFVnIkYVKBNuPB93ZmifVP0RSTkDPEuuvBPK0f5fIpvOQm5LWbEzfzU6PuEYgj U50UIk8Tp0P5j8C+A99KDyqazC5Brsdgyxdlbooaba0YuIlqnbpsa6K0QEx+fNoCFHk2 GPhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158492; x=1729763292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dj3ri9p71nmuCZf/HvkLHVU1fpbThKpmsfMSEQvNK9I=; b=VVG2tJu2kC2szBlmnbB0FgafMqb39oTRrLdyAeHikpKWu+M7uSXtEQeW7JbuptTjPF uKfN0fteYTBH4e/2sxfVPReXbXaIZjMEsUK8bW1YyWyl2XWl0ZeUQw6XnI1gP0luIlPf iw96Y2RkX/g7TfYBkJb2QrkpzUT+YxzeE7K8kFsF1vbvth8E1SvxhiXFiiVjfE8GJkJ7 QQm6HewN4oHxfQScBbAJTDuwc6yWmfbPpou22940FNNcBTLf40gY/8XJpF/UjL6vxpwj TuFC7ol0iTr9xD584qfUUZ8yX18c0wrq8NfOd7bc578U5H0YnSSvLcXkQWG7GMwJU6c+ Ekzw== X-Gm-Message-State: AOJu0YwDCVgsQDf6lhXKFQSIre252Dp2h1IsD2uD6Cga9HiV0F1uyqQz ACR90T7dCYzvOUYKmfGNn3CJNUro2AU7j/Rb8WYZ0KQhmsAlUDQ/ZIxPlKRRg0I= X-Google-Smtp-Source: AGHT+IEKEDRwguwxshyZXMicxDUmcRCwiWXS2djsKDNBwB/wtcHqk2whV9zra/Oag0PCIfiHyKtsxQ== X-Received: by 2002:a05:6a20:9f4a:b0:1d5:1729:35ec with SMTP id adf61e73a8af0-1d8c955c8ebmr29391532637.7.1729158492598; Thu, 17 Oct 2024 02:48:12 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71e774a4218sm4385365b3a.120.2024.10.17.02.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:48:12 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, mgorman@suse.de, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, zokeefe@google.com, rientjes@google.com, jannh@google.com, peterx@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, Qi Zheng Subject: [PATCH v1 4/7] mm: zap_present_ptes: return whether the PTE page is unreclaimable Date: Thu, 17 Oct 2024 17:47:23 +0800 Message-Id: <84a9fddde9993e4a5108f188193fd9c8ff1c5c31.1729157502.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B75AC1A0012 X-Stat-Signature: toetfb44iaqt5iu5gm7iuugunhfeoh1c X-HE-Tag: 1729158481-405538 X-HE-Meta: U2FsdGVkX18cnOayXAc6QcLdid4Oc/1ynS5XH8WZ4MAI1tXsjAM9JVM5QJ8B6Sr8gm9FAETzKX9rg6smZ+VhPIEXrRADYdnJtTy3w/5VBL9LwUCnfv6dfuNTtVfK/sK7MBzI+OhHAKGhFfCV5f0RZF54Hwu87c2eXkbb9o6VaUHIFaPr7fQFX7KyylCWaNlqfaA1NJqtIW8PFhG+fwbRT3tIOPsH7mf7PaqLiFAs2dzR2+zPMWpsebTqzykHvm+meGXZaVU+YbdPN+Z+Lclqd7Gpi6aHph1DErKFc/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: 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: List-Subscribe: List-Unsubscribe: In the following two cases, the PTE page cannot be empty and cannot be reclaimed: 1. an uffd-wp pte was re-installed 2. should_zap_folio() return false Let's expose this information to the caller through is_pt_unreclaimable, so that subsequent commits can use this information in zap_pte_range() to detect whether the PTE page can be reclaimed. Signed-off-by: Qi Zheng --- mm/memory.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 534d9d52b5ebe..cc89ede8ce2ab 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1501,7 +1501,7 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb, struct vm_area_struct *vma, struct folio *folio, struct page *page, pte_t *pte, pte_t ptent, unsigned int nr, unsigned long addr, struct zap_details *details, int *rss, - bool *force_flush, bool *force_break) + bool *force_flush, bool *force_break, bool *is_pt_unreclaimable) { struct mm_struct *mm = tlb->mm; bool delay_rmap = false; @@ -1527,8 +1527,8 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb, arch_check_zapped_pte(vma, ptent); tlb_remove_tlb_entries(tlb, pte, nr, addr); if (unlikely(userfaultfd_pte_wp(vma, ptent))) - zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, - ptent); + *is_pt_unreclaimable = + zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, ptent); if (!delay_rmap) { folio_remove_rmap_ptes(folio, page, nr, vma); @@ -1552,7 +1552,7 @@ static inline int zap_present_ptes(struct mmu_gather *tlb, struct vm_area_struct *vma, pte_t *pte, pte_t ptent, unsigned int max_nr, unsigned long addr, struct zap_details *details, int *rss, bool *force_flush, - bool *force_break) + bool *force_break, bool *is_pt_unreclaimable) { const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; struct mm_struct *mm = tlb->mm; @@ -1567,15 +1567,18 @@ static inline int zap_present_ptes(struct mmu_gather *tlb, arch_check_zapped_pte(vma, ptent); tlb_remove_tlb_entry(tlb, pte, addr); if (userfaultfd_pte_wp(vma, ptent)) - zap_install_uffd_wp_if_needed(vma, addr, pte, 1, - details, ptent); + *is_pt_unreclaimable = + zap_install_uffd_wp_if_needed(vma, addr, pte, 1, + details, ptent); ksm_might_unmap_zero_page(mm, ptent); return 1; } folio = page_folio(page); - if (unlikely(!should_zap_folio(details, folio))) + if (unlikely(!should_zap_folio(details, folio))) { + *is_pt_unreclaimable = true; return 1; + } /* * Make sure that the common "small folio" case is as fast as possible @@ -1587,11 +1590,12 @@ static inline int zap_present_ptes(struct mmu_gather *tlb, zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, nr, addr, details, rss, force_flush, - force_break); + force_break, is_pt_unreclaimable); return nr; } zap_present_folio_ptes(tlb, vma, folio, page, pte, ptent, 1, addr, - details, rss, force_flush, force_break); + details, rss, force_flush, force_break, + is_pt_unreclaimable); return 1; } @@ -1622,6 +1626,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, pte_t ptent = ptep_get(pte); struct folio *folio; struct page *page; + bool is_pt_unreclaimable = false; int max_nr; nr = 1; @@ -1635,7 +1640,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, max_nr = (end - addr) / PAGE_SIZE; nr = zap_present_ptes(tlb, vma, pte, ptent, max_nr, addr, details, rss, &force_flush, - &force_break); + &force_break, &is_pt_unreclaimable); if (unlikely(force_break)) { addr += nr * PAGE_SIZE; break;