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 85615C3DA7A for ; Mon, 2 Jan 2023 18:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E1AD8E0002; Mon, 2 Jan 2023 13:05:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 990E88E0001; Mon, 2 Jan 2023 13:05:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87F6F8E0002; Mon, 2 Jan 2023 13:05:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 79DAC8E0001 for ; Mon, 2 Jan 2023 13:05:30 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1FB39C07A1 for ; Mon, 2 Jan 2023 18:05:30 +0000 (UTC) X-FDA: 80310636420.27.F12B220 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 73CE24000C for ; Mon, 2 Jan 2023 18:05:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H+ujm1sy; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672682728; 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=w3mLnRIt+HpZ9msmYlU01/hsLNmBZwMA2RpROeWKrxY=; b=VlkasA3Wpqjt3eB0RZJYTOoz6SvrjOG1WAVe9ycgzZdHjVcPayktf/zwh4QdwhNGTY358v uUNEiuC5SG0Eln6E/H6SBafIIKIUPFGJRAr/XN87BeIkUe7xM3Mmogypa6cJSTbKqSGEqv 8kZaLv+wkuR2tCl6dAUCKJE+gmofptI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H+ujm1sy; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672682728; a=rsa-sha256; cv=none; b=xysGigLU+P406I+QpYWJGJm7HlOYyk+HzRK2ElDiGRK93stHXkkF7GnPaEkEtONlrW46v7 Uf/+KotxrRoDQ3FIO8b6/3bY3VdGiUEO47uq3h+198B+p+u3nkZ7gj3XoTG4vu8ZpqcocP 0t8KcIu/P7a5/SxsD6Mhq6OV3pAHspA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672682726; 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; bh=w3mLnRIt+HpZ9msmYlU01/hsLNmBZwMA2RpROeWKrxY=; b=H+ujm1sy5kba9tDkeZq1ezbWqooU7ZUpT1HeJZi7u2BiSv5HtD7rxN/Gee1JFSLrGyk6kt mmhAMxkRigpKm44fJBUcAiMp54JZV4XuXbd+gWg4+sMdUhP3/LU+uxl67tBrc6uk2VbO/6 C4sc7RYIcsNvwq9H3Sp8RMToPhbjR7I= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-411--PPgdppjN2-v5P8vGephYA-1; Mon, 02 Jan 2023 13:05:25 -0500 X-MC-Unique: -PPgdppjN2-v5P8vGephYA-1 Received: by mail-wm1-f71.google.com with SMTP id bi18-20020a05600c3d9200b003d991844dbcso9310798wmb.4 for ; Mon, 02 Jan 2023 10:05:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w3mLnRIt+HpZ9msmYlU01/hsLNmBZwMA2RpROeWKrxY=; b=57DeImTtdF6CG+TIwUcxoDRq9pWlcaLY/nmB+8nIxiLit7hRjJHxUKBSbzBBlLHant U2vDS+Hq1z47N+YguBmOmWjvI494TB3vVDgOc1uPtW1KBhWNzGlEahXp7MIMrm0OcBmE Z0ug41qOHanhO4eodQDgjhUxFa3sbHwwBoL8MtCgrOc20lFMmLEV3BMh8xNbsxlmqi3N tvHNNlF3tOTFZAyKzK9J7Lr7+QUAO/FPLqHdfni56xbVwwwyjQxODapz47QAeuOTBEDP XxXaLAL2xcAtP7A/2CaSqSxbgQtxy/58zxeeQ1SmgjPO7Ythn/XSMVwcAAsf/ngOuEQu HejQ== X-Gm-Message-State: AFqh2koop7SsqwZXjz+mZJhhm+spnuZVVR+040d0ky/UTT/RO52QjT2k Kl0xxFIxJiQYQdyTNi08q+q9C3zrCNeLCZ1zBU5957rEUCLYEq/GiH+othIXo/96elSGCAqIQRz R7ErmOPntapo= X-Received: by 2002:a05:600c:1c81:b0:3d1:e907:17cb with SMTP id k1-20020a05600c1c8100b003d1e90717cbmr29503691wms.1.1672682724434; Mon, 02 Jan 2023 10:05:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXuqkWjF7HqnjgodsGJy5LR7bND+uNurVGzbXVlIrOKEU4p1Ld7ZurNtVnXY0fjCPKI7Zxgvbg== X-Received: by 2002:a05:600c:1c81:b0:3d1:e907:17cb with SMTP id k1-20020a05600c1c8100b003d1e90717cbmr29503678wms.1.1672682724144; Mon, 02 Jan 2023 10:05:24 -0800 (PST) Received: from ?IPV6:2003:cb:c703:500:9382:2e5a:fea:8889? (p200300cbc703050093822e5a0fea8889.dip0.t-ipconnect.de. [2003:cb:c703:500:9382:2e5a:fea:8889]) by smtp.gmail.com with ESMTPSA id j20-20020a05600c191400b003b4fe03c881sm50629293wmq.48.2023.01.02.10.05.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Jan 2023 10:05:23 -0800 (PST) Message-ID: <3a4b1027-df6e-31b8-b0de-ff202828228d@redhat.com> Date: Mon, 2 Jan 2023 19:05:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: alexlzhu@fb.com, linux-mm@kvack.org, kernel-team@fb.com Cc: willy@infradead.org, hannes@cmpxchg.org, riel@surriel.com, yuzhao@google.com, ningzhang@linux.alibaba.com References: From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v6 0/5] THP Shrinker In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 73CE24000C X-Stat-Signature: benjrr3oin8he15bc9853k3xdhekuut5 X-Rspam-User: X-HE-Tag: 1672682727-21960 X-HE-Meta: U2FsdGVkX1/4HI1rmoCsDzT8rR8AFU+TfqoGpNZkA1yUMj1CgyrpvgkfReyMUqRhCzLuuT70Gl2MBBRhD4UxJQE8ZmRg06SQJSSea4itOEtnKQhZEtvRDUm4LvrcGwRL6sUHlm30lro0qflcKAqTTfLGJtaAcn/JuqTTyCiRdVH0gTq0Cfw6ScnG92FMHcuMbWuojf/GuWXkH7lOEfXVzisSsD3A3HFM+ICM0BEB/bg1o1HSegJLY5zeBaerRNYvlv3E4cXgEwhzL9vWKlb9ZmrIEefN3gscPdfD0SXanoTJ4ibCGnjpU0BzskK4zFmYdMQEW4JUplq0x1uDD1qpGeO5/x9xhd59w3GlQHsqSzHvQssa2/6XTQ5YKicfeZ2u/9aY6s60wygQKJY/ldOOJDTPu6LqzdxO+YUVPhlcMdPcG1kxUjBHlswU9JhsqVA2Bjy6uuuIIeM31r6kLU6EX3ezUH1w/dtr2cO/uCHPS1WepB+FqyfjI/eJCXCIXnvt2TPcs+M2l/2mXlUGmMbc1ieLJUDDGkAfo0fQ+iDCEz8nYlmiNGfiRfwBnpQ6vkoDL+FhCOmjTxNTW+/SQaSEsjP6R7emAwhksRCns9vbw+ckrSqYNAtZPO0FKHje0f3u1fquWjq/uFLOmfpANp8QX7f3gCq/qIKhZy2zNASzHVdAiw512Sre8wsVjGwUz4vDNs18p5Ry2ou7v2HVslkTD2vMOzL1DzhOsOzu22NprAz6kOfo6u3Qdu8owCprqXUjLTl9MhQbjCZEQAjTyKJsqBbc4NMjHAOL7Slkb++lquidkr0CvmCc8vSeKwB1q+0/9xEPx8etvkqwKWTV5c8oSW3k1BKcAZkEWenzO0TA3U8km5rfUbLszsd5rZD7W87lw4MQ86ItJCi6yMU9qs6xGm8LxAIaDmjNh+run+qlD1KaYgb8urGKHgYpGdWCP14ptbVPp8zjylkjft3r+6o CAOz1YTv 1nPQkhgxpvhINJajFExIy5AgWZShMqVpOXlRfiYkAigsM6qlJTUq4zDGAKObN33kulqethVLW8YxJiLXDvPrQWHSQEpIK1qS2wJEafnIXjh3bNqhJ6N/7MaUTcyE6Tk3Lb6Wr4W7hSnzZkPA= 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: On 03.11.22 07:01, alexlzhu@fb.com wrote: > From: Alexander Zhu > > Changelog: > > v5 to v6 > -removed PageSwapCache check from add_underutilized_thp as split_huge_page takes care of this already. > -added check for PageHuge in add_underutilized_thp to account for hugetlbfs pages. > -added Yu Zhao as author for the second patch > > v4 to v5 > -split out split_huge_page changes into three different patches. One for zapping zero pages, one for not remapping zero pages, and one for self tests. > -fixed bug with lru_to_folio, was corrupting the folio > -fixed bug with memchr_inv in mm/thp_utilization. zero page should mean !memchr_inv(kaddr, 0, PAGE_SIZE) > > v3 to v4 > -changed thp_utilization_bucket() function to take folios, saves conversion between page and folio > -added newlines where they were previously missing in v2-v3 > -moved the thp utilization code out into its own file under mm/thp_utilization.c > -removed is_anonymous_transparent_hugepage function. Use folio_test_anon and folio_test_trans_huge instead. > -changed thp_number_utilized_pages to use memchr_inv > -added some comments regardling trylock > -change the relock to be unconditional in low_util_free_page > -only expose can_shrink_thp, abstract the thp_utilization and bucket logic to be private to mm/thp_utilization.c > > v2 to v3 > -put_page() after trylock_page in low_util_free_page. put() to be called after get() call > -removed spin_unlock_irq in low_util_free_page above LRU_SKIP. There was a double unlock. > -moved spin_unlock_irq() to below list_lru_isolate() in low_util_free_page. This is to shorten the critical section. > -moved lock_page in add_underutilized_thp such that we only lock when allocating and adding to the list_lru > -removed list_lru_alloc in list_lru_add_page and list_lru_delete_page as these are no longer needed. > > v1 to v2 > -reversed ordering of is_transparent_hugepage and PageAnon in is_anon_transparent_hugepage, page->mapping is only meaningful for user pages > -only trigger the unmap_clean/zap in split_huge_page on anonymous THPs. We cannot zap zero pages for file THPs. > -modified split_huge_page self test based off more recent changes. > -Changed lru_lock to be irq safe. Added irq_save and restore around list_lru adds/deletes. > -Changed low_util_free_page() to trylock the page, and if it fails, unlock lru_lock and return LRU_SKIP. This is to avoid deadlock between reclaim, which calls split_huge_page() and the THP Shrinker > -Changed low_util_free_page() to unlock lru_lock, split_huge_page, then lock lru_lock. This way split_huge_page is not called with the lru_lock held. That leads to deadlock as split_huge_page calls on_each_cpu_mask > -Changed list_lru_shrink_walk to list_lru_shrink_walk_irq. > > RFC to v1 > -refactored out the code to obtain the thp_utilization_bucket, as that now has to be used in multiple places. > -added support to map to the read only zero page when splitting a THP registered with userfaultfd. Hm. I just stumbled over QEMU background snapshot code again: What QEMU does for background snapshots is the following: 1) Read-access all guest memory so we have something mapped. (ram_write_tracking_prepare()->ram_block_populate_read()) 2) Register uffd-wp on all guest memory and uffd-wp protect it (ram_write_tracking_start()). So if you split a THP and discard zeropages after 1), but before 2), the background snapshot might be messed up: instead of zeroes inside the background snapshot we might find modifications that happened after starting the snapshot, because uffd-wp protection of some pages was impossible. What QEMU does before all that is sense if uffd-wp is possible for all guest memory by temporarily register uffd-wp and then unregsitering it again (ram_write_tracking_compatible()). Maybe we could use that (any uffd-wp registration happened for the process) as an indication whether we have to be careful and not discard zero pages ... -- Thanks, David / dhildenb