From nobody Wed Oct 8 07:12:43 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 E96141DF96F for ; Wed, 2 Jul 2025 06:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751436105; cv=none; b=k+mxrEYZnsRj4BWBLkOaUKFGnKMRF3pmIPZlpYLTVW/VqEvrl6uWCG4tAWJT10Ookpg0MtSybBbrek8m6fGvzhLc4rSUjHI776TjqzXXcujtIRvuBBIjGVyCd0GN53B6S8Fl/qpL+w1ZsSWXaKLEZTowXhqjdOyeaN0peLr3h4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751436105; c=relaxed/simple; bh=PCz1XiVA+FkwVn8JcYxuVc66+H9tb0XXfMn1uyb/VJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M5WcqW3PW5IkfQoqyoO6su/c+lvuwS63bzKmqGAYtKbv63yDpPpBbTvo0YTVpjZPrbYETeierOzCHce9H4oNUbLvqnTfcK21ag9NPVKKyeoz+5HQbEK0yc0Djiyma7NSZ9xgYW6EEhfkES0XlBFOtydLynNrqaOWYmfVkOTZeUo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=PW86EjYH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PW86EjYH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751436103; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5nTPrWf9Aqck2ptKb2zyXs5vzzOQnB/G54DtwX2rrW0=; b=PW86EjYHgT9SMSQwBEmroumFdd1o+Ld6yp6ACH7ZTVDXdRawtYeHDws0fI6q/BdjUcdlcu 4XfmpxV4QkrciA+r4d16f96DobUxPjZKOfLprTbh2ke3oWGHW5GSWKbmkizdkCix0szJO9 pKW0Z7lYdu04OXxwPkE3fKB+33YWOxs= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-aYZuKyN1MwOe2pokc-BKxA-1; Wed, 02 Jul 2025 02:01:38 -0400 X-MC-Unique: aYZuKyN1MwOe2pokc-BKxA-1 X-Mimecast-MFC-AGG-ID: aYZuKyN1MwOe2pokc-BKxA_1751436094 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 259231809C8B; Wed, 2 Jul 2025 06:01:34 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.112]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9ED7F18003FC; Wed, 2 Jul 2025 06:01:19 +0000 (UTC) From: Nico Pache To: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: david@redhat.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, dev.jain@arm.com, corbet@lwn.net, rostedt@goodmis.org, mhiramat@kernel.org, mathieu.desnoyers@efficios.com, akpm@linux-foundation.org, baohua@kernel.org, willy@infradead.org, peterx@redhat.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, 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 Subject: [PATCH v8 12/15] khugepaged: kick khugepaged for enabling none-PMD-sized mTHPs Date: Tue, 1 Jul 2025 23:57:39 -0600 Message-ID: <20250702055742.102808-13-npache@redhat.com> In-Reply-To: <20250702055742.102808-1-npache@redhat.com> References: <20250702055742.102808-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" From: Baolin Wang When only non-PMD-sized mTHP is enabled (such as only 64K mTHP enabled), we should also allow kicking khugepaged to attempt scanning and collapsing 64K mTHP. Modify hugepage_pmd_enabled() to support mTHP collapse, and while we are at it, rename it to make the function name more clear. Signed-off-by: Baolin Wang Signed-off-by: Nico Pache --- mm/khugepaged.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6ea681b81647..d20a217387ed 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -430,7 +430,7 @@ static inline int khugepaged_test_exit_or_disable(struc= t mm_struct *mm) test_bit(MMF_DISABLE_THP, &mm->flags); } =20 -static bool hugepage_pmd_enabled(void) +static bool hugepage_enabled(void) { /* * We cover the anon, shmem and the file-backed case here; file-backed @@ -442,11 +442,11 @@ static bool hugepage_pmd_enabled(void) if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && hugepage_global_enabled()) return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_always)) + if (READ_ONCE(huge_anon_orders_always)) return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_madvise)) + if (READ_ONCE(huge_anon_orders_madvise)) return true; - if (test_bit(PMD_ORDER, &huge_anon_orders_inherit) && + if (READ_ONCE(huge_anon_orders_inherit) && hugepage_global_enabled()) return true; if (IS_ENABLED(CONFIG_SHMEM) && shmem_hpage_pmd_enabled()) @@ -490,7 +490,7 @@ void khugepaged_enter_vma(struct vm_area_struct *vma, vm_flags_t vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && - hugepage_pmd_enabled()) { + hugepage_enabled()) { unsigned long orders =3D vma_is_anonymous(vma) ? THP_ORDERS_ALL_ANON : BIT(PMD_ORDER); =20 @@ -2702,7 +2702,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned = int pages, int *result, =20 static int khugepaged_has_work(void) { - return !list_empty(&khugepaged_scan.mm_head) && hugepage_pmd_enabled(); + return !list_empty(&khugepaged_scan.mm_head) && hugepage_enabled(); } =20 static int khugepaged_wait_event(void) @@ -2775,7 +2775,7 @@ static void khugepaged_wait_work(void) return; } =20 - if (hugepage_pmd_enabled()) + if (hugepage_enabled()) wait_event_freezable(khugepaged_wait, khugepaged_wait_event()); } =20 @@ -2806,7 +2806,7 @@ static void set_recommended_min_free_kbytes(void) int nr_zones =3D 0; unsigned long recommended_min; =20 - if (!hugepage_pmd_enabled()) { + if (!hugepage_enabled()) { calculate_min_free_kbytes(); goto update_wmarks; } @@ -2856,7 +2856,7 @@ int start_stop_khugepaged(void) int err =3D 0; =20 mutex_lock(&khugepaged_mutex); - if (hugepage_pmd_enabled()) { + if (hugepage_enabled()) { if (!khugepaged_thread) khugepaged_thread =3D kthread_run(khugepaged, NULL, "khugepaged"); @@ -2882,7 +2882,7 @@ int start_stop_khugepaged(void) void khugepaged_min_free_kbytes_update(void) { mutex_lock(&khugepaged_mutex); - if (hugepage_pmd_enabled() && khugepaged_thread) + if (hugepage_enabled() && khugepaged_thread) set_recommended_min_free_kbytes(); mutex_unlock(&khugepaged_mutex); } --=20 2.49.0