From patchwork Wed Dec 4 11:09:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13893588 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 CB435E7716B for ; Wed, 4 Dec 2024 11:11:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E2E06B009D; Wed, 4 Dec 2024 06:11:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 592C96B009E; Wed, 4 Dec 2024 06:11:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45AE46B009F; Wed, 4 Dec 2024 06:11:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 285B16B009D for ; Wed, 4 Dec 2024 06:11:16 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9B206160F6C for ; Wed, 4 Dec 2024 11:11:15 +0000 (UTC) X-FDA: 82857009270.09.6596B2A Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 3F64220014 for ; Wed, 4 Dec 2024 11:11:07 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eSckiQpO; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 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=1733310659; 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=/4hB6V6uA9TX2vZoO0lHgFVoZw/iaOacAaPzNOaZz/w=; b=Fg3yNHLl4MZelAChyUaf5dKODEesXDz/j7Wcj2XcAWYsGuNcsNnYq+PblSe0mCaRPkFk2M 6YmL9CsJbb+ANS1vTrXnfYl/dvixkvVqn8Y+I6Lmgi9ePipjHj3LJIuO6hhWMEMxwcrDKn TumoIsD96MJ6w+9tbEX599Y1pTpFGOE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733310659; a=rsa-sha256; cv=none; b=wVeOnDkUpJF0xL1rl49lFcdpdechdo62YiC9Y7fTkzSVRGbdy3w+vw8cAlIh9F5Hy4vedV hJkfmEyFqpOFwKBE7p/PV7wdyai17qOWzFq6bCqA6ogSBHYEnyKkea8CRLR9AiQtUljG5w LRPc2NnJUJAWeN+Cp1eNk9Urk4K5rs4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=eSckiQpO; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21578cfad81so30814185ad.3 for ; Wed, 04 Dec 2024 03:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1733310672; x=1733915472; 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=/4hB6V6uA9TX2vZoO0lHgFVoZw/iaOacAaPzNOaZz/w=; b=eSckiQpORkd51XwN0MxdPfeiegXu5t+Gtyz/8pR3DYu6XqQXUNwEYj9OBlWuqZHVw5 i92TnydsnLyYEm7mbRI72fmlIFIcb6DVCEyqyRSqrwc6kvivLMJZLMT7pQ4tOFSqRit0 Hghmkf379ru5nlf1v+PSqYzKEFWy5O+WM5P+NWoyrs3OXmmWz7fGGF7EGqc2UzdQbI7j kp13mPVHBz/vKlcU67FxSfH1UjApMAzINEKpvjVoG2Qezy3Ef5oAZEzIKoqUUL1wJEER 2u2iKxoWLlKlevnk+9ydJZrjCP1O4g3jFN/BsDiiOjIf3c+ORKCQbHdlW4ZYXVM24lMV 6KSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733310672; x=1733915472; 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=/4hB6V6uA9TX2vZoO0lHgFVoZw/iaOacAaPzNOaZz/w=; b=wJFDPO9nCPFhi13seqRxegkkWM4h+Re26RXQWeKSG79Edzf+QMVdFsyX3o/CqJBJ3b qjND7BHGZlW1w0viw16/mYNzsfjYFpXLyAD0mYQ6r3OfdUf8YaWMzOgSCUabiXOTGTu0 4nBkXHMkEHvpyxF/SCal62lnxiwckrao5FM9YjdAYsE78/TbiqOR5BuRUJRmUJM/D/jW FDzfk/4yC23MlJsc5AeaWyfZ4rw1dLb3bAVST5SNf+1gOojcr+7RJ8oTbCcjgDjZ7cXs P0AAuhivvVPJDzEMKjeVNtZJ8CPhy4f0+Zfb4d1NX+lVvCwIqt63ylza7lb3G0lBO5ZC WAtQ== X-Forwarded-Encrypted: i=1; AJvYcCX3vRuAhmIe67M0rf9l3gX3sJJlwjPisql7veYN/MFADiKCvbXxHglEg7RMpXe1MNdaKwbz38w8xQ==@kvack.org X-Gm-Message-State: AOJu0Ywjm1FGbLq+BSMBUZK+2A34dwmAwMZNt00w2LwaYBxmqZUHG78t R4cA4SkuY5R+7j226jQahP9BvVz1cV2sqa4/gAmDWGkuhgwBiQh3qrzWxsaKqlc= X-Gm-Gg: ASbGnctHNUNM4Z9DQJ5mwnt/6ujvYI6EpTFlu35Ht7kqAKNqcVYsFg8sgWffG05/aOg Zd4Q5MHb9yI6i667jC2EoF8XnjnP2U4Ys2EiVLfGbmHGSMNtRsa4f1r87WAX+sCAcsMWKB0/eJe 9xr784O84VdI2Uua17v9if9q1iE7KsqjMfPt2oXmQTH+HkCXGiAwbn/nZAme85f/vCT/vg5ZXYk BrwPNIz73auUngsCXf5UT0XGMfb4V+XO/1/v5cQGjiSFTikfUA3zLwAEs3WNJFoVgIQSNfMzNhg qkD1D8XwVS/vhsE= X-Google-Smtp-Source: AGHT+IHVmRnYQumB1wXhU3np0xfxzAbGYvF0A99UdzOBbPzf6Gm/CK0T1MxPbJQR0FQZPPyKoGad2Q== X-Received: by 2002:a17:902:ce0c:b0:211:6b21:73d9 with SMTP id d9443c01a7336-215bd24146cmr87777885ad.37.1733310672514; Wed, 04 Dec 2024 03:11:12 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.148]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21527515731sm107447495ad.192.2024.12.04.03.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Dec 2024 03:11:11 -0800 (PST) From: Qi Zheng To: david@redhat.com, jannh@google.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, peterx@redhat.com, akpm@linux-foundation.org Cc: mgorman@suse.de, catalin.marinas@arm.com, will@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, x86@kernel.org, lorenzo.stoakes@oracle.com, zokeefe@google.com, rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH v4 07/11] mm: do_zap_pte_range: return any_skipped information to the caller Date: Wed, 4 Dec 2024 19:09:47 +0800 Message-Id: <59f33ec9f74e9f058ed319b0bfadd76b0f7adf9b.1733305182.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-Queue-Id: 3F64220014 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 5ejphas8z65xuyki7c3nnipjuw4auyf1 X-HE-Tag: 1733310667-330395 X-HE-Meta: U2FsdGVkX1+oH1ERhRYdd3EX5vp2DQ/kXKnDcWn60ExvamqRI408N5PBDry6ehB/tbf9REEdPpmA3Dziy66FgKK5/FYNYn65FaNZMBm7cRWNyOfNZqMEdkjNN2Bm7WZsSz3U4/UiACy2n+gML3jrfdmxPRMub3g2IneFXJp5/eZBcf6jvXuqJn/26WipIRHUSxljZRbNGZ1YpbQRKvORzvzJi7FVzQg2+UBbCLU0tNVNJZ2b+kpi4n8az5WRYDLsoITnTea03K568yvqRNpIoexSqNuqZXM3FeOra7JHi3C8pUK0rKFKkOP/eM+BaQyxeHqsEFJE91or/qoOB8PGfbU4GNRojUYCQdqzHsAw31VG2kxR5aAalgsePkFPidklRoBdwBYbeuW2wE6SHZlD8Jt7NzuF1AtuvoinDJKE3kTLTo5c39iQBatC5qVW8EZII4ojOjwAc/mwPpg4MTRftlytVtOjr10uksgNbD+/zi+rJQIStEpp2QNN4h3SDJy6RMxihbHE57lyposw1ysa6Y3sFyiSHBRawoRztr0X570aqyIhB+GjFpfB/Asp+UamWECM/5Ju0VvlZn33bDkNmo/NwOBp8GVLofU+mUl6SZOddyP+INBziK0qq5QSCZCV6FsPJ0JyvZ9pdGag8U+4ihT+HD1VaAyBK63ZhIb7U0uWImFuR/OQ4usmzvNcyRibE5V6sIUdWpvY85qSVWOLR8wLaCz8wGaJ0xFGlVxLXemOBy6Y5ipWYwclbMewX9ZjNeyASgFa1JYzDd2+lVJ5u2RzN7KTdyiOg2m9PSopCLjpz94bFsLLw9cFBtDjoKDmsjwx737gI3NqQqYbIjC34xg3XUjjjJtAWeKoHIv+otiVtUsj1zsZucSkpuKdN+Z6EHpfJ9IZsUeEKvdO6aRldlxRO+Hz0X1sqPIltAfQxgPD4UPgMb2Z2ye+spBN4BeWc2EC2lyXttmz5hqunzh rQZQDxR0 cqFokeFJU+c4LAU006ny2q+TSiTVWJTnvfmGHf21P1w9uL4ZwGmaoqDUwramQHbxE1POn/4f1GjwrVV2Is1i2hJIhFkRwoZyAodjSgxmMECUGBaUCxZW7H8q9MGAmvPiSGCGDyldt6i9zOG7jnqE9KeqyaFa1F2+fYXWfcv5EICPtjf6KkPrQ8xD84S3onQJwXT0Kf4Hv3pVZsR5m8xrr0iTVm4Zfi6Aqxr7Qhou9HUFDNGF/e+dSTq8JXUxs1AVvePP3DufAY0yYFa9phGreY4/gCnWBnKduVSU2aTRd4o63xZUURQmzE7OAT47m9p6f6914J2CnkMkKRPi5MFULiSDoiJdv5zR4b3P0ciCdApeWZWw= 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: List-Subscribe: List-Unsubscribe: Let the caller of do_zap_pte_range() know whether we skip zap ptes or reinstall uffd-wp ptes through any_skipped parameter, 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 | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f149bc2c0586..fdefa551d1250 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 *any_skipped) { 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); + *any_skipped = 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 *any_skipped) { const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY; struct mm_struct *mm = tlb->mm; @@ -1567,15 +1567,17 @@ 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); + *any_skipped = 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))) { + *any_skipped = true; return 1; + } /* * Make sure that the common "small folio" case is as fast as possible @@ -1587,22 +1589,23 @@ 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, any_skipped); 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, any_skipped); return 1; } static inline int zap_nonpresent_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) + struct zap_details *details, int *rss, bool *any_skipped) { swp_entry_t entry; int nr = 1; + *any_skipped = true; entry = pte_to_swp_entry(ptent); if (is_device_private_entry(entry) || is_device_exclusive_entry(entry)) { @@ -1660,7 +1663,7 @@ static inline int zap_nonpresent_ptes(struct mmu_gather *tlb, WARN_ON_ONCE(1); } clear_not_present_full_ptes(vma->vm_mm, addr, pte, nr, tlb->fullmm); - zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, ptent); + *any_skipped = zap_install_uffd_wp_if_needed(vma, addr, pte, nr, details, ptent); return nr; } @@ -1669,7 +1672,8 @@ static inline int do_zap_pte_range(struct mmu_gather *tlb, struct vm_area_struct *vma, pte_t *pte, unsigned long addr, unsigned long end, struct zap_details *details, int *rss, - bool *force_flush, bool *force_break) + bool *force_flush, bool *force_break, + bool *any_skipped) { pte_t ptent = ptep_get(pte); int max_nr = (end - addr) / PAGE_SIZE; @@ -1691,10 +1695,11 @@ static inline int do_zap_pte_range(struct mmu_gather *tlb, if (pte_present(ptent)) nr += zap_present_ptes(tlb, vma, pte, ptent, max_nr, addr, - details, rss, force_flush, force_break); + details, rss, force_flush, force_break, + any_skipped); else nr += zap_nonpresent_ptes(tlb, vma, pte, ptent, max_nr, addr, - details, rss); + details, rss, any_skipped); return nr; } @@ -1705,6 +1710,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, struct zap_details *details) { bool force_flush = false, force_break = false; + bool any_skipped = false; struct mm_struct *mm = tlb->mm; int rss[NR_MM_COUNTERS]; spinlock_t *ptl; @@ -1725,7 +1731,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, break; nr = do_zap_pte_range(tlb, vma, pte, addr, end, details, rss, - &force_flush, &force_break); + &force_flush, &force_break, &any_skipped); if (unlikely(force_break)) { addr += nr * PAGE_SIZE; break;