From patchwork Thu Oct 17 09:47:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13839729 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 BA676D2126D for ; Thu, 17 Oct 2024 09:48:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 509C76B0088; Thu, 17 Oct 2024 05:48:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B9756B0096; Thu, 17 Oct 2024 05:48:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 359E26B0098; Thu, 17 Oct 2024 05:48:04 -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 170FE6B0088 for ; Thu, 17 Oct 2024 05:48:04 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3601FC0FEB for ; Thu, 17 Oct 2024 09:47:52 +0000 (UTC) X-FDA: 82682617710.06.767C0C3 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf09.hostedemail.com (Postfix) with ESMTP id EF8AE140004 for ; Thu, 17 Oct 2024 09:47:54 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=G+oUeiV8; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.182 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=1729158336; 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=KKkeoST6I/bkefiDvyHuFZOvKUoGTogE4tqpFCMcSq8=; b=1amqHV0+FejKiPs6RLdYrRZ6+MAB1vEbcJl1NKEgJxzUGuqPpjB/2QO4zI5zQnLk/w+qXn 7LNYj9wte8hhLsYv8tAtMbPiNeevntj7fWOVK1Dyc9MXdKEbIlyxuOQLj3tynfTIwTjWCS pik0ukxlZj6p+zzBfzBbrOiByLAhjZ8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729158336; a=rsa-sha256; cv=none; b=G4TzvhcNfqqq3fmy64PHghqfrfT3YS0Bxr/DY/WsicGcpHIvN3S/UUik65JjrlZPQ0TLGh Uu49n7sepSsPg3Duqtr+X33sv+o0/+xvhEoyZelr0cJCL6ezJzvP1Tc6m4VHBKre6m/xQn mCj5oz0gqnJPhYGt42e4CFjnCh+13Vo= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=G+oUeiV8; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7ea8c4ce232so762521a12.0 for ; Thu, 17 Oct 2024 02:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1729158481; x=1729763281; 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=KKkeoST6I/bkefiDvyHuFZOvKUoGTogE4tqpFCMcSq8=; b=G+oUeiV8vruRVXWp82sqj+Swn8xIuHNzUQgU9zb/n2vcqmifdDa7E85763F0O48X4m TsioOsX3RrsPcGGU+TnoU9S4HgoM9ptbjtM5lmkreuISYkg8dUo85+mfNGVevYkjopPV Ymg5n8ovJqo8bARMnAFCvIu9dUJ1uEskkokSskID4WOLJeS3GXzh1AU6cpvAI1iS24v8 MjDAC1TbwSOL5UJU211PXHEDGYgt8/vHLcdyl+shLqQsZOhVogDlDot8LSDxhPLZ2dCq fLEdpZsoHEeWJ8oCr6G3YIxHbKriHHeq4b9krBN+l3h/PjI1Wbl3KYEylTLEv9MxVQkE hnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158481; x=1729763281; 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=KKkeoST6I/bkefiDvyHuFZOvKUoGTogE4tqpFCMcSq8=; b=MmHfWB1QzD/pIK+Z3tES1xwY1Sz8a6GIkItmKnAXrEprck7AHuXj9ACAXPHbVKkznB sarKw3cQ6133+b/VXeZxaNrCrTC4drdg318g1BN8Fz4jGlREH6TRXh3od6DaFipEfH0+ bTu4iOgzDzY9I7A7e6XO3fcMRx7g1l390F2wzkeSSlbcGbis+5SZqkU5m1zC/QL4N0Fy hI6sXVfri31+QRx9FMODrkFCTxU9o0lOJm8JFWp9wAD3AJpWnHmz1QAPMW4y6bp77VNj NdvRe/XTzDFSyT7rr8EM7xLou7g9ZO0OwpuRxrdJ7Pw/PmRzERXgBhcIyuTO6hGq6Zaw 4QZQ== X-Gm-Message-State: AOJu0YwOiNDlojfSESoUNcGY2ha7rzYB3bLHECM5LOzuuDBQg7x1BA+x l654udHCcBSPx9f4X9HAapVENPeMnpqjKsKx9pZXHXhb6v/EeQPAY8watxmw1aw= X-Google-Smtp-Source: AGHT+IEI5E0ziycErtAHmWC08AA6d27vlvkOtexRBD8N1aJkqSz6qnPieAM9Lamrn4x3BOyjY5wnjQ== X-Received: by 2002:a05:6a21:3998:b0:1d9:21c7:5af7 with SMTP id adf61e73a8af0-1d921c75b3dmr1710778637.15.1729158480809; Thu, 17 Oct 2024 02:48:00 -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.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:48:00 -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 2/7] mm: make zap_pte_range() handle full within-PMD range Date: Thu, 17 Oct 2024 17:47:21 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: in6idczbtmjexw86qy4oudkn7nb7bwcc X-Rspamd-Queue-Id: EF8AE140004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729158474-387249 X-HE-Meta: U2FsdGVkX1+ItNrxTKBS3DbY2vkfVy8FHMrgbjNL665gPobAGlZ77BVXkPe3fvToW2PwbCMc1vHv50NSk7lzxR1uwqw3jije/67qB/c9/j06k9f9H35fk4HQvROQMWZe5YkIW4in/A+bPsB/hDQJ+5RC2S5en1ZQEspYMD4D2C96BSunKKxQzTa5dB9TsdCbUBbgXrwjzTPf/nG7xG+T1RhLP5kD941Wh22v/WAt8Zt1ejyom7inPpIlDau8bP/vCz6bR87D3hNkS5bXhG8NeJYH2sVgHPUtablYTKiEb+BD2gLuzx6sBWaXOWNUiEURQX9iQv5IQ1vuSseVOOoGZCt8DCXTa1rPBn1SDDWc8TB74xAK/dG9IY+BU83eRODjxox4ZFjQ2Kdg9OtcvBz/TDTBOZir5OpYj0tezoKY6ffav82LJv+4hEmGkAbjaHZuL3pjj5Ibek0yYAjfpw5FC2Xna8gPriW942ktfraEybmODsxu6p0PTj4K+mW4exs1HAaKqfKktrauli+s3FzeojnSisge55HD8FH8rwjT3d0xZCdIPqU7QeO4UsC7uIN8Hl6hsYevPGfL+vS05Sr8/D8LFuJ7/9ErbID3rMg36gVQb8iTisIKTGezgbps3Pss+VeEQzE71QfOCx4+oACTOh1xc/LSDZZWrk8rJ6RLfRMnvohfTonxORIg7E+UnVdRr4rY7vsO30twQr5wT1VbLFmcl8yVPw3JDr0GM/gq8Npk5kL+T/+S8M5kLNDqTXf5NzmYfKQHNhaT94r/SfatYAlt/FQMD7iRQTkzF9ofAknWP1e4xmQFNxOEGOeOKzVp7/Rt/VykRjjsHC4EMdOFvom7UbRp5ZHoorWXLJ0m9PQ4Qg8mH3191/dtLt0SDm/NVCte9j3bhtVNxo4IgvaeBMeQXeAOlwM/3S1MjF0T+W5d4cuhAx1wZAYy5KN7LW7RuVIMu84/6SlmsNYOtfo H0Lgprdi 75Ew98pYjf96M2NAAW0urnZUAghFAYI8aNFhnml5OdZreOGQMYA8IPDhRDTBN2Nry2I285FfVrTR/faGEub30QeK46ja74TQDuvijy/w/mdBEhT4LK0KaUyeI9W7MxrnFzSPXoVWfeiI40SibOW3U7RrfZh5PmeXWvUF3xq0Trums73XRrTdTSy60G7mFVedp2LZfemNeI3OJxp2FTbRXnvKhORuZmhFJkBgLjeSa10zASzdhkOXDneb/nT1xxPuom0RHwyKiqbmF1pCPbkT3nUR7tbXoipw1pfezTZFHah8Skhp8nJFZHWXr0MQ/j+Xa8ea5VDTAWg2gBjY2YOgxouUdX5/3TO44509wiz9SupgdiO0= 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: In preparation for reclaiming empty PTE pages, this commit first makes zap_pte_range() to handle the full within-PMD range, so that we can more easily detect and free PTE pages in this function in subsequent commits. Signed-off-by: Qi Zheng --- mm/memory.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index caa6ed0a7fe5b..fd57c0f49fce2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1602,6 +1602,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, swp_entry_t entry; int nr; +retry: tlb_change_page_size(tlb, PAGE_SIZE); init_rss_vec(rss); start_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl); @@ -1706,6 +1707,11 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (force_flush) tlb_flush_mmu(tlb); + if (addr != end) { + cond_resched(); + goto retry; + } + return addr; } @@ -1744,8 +1750,6 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, continue; } addr = zap_pte_range(tlb, vma, pmd, addr, next, details); - if (addr != next) - pmd--; } while (pmd++, cond_resched(), addr != end); return addr;