From mboxrd@z Thu Jan 1 00:00:00 1970 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 EEC95C3ABA9 for ; Fri, 2 May 2025 06:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68A356B0088; Fri, 2 May 2025 02:29:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63B016B0089; Fri, 2 May 2025 02:29:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B1166B008A; Fri, 2 May 2025 02:29:29 -0400 (EDT) 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 306B76B0088 for ; Fri, 2 May 2025 02:29:29 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 71F6F140696 for ; Fri, 2 May 2025 06:29:29 +0000 (UTC) X-FDA: 83396991258.02.5AB8F71 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id E1A8440008 for ; Fri, 2 May 2025 06:29:26 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aEoEJCiw; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746167367; a=rsa-sha256; cv=none; b=TaIQnB/S21dmYlwMsR/J2pkSzgMfdOigUQApoZj88BdhrxQuxEp1d7OJO7jJQE+y2oU0mq tpZ6spxBkvr/fD80U0f1BeSTkULJV/fBMznOg/sgjsrMzxfQMcSKRNRJx+TwjV84fkDgxw nf6ful+Rs5Uh2N15kVuST8n6lFYGJqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746167367; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iZDEsQl9wXHHDjWYntq9+iB6WMGNQimz1vP5zwMw6YQ=; b=USVrJsq5j58LiX354qsvsFIsxtk8IJ0k/3z8QTmOzx2kkOdKdL3GQ6eKvDCijq4ZwR19ce zKII5MS0mgEho99D0eA0eqtDYTA1gM5HS+c+e17je08/BPDSWTxeW4GbPBwq/y4Uoqe8bv 42hlBMPMqEDVwt5gQAf2uMapY6h8VNU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aEoEJCiw; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746167366; 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:autocrypt:autocrypt; bh=iZDEsQl9wXHHDjWYntq9+iB6WMGNQimz1vP5zwMw6YQ=; b=aEoEJCiwgPML+OYA5DgqFWdB+LLxgDvGYkzUeUDXdLHVNAnJNs/sFWKBjlDP3xDaxW0elO mMI5v8dCVAKrmK113MT/gn5AcankXc16MAMdCbFKcNQ3XR+GJdViYS/tSVaksNpjVJLr0W j/5q9tW84RPU2KyeBwZPuIlkQVjsDT8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-348-wzoI2mCRMoyVHAtYPgFUGg-1; Fri, 02 May 2025 02:29:24 -0400 X-MC-Unique: wzoI2mCRMoyVHAtYPgFUGg-1 X-Mimecast-MFC-AGG-ID: wzoI2mCRMoyVHAtYPgFUGg_1746167364 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43d007b2c79so10115165e9.2 for ; Thu, 01 May 2025 23:29:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746167363; x=1746772163; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=iZDEsQl9wXHHDjWYntq9+iB6WMGNQimz1vP5zwMw6YQ=; b=grD/f+0DnEyqMCk+3kn1RSdbnUsenpjXe85q5BC2AB/CxJ/9fNyaafACAV3uLJ85IX kXKU0fVt9ZGHV7VZmMsn7AGIY/1wVKH2ZtZX1fQoxEzoTGbtp0siiPIRQatzra5fGBiz D3qf93YsSZLF8LvPSiTC3xhxPFsUhJmNI6rVr/kBylCsbkttlgHfQZFze8Gy3rbsiWO+ tmcHewg2X4EVZbhyFcO0PQ5CyCwV3PQqEmB6HUaqs24JAGol/9rFnNS5TEiYHUYx3BuH /BWbIFesqJ7udDIiHij0vBoX7pnYrM7pCNrn1hWSvyYRq4bhdvixIaD0MvGchJTQOFvD CZeA== X-Gm-Message-State: AOJu0YwhPSgpXz9E6VfLAsxg7QGm4T6oyOs36fM844p2isGucxiCVvAZ 5eBj2wwLC7PdRxFXGn/6MDvm1wrfYDucfWTrISdkyx9CmNzK+QUJvRiDUjqxDKIbWF2Z+KfewOa kjJuKH5RA/Z8CUmioG40ZWtuypzedvOYWTYt9IHgdDIysYoG0 X-Gm-Gg: ASbGncuRvAOAPPyStoQJ5iuK/yP41zOlPX+Q8mUQVTWIWBBWvlUg+xA9tSw7egHR+vw IKuWde8mHCBJkRhKPrCkh+KgZ0VDCsoBo9s48s+8Oe1Rs5YrKT7ugUs/uGeanfuI2hoLZTH3UrV 4RbHgv0IdnfEvcp5wLsirt+Zjk9K3j0NastOzc44haR6xPgFpL0w1m/BrPZqQ11XRoMqnfLjuYt pSjQcVy9aTtdQBO9JnIqzKOUSDGZHNkUirJBgFi1C2LeqjNoNcoFSdawkgxanSM/iJtVijlwDVQ hiMhEL7VN2SIbytGkrX1mF/hiKcRnwwRptK22BPEROgCAw9+4bsPpySiacSlEevlI60Mm2KsZKq uwUv1SK9F7Teoom0nihn93+OXN+Kx2n3r/jSQ/ec= X-Received: by 2002:a05:600c:6286:b0:440:6852:5b31 with SMTP id 5b1f17b1804b1-441bbec1e10mr11638335e9.10.1746167363698; Thu, 01 May 2025 23:29:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2+xVsQ0C21l/rgaRxgHSUEMDNv+GhVKjGW+Tkc9Q4XJjh9K2+iMYzkDzIzSpf98d4/5Cenw== X-Received: by 2002:a05:600c:6286:b0:440:6852:5b31 with SMTP id 5b1f17b1804b1-441bbec1e10mr11638075e9.10.1746167363298; Thu, 01 May 2025 23:29:23 -0700 (PDT) Received: from ?IPV6:2003:cb:c713:d600:afc5:4312:176f:3fb0? (p200300cbc713d600afc54312176f3fb0.dip0.t-ipconnect.de. [2003:cb:c713:d600:afc5:4312:176f:3fb0]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-441b2af2a0csm79208595e9.18.2025.05.01.23.29.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 May 2025 23:29:22 -0700 (PDT) Message-ID: Date: Fri, 2 May 2025 08:29:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 07/12] khugepaged: add mTHP support To: Nico Pache , Jann Horn Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, akpm@linux-foundation.org, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, ryan.roberts@arm.com, willy@infradead.org, peterx@redhat.com, ziy@nvidia.com, wangkefeng.wang@huawei.com, usamaarif642@gmail.com, sunnanyong@huawei.com, vishal.moola@gmail.com, thomas.hellstrom@linux.intel.com, yang@os.amperecomputing.com, kirill.shutemov@linux.intel.com, aarcange@redhat.com, raquini@redhat.com, dev.jain@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, tiwai@suse.de, will@kernel.org, dave.hansen@linux.intel.com, jack@suse.cz, cl@gentwo.org, jglisse@google.com, surenb@google.com, zokeefe@google.com, hannes@cmpxchg.org, rientjes@google.com, mhocko@suse.com, rdunlap@infradead.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com References: <20250428181218.85925-1-npache@redhat.com> <20250428181218.85925-8-npache@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEY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6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: y4FqHbMHSd7ym7GUOxp6OrCz6DEPGPo06oOG2pr7sBk_1746167364 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E1A8440008 X-Stat-Signature: 8r7dmbdiwcxqqkbibt5c35q3yariswk1 X-Rspam-User: X-HE-Tag: 1746167366-322817 X-HE-Meta: U2FsdGVkX1+YNCozxSLbEa1H4rHUmyduOmXbLZFn5rSPbCdjHS8z9w4GGT2WAc8kBoSoe4cQHVO1a14SzNvE0ONDrUWBr1Pb8lkwINbFrFHL10woyPDVlc2Wrx3JzdgJc9y048S0CT7PJkngMqFo1QaQjyLBK884V+Bv4A3QoP5bkmrdmBWQ5cTybAoOdFERhpipgQKfIswhAtI3Ln35u0mYa9EL/amu9uagu56g8XvCznBMCzPshmc/5egYwIEB4uuvA0QNVExBvBe5wmFRrD1HetXJjBNhIJ76OI08RbXdivYCZ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b7ajzndTcusZyWaE3KWEOrAfWVP9pF9yjVIRgknipRZ2HPu9uWROeUpk1tu0B0Gn4Tz88vQdkTVMF0HV3VHahCZ/9QhRFQ6sz8J7x8eYgmUP/Wk+S/d1oDGtONqr22hI+rgLxl9CDIkskKLir8q5kC8td2xhaHIobsIJzsKGIBNZ+ltE= 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: On 02.05.25 00:29, Nico Pache wrote: > On Wed, Apr 30, 2025 at 2:53 PM Jann Horn wrote: >> >> On Mon, Apr 28, 2025 at 8:12 PM Nico Pache wrote: >>> Introduce the ability for khugepaged to collapse to different mTHP sizes. >>> While scanning PMD ranges for potential collapse candidates, keep track >>> of pages in KHUGEPAGED_MIN_MTHP_ORDER chunks via a bitmap. Each bit >>> represents a utilized region of order KHUGEPAGED_MIN_MTHP_ORDER ptes. If >>> mTHPs are enabled we remove the restriction of max_ptes_none during the >>> scan phase so we dont bailout early and miss potential mTHP candidates. >>> >>> After the scan is complete we will perform binary recursion on the >>> bitmap to determine which mTHP size would be most efficient to collapse >>> to. max_ptes_none will be scaled by the attempted collapse order to >>> determine how full a THP must be to be eligible. >>> >>> If a mTHP collapse is attempted, but contains swapped out, or shared >>> pages, we dont perform the collapse. >> [...] >>> @@ -1208,11 +1211,12 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, >>> vma_start_write(vma); >>> anon_vma_lock_write(vma->anon_vma); >>> >>> - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, address, >>> - address + HPAGE_PMD_SIZE); >>> + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, mm, _address, >>> + _address + (PAGE_SIZE << order)); >>> mmu_notifier_invalidate_range_start(&range); >>> >>> pmd_ptl = pmd_lock(mm, pmd); /* probably unnecessary */ >>> + >>> /* >>> * This removes any huge TLB entry from the CPU so we won't allow >>> * huge and small TLB entries for the same virtual address to >> >> It's not visible in this diff, but we're about to do a >> pmdp_collapse_flush() here. pmdp_collapse_flush() tears down the >> entire page table, meaning it tears down 2MiB of address space; and it >> assumes that the entire page table exclusively corresponds to the >> current VMA. >> >> I think you'll need to ensure that the pmdp_collapse_flush() only >> happens for full-size THP, and that mTHP only tears down individual >> PTEs in the relevant range. (That code might get a bit messy, since >> the existing THP code tears down PTEs in a detached page table, while >> mTHP would have to do it in a still-attached page table.) > Hi Jann! > > I was under the impression that this is needed to prevent GUP-fast > races (and potentially others). > As you state here, conceptually the PMD case is, detach the PMD, do > the collapse, then reinstall the PMD (similarly to how the system > recovers from a failed PMD collapse). I tried to keep the current > locking behavior as it seemed the easiest way to get it right (and not > break anything). So I keep the PMD detaching and reinstalling for the > mTHP case too. As Hugh points out I am releasing the anon lock too > early. I will comment further on his response. > > As I familiarize myself with the code more, I do see potential code > improvements/cleanups and locking improvements, but I was going to > leave those to a later series. Right, the simplest approach on top of the current PMD collapse is to do exactly what we do in the PMD case, including the locking: which apparently is no completely the same yet :). Instead of installing a PMD THP, we modify the page table and remap that. Moving from the PMD lock to the PTE lock will not make a big change in practice for most cases: we already must disable essentially all page table walkers (vma lock, mmap lock in write, rmap lock in write). The PMDP clear+flush is primarily to disable the last possible set of page table walkers: (1) HW modifications and (2) GUP-fast. So after the PMDP clear+flush we know that (A) HW can not modify the pages concurrently and (B) GUP-fast cannot succeed anymore. The issue with PTEP clear+flush is that we will have to remember all PTE values, to reset them if anything goes wrong. Using a single PMD value is arguably simpler. And then, the benefit vs. complexity is unclear. Certainly something to look into later, but not a requirement for the first support, The real challenge/benefit will be looking into avoiding taking all the heavy weight locks. Dev has already been thinking about that. For mTHP it might be easier than for THPs. Probably it will involve setting PTE migration entries whenever we drop the PTL, and dealing with the possibility of concurrent zapping of these migration entries. -- Cheers, David / dhildenb