Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp105295lqt; Mon, 18 Mar 2024 02:48:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbLtL24/tK4SB3l/elys1jOyWqMZsj/Nv6/roDZsNqMZwBZiC5EvM7cHJuuByTEOcXC/gl3D94kegh9Ywb7i7fs51ZGeYXmmWQc6EDDw== X-Google-Smtp-Source: AGHT+IEYrXNvmz8UOh5Syql4VqYoTz3CrcpLKK/zygfuDIp3xyJR+kRzNxfu8/N6XHDLqeGG5ZNu X-Received: by 2002:a05:6870:3101:b0:21e:9eac:b0a3 with SMTP id v1-20020a056870310100b0021e9eacb0a3mr12455618oaa.24.1710755295372; Mon, 18 Mar 2024 02:48:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710755295; cv=pass; d=google.com; s=arc-20160816; b=jno0ymgqtgyNATAK+9SAL4OddrbyKroL9B4pDm/FZi6b5JaR3wTakTOzdoXDgRsjDU h6/Swp/iy8w4vT21yKsRK21gvRlgjVFEst8FAa+NdoEyD+SylGLzXhYJ/9/ZzcrGcp2r Jue1VR75yBV7wI1P027owFbC8KhiRfEaHqNnW5k+HDp3NbCIjXSSHwUn9XH6zepFlIq2 Z4oUIJMrW/iFlq3FUfCILirwJa/u65e/mfZS6kvgWl7/RY+OvPsBpM0cxf7sGmIQZUpH m77i4lpeOVvWhPVU56opdlFCxX9oOziw+1ocHu74dTLjZKgCXOExsBXhvlLAWdQYpk8L xnsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=nELhg4+vsVbvdDiQeSgfbHglrwF0XWGALe3+9j7o4IM=; fh=HZe650nzRTv8mJiGkNOYh+8c+6o1njrmsvKpqZ7dgps=; b=HMLHuUr9aSrbyFsmJXGmRNFU1qR8Zndh8M36gOZCgmCQjUvEn1f0J2Rwdv9W7/LSfz uKW5KYbAraQWex0dkJYSVC0I15lxHSalyJR6EU9TeszGTdiNE5W1AkpJKU/s5g4DdCml /pxrYLp2Xw3crkxvQ4VF7BAF2WCL2+QX6SCwyKPL3ySxXBQFOi0iN4UyoTY6jOdT6Kyz svndF9nHSFeDhGGAWF/iYB1CJFCkinl42XK1XDGOMVceLUYYLRbPbOvZ/4t/lNaDyokI f6IbOR8JrXqg4/ZGdBjx2lqnYNNCMgqxcXvlG+HFvebmQtzGC1+vpzsj6WHn0cJ0jeM4 mybw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aA//cief"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-105901-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x22-20020a056a00189600b006e72c81aafasi1363801pfh.296.2024.03.18.02.48.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 02:48:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105901-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aA//cief"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-105901-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105901-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EFCF62812EE for ; Mon, 18 Mar 2024 09:48:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3D892C6B7; Mon, 18 Mar 2024 09:48:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aA//cief" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC4182C6A7 for ; Mon, 18 Mar 2024 09:48:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710755289; cv=none; b=BZ6WbWmmG7BWZPBTj025P/LEEfA4KSwtVJRQTfz7I3HNR9P62QtoeaOagI0yNmsKKpPm5GF5RY5m8qJHMPsxdimIkVLMZUEwH2edvkPfpQP0SyBooS27DaJgm04po9KYSDsUKQC+AR9qxUbhXt7RxrkZ5JIOwHoCeJakrAlFQDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710755289; c=relaxed/simple; bh=yLZm8UmDIbSLbszppiTYYW6vVaMGGuKCFnvT//osZEM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=tDg6QhyCpv9k0GYUi6fWlpPGVdCMrp8jHMmStkmFZYZ7+a4sfglVg+9CYOv+kIbMtFFC0PM7+8k1Y0BvCZZPST79c48jj3RKKRq/Sb+BS3eYxxd7lyZWJaM3w4x2egeOqMSj7jAU3ff+az70dpLjCxrYyUIpmuu68dIuK4ZvhdA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aA//cief; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710755286; 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=nELhg4+vsVbvdDiQeSgfbHglrwF0XWGALe3+9j7o4IM=; b=aA//ciefOrKZ6Sn9WJS64kg4mS+aNFlJ2RBpdxCEM1xcuL72lyDd2MBr43qwdKgUigPkit IUrz6YRdDmdwOdijddXtzJCWXqh/7+Rqn2ifijKcV+l22HGmBWknD9+MXNc281eYIofnXB flElNd8kUacatUf6Tdk6CrgfnzPEfHw= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-v-jYkp9DM9GhoFhhrrt_1g-1; Mon, 18 Mar 2024 05:48:04 -0400 X-MC-Unique: v-jYkp9DM9GhoFhhrrt_1g-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-33eb8721b64so2402997f8f.1 for ; Mon, 18 Mar 2024 02:48:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710755283; x=1711360083; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nELhg4+vsVbvdDiQeSgfbHglrwF0XWGALe3+9j7o4IM=; b=j4J8fFWfBtPS1oSaxAL1NGn7m8Q5KSg/1d4SuGEbWUARHwbZG1krUCV7hvtuhxWvWh vFG/XAyeScPKnc7gQumz9x8LqOhIDKaAIjQsAOYi6agy0RvgvXRGPSL8pekYpaDDdoRc E24J3wqMlZ65dxnp2CeN4MRJY1tY/cKTUEoIL/eTon02UBap7pZZ18wt+xnqSwJL6Xkz nbQV+g/pYmwawaRNncAXZ96cC/fdxi0kTZJHEHqCzWj5NdGatpK+WGpxIwTw1UfkVlmw V5ngzIsRQl4zuPothIG9msqJyLWtC+Apcs1CQUKmV+FmwOif1ssVnJL6WENEuK2j8vqH LG2Q== X-Forwarded-Encrypted: i=1; AJvYcCU4xEi4VFJbotc7tF/5UZ0xatqAHLOZobP99Auh0R1tJTbALl8Ag28OLM3gSLOPi+1376TbZKavOmsTuqimcCLb//Cym8R+jHgvJjVh X-Gm-Message-State: AOJu0Yzc1EHYOuq2INiGbDoEpHBZgJwmVQBj8xxDt2lk6Ab/OYboil6D r7BD3ghazIfr2U4J2EW9xr/48jtA+aapJMN4KZxxOmLkavFTWkT9HL7Om1Nnhl1QksV0hxko061 6aQpRy/7aKGbcatAY6d1FliyyzH+T6zJ1W+OhVcqNg3L+kP6iP5lZx8B4vJGJWQ== X-Received: by 2002:a5d:5750:0:b0:33e:8fd:1173 with SMTP id q16-20020a5d5750000000b0033e08fd1173mr7686356wrw.60.1710755283645; Mon, 18 Mar 2024 02:48:03 -0700 (PDT) X-Received: by 2002:a5d:5750:0:b0:33e:8fd:1173 with SMTP id q16-20020a5d5750000000b0033e08fd1173mr7686336wrw.60.1710755283190; Mon, 18 Mar 2024 02:48:03 -0700 (PDT) Received: from ?IPV6:2003:cb:c737:1f00:94ff:246b:30d0:686b? (p200300cbc7371f0094ff246b30d0686b.dip0.t-ipconnect.de. [2003:cb:c737:1f00:94ff:246b:30d0:686b]) by smtp.gmail.com with ESMTPSA id p10-20020a5d638a000000b0033e206a0a7asm9318645wru.26.2024.03.18.02.48.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Mar 2024 02:48:02 -0700 (PDT) Message-ID: Date: Mon, 18 Mar 2024 10:48:01 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2] mm: support multi-size THP numa balancing Content-Language: en-US To: Baolin Wang , "Huang, Ying" Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, wangkefeng.wang@huawei.com, jhubbard@nvidia.com, 21cnbao@gmail.com, ryan.roberts@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <903bf13fc3e68b8dc1f256570d78b55b2dd9c96f.1710493587.git.baolin.wang@linux.alibaba.com> <871q88vzc4.fsf@yhuang6-desk2.ccr.corp.intel.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/E8M7TEw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9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 18.03.24 10:42, Baolin Wang wrote: > > > On 2024/3/18 14:16, Huang, Ying wrote: >> Baolin Wang writes: >> >>> Now the anonymous page allocation already supports multi-size THP (mTHP), >>> but the numa balancing still prohibits mTHP migration even though it is an >>> exclusive mapping, which is unreasonable. Thus let's support the exclusive >>> mTHP numa balancing firstly. >>> >>> Allow scanning mTHP: >>> Commit 859d4adc3415 ("mm: numa: do not trap faults on shared data section >>> pages") skips shared CoW pages' NUMA page migration to avoid shared data >>> segment migration. In addition, commit 80d47f5de5e3 ("mm: don't try to >>> NUMA-migrate COW pages that have other uses") change to use page_count() >>> to avoid GUP pages migration, that will also skip the mTHP numa scaning. >>> Theoretically, we can use folio_maybe_dma_pinned() to detect the GUP >>> issue, although there is still a GUP race, the issue seems to have been >>> resolved by commit 80d47f5de5e3. Meanwhile, use the folio_estimated_sharers() >>> to skip shared CoW pages though this is not a precise sharers count. To >>> check if the folio is shared, ideally we want to make sure every page is >>> mapped to the same process, but doing that seems expensive and using >>> the estimated mapcount seems can work when running autonuma benchmark. >>> >>> Allow migrating mTHP: >>> As mentioned in the previous thread[1], large folios are more susceptible >>> to false sharing issues, leading to pages ping-pong back and forth during >>> numa balancing, which is currently hard to resolve. Therefore, as a start to >>> support mTHP numa balancing, only exclusive mappings are allowed to perform >>> numa migration to avoid the false sharing issues with large folios. Similarly, >>> use the estimated mapcount to skip shared mappings, which seems can work >>> in most cases (?), and we've used folio_estimated_sharers() to skip shared >>> mappings in migrate_misplaced_folio() for numa balancing, seems no real >>> complaints. >> >> IIUC, folio_estimated_sharers() cannot identify multi-thread >> applications. If some mTHP is shared by multiple threads in one > > Right. > Wasn't this "false sharing" previously raised/described by Mel in this context? >> process, how to deal with that? > > IMHO, seems the should_numa_migrate_memory() already did something to help? > > ...... > if (!cpupid_pid_unset(last_cpupid) && > cpupid_to_nid(last_cpupid) != dst_nid) > return false; > > /* Always allow migrate on private faults */ > if (cpupid_match_pid(p, last_cpupid)) > return true; > ...... > > If the node of the CPU that accessed the mTHP last time is different > from this time, which means there is some contention for that mTHP among > threads. So it will not allow migration. > > If the contention for the mTHP among threads is light or the accessing > is relatively stable, then we can allow migration? > >> For example, I think that we should avoid to migrate on the first fault >> for mTHP in should_numa_migrate_memory(). >> >> More thoughts? Can we add a field in struct folio for mTHP to count >> hint page faults from the same node? > > IIUC, we do not need add a new field for folio, seems we can reuse > ->_flags_2a field. But how to use it? If there are multiple consecutive > NUMA faults from the same node, then allow migration? _flags_2a cannot be used. You could place something after _deferred_list IIRC. But only for folios with order>1. But I also wonder how one could achieve that using a new field. -- Cheers, David / dhildenb