From patchwork Mon Dec 16 16:51:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13910085 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 AD1F2E7717F for ; Mon, 16 Dec 2024 16:53:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 362746B00BC; Mon, 16 Dec 2024 11:53:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3134F6B00C0; Mon, 16 Dec 2024 11:53:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18A626B00C7; Mon, 16 Dec 2024 11:53:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E959C6B00BC for ; Mon, 16 Dec 2024 11:53:40 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ABA151A0195 for ; Mon, 16 Dec 2024 16:53:40 +0000 (UTC) X-FDA: 82901418054.04.8DCC7B9 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id E996E140004 for ; Mon, 16 Dec 2024 16:53:18 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734367988; 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; bh=WZ4O5Num19mBVok4b6QGM7XTbrkse/VcnZ42Aznf+Nc=; b=vI82gsoULkSOXcK6atCHNQqF84Clrxf929fNKoZ0FMs5fcoMGlacI4C8L4oJG58ErCG0sL /0b3vKYhK5tLIv6dHc7vnRwoWbC1VgUz9XgSjqu52B/yJzjYPB3Zm0zl5T9Kx0Zk7loeSB eH3m6rfVy5k8sMYdnVEPKRazgpGEdmA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734367988; a=rsa-sha256; cv=none; b=4eL5SI9jugX7qH7wI+En4H2Z2SAZuhtSO2tPxKFCrc9Hx9VHOZR3lNOHqc9FNYZj5bPHcB jzd1rwCdOg3uXdNr4XkPnCIm7NM0Y/oyxvp58+aJiMONcx3uT5KloQZufUx4CoodlQ+5Xt 2y6K1KtPr7ZlXuSKVfn/L8rQpwCXQDU= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 911B616F8; Mon, 16 Dec 2024 08:54:06 -0800 (PST) Received: from K4MQJ0H1H2.arm.com (unknown [10.163.78.212]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B695E3F528; Mon, 16 Dec 2024 08:53:27 -0800 (PST) From: Dev Jain To: akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, kirill.shutemov@linux.intel.com Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dev Jain Subject: [RFC PATCH 11/12] khugepaged: Enable sysfs to control order of collapse Date: Mon, 16 Dec 2024 22:21:04 +0530 Message-Id: <20241216165105.56185-12-dev.jain@arm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20241216165105.56185-1-dev.jain@arm.com> References: <20241216165105.56185-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E996E140004 X-Rspam-User: X-Stat-Signature: 6b4f7k5zb6c9ugzdb3wr6xfoyahs7seo X-HE-Tag: 1734367998-807489 X-HE-Meta: U2FsdGVkX18bHSUEFpI4m3qnCrCs4TudIQk5bh6sBEOQl+uUw5YJhbnpF1An3oCWBc4LMHJLB5nSA+a0drInSZxKvIl5A1qYb035f9EQTnrzTlx52N9mhA+XaoXkcFGunebGULoLXBgq0XMeoVqYK4eWu9YxQr2hLaNTORPbkrpt564iRaXRu8cdVP9/if0pNo8ewLT4yAgBXl13Ry9R8kvTij3UD8ZWTLVV6cMKBJZaRJpQonfrzghdQmOESTYt3rOGhphQGWK6Oh4qrI+hi5P1FEUmAcoom4ceLbmlXmQKMWTulsawPAyMInTlgZxtuuw2U8hKZce29q3cu2+h4lghl/d49M+pv3mktbLmmwZRaEuv+rP1TkFh/5mtHtSi8WV0NhYzI2oCF3KIzSN/WeANyKccHAiqhzbSi7n+UclHFu9C+yIqpNAH/2WT4pei2xcoFZSx4cFi/APa0ozFxzYFarOScqJsP6mgyc/ZTtqfQNBlRu34PpjHHAphyPbF08znbf0MyayU52VcBm6MuI311r5D1bx5MgUrVzfj6nGSc9p9QG/r+ZeMdsJx31piaOfCjOnr2kBmouoLRacPNWBPyP09fcuEuLDAkK3IMy8pi/vt3M6Tl0UUd0Oo/kNKkTLbErb+TKiApXEt2wtoTCHBCGC6SKMi4H9SskIv6Nqg1WWEOqX+N0pSQTvIgff75RaK2/wMB8+tAA5PD3HJwrCZE8aSbdHWQU3SFLf6RzfWrkxImU7o4bYQIRi4juI+dgqoAZ2ZMnM+5GEEYOq00I56CLZ5vz+oqfJRnM8GOhJ6Iiw/ZvkG5oU5iwVE+3igNe4/k5Pu2Wx5IyIV3hkDiHttURBu11Jv1UNO1ZbiHvtlKFmym5Eheu+m+9DwmIZXeh/Xkl42GyJPTleefe5eeVrFoS/wPm3a7sf/DYBmaOKgsV6TIHof9ZtjCM4pMyQnMvtJ3Xo5FELLK/K5MJf eA/Sr8KS TiKFc1d9g/LgApObWUxOd2DKXT3WiFThEPWC1BevhEyMrWN09XdRVf0StxH3/7vXwvAjrzRp0wbOsgKgEFwNvdlSuHXv11gR+VKDWndVigszNG0IwG63woKVwLbK0zPzHOSGT41nTnfImnODnBJBrtWYyDeKE4QsRtJUCkDktBdw3DqAP69I5nNwbAmVegaOe5Cw6cVroaEqT8IcGag7XtgUYzbA+9DaE5SmSEIzt4Ct1ScK8O6LjrdH1MKWs+lcC7Qkj5xLgmvhqbKwquv/qckWgRySjhJsXL+TydmpIY0DG1pa9VGnZjDoIptOHLQ6j3+FY 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: Activate khugepaged for anonymous collapse even if a single order is activated. Note that, we are still scanning the VMAs only when they are PMD-aligned/sized, for ease of implementation. Signed-off-by: Dev Jain --- mm/khugepaged.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 47e7c476b893..ffc4d5aef991 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -414,24 +414,20 @@ static inline int hpage_collapse_test_exit_or_disable(struct mm_struct *mm) test_bit(MMF_DISABLE_THP, &mm->flags); } -static bool hugepage_pmd_enabled(void) +static bool thp_enabled(void) { /* * We cover the anon, shmem and the file-backed case here; file-backed * hugepages, when configured in, are determined by the global control. - * Anon pmd-sized hugepages are determined by the pmd-size control. + * Anon mTHPs are determined by the per-size control. * Shmem pmd-sized hugepages are also determined by its pmd-size control, * except when the global shmem_huge is set to SHMEM_HUGE_DENY. */ if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && hugepage_global_enabled()) return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_always)) - return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_madvise)) - return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_inherit) && - hugepage_global_enabled()) + if (huge_anon_orders_always || huge_anon_orders_madvise || + (huge_anon_orders_inherit && hugepage_global_enabled())) return true; if (IS_ENABLED(CONFIG_SHMEM) && shmem_hpage_pmd_enabled()) return true; @@ -474,9 +470,9 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, unsigned long vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && - hugepage_pmd_enabled()) { - if (thp_vma_allowable_order(vma, vm_flags, TVA_ENFORCE_SYSFS, - PMD_ORDER)) + thp_enabled()) { + if (thp_vma_allowable_orders(vma, vm_flags, TVA_ENFORCE_SYSFS, + BIT(PMD_ORDER + 1) - 1)) __khugepaged_enter(vma->vm_mm); } } @@ -2586,8 +2582,8 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, progress++; break; } - if (!thp_vma_allowable_order(vma, vma->vm_flags, - TVA_ENFORCE_SYSFS, PMD_ORDER)) { + if (!thp_vma_allowable_orders(vma, vma->vm_flags, + TVA_ENFORCE_SYSFS, BIT(PMD_ORDER + 1) - 1)) { skip: progress++; continue; @@ -2611,6 +2607,11 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, khugepaged_scan.address + HPAGE_PMD_SIZE > hend); if (IS_ENABLED(CONFIG_SHMEM) && vma->vm_file) { + if (!thp_vma_allowable_order(vma, vma->vm_flags, + TVA_ENFORCE_SYSFS, PMD_ORDER)) { + khugepaged_scan.address += HPAGE_PMD_SIZE; + continue; + } struct file *file = get_file(vma->vm_file); pgoff_t pgoff = linear_page_index(vma, khugepaged_scan.address); @@ -2689,7 +2690,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, static int khugepaged_has_work(void) { - return !list_empty(&khugepaged_scan.mm_head) && hugepage_pmd_enabled(); + return !list_empty(&khugepaged_scan.mm_head) && thp_enabled(); } static int khugepaged_wait_event(void) @@ -2762,7 +2763,7 @@ static void khugepaged_wait_work(void) return; } - if (hugepage_pmd_enabled()) + if (thp_enabled()) wait_event_freezable(khugepaged_wait, khugepaged_wait_event()); } @@ -2793,7 +2794,7 @@ static void set_recommended_min_free_kbytes(void) int nr_zones = 0; unsigned long recommended_min; - if (!hugepage_pmd_enabled()) { + if (!thp_enabled()) { calculate_min_free_kbytes(); goto update_wmarks; } @@ -2843,7 +2844,7 @@ int start_stop_khugepaged(void) int err = 0; mutex_lock(&khugepaged_mutex); - if (hugepage_pmd_enabled()) { + if (thp_enabled()) { if (!khugepaged_thread) khugepaged_thread = kthread_run(khugepaged, NULL, "khugepaged"); @@ -2869,7 +2870,7 @@ int start_stop_khugepaged(void) void khugepaged_min_free_kbytes_update(void) { mutex_lock(&khugepaged_mutex); - if (hugepage_pmd_enabled() && khugepaged_thread) + if (thp_enabled() && khugepaged_thread) set_recommended_min_free_kbytes(); mutex_unlock(&khugepaged_mutex); }