From patchwork Fri Oct 11 10:24:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13832342 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 894ECCFD316 for ; Fri, 11 Oct 2024 10:25:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2124C6B00AD; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C4646B00B1; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08A2B6B00B2; Fri, 11 Oct 2024 06:25:09 -0400 (EDT) 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 DA3BE6B00AD for ; Fri, 11 Oct 2024 06:25:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DEA1FABEB2 for ; Fri, 11 Oct 2024 10:24:59 +0000 (UTC) X-FDA: 82660938654.03.34219CF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 44A3920008 for ; Fri, 11 Oct 2024 10:25:04 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YRvUPBv9; spf=pass (imf13.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=1728642262; 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:dkim-signature; bh=VMssNf1Ju+sw1bhZpq8lk0Jjp7pzX4VBi27YvpYNCzI=; b=il6uSUCm2yEbEIg5rT8TkvdN+lBF8pQTDBK/nBRDFpEYRfE6nweWmeDR8fZUYgR5gbbRsc MwUDOBkOy/Z/DWCCgRngh5zXohT1FcFg69d6Mc2/6kvHayfMrpf8Tgv496WAso0Y392OLu SKHF43xwNReSEi6AnAmax0C0LQorfLI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YRvUPBv9; spf=pass (imf13.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=1728642262; a=rsa-sha256; cv=none; b=EyEkGvduErOm69SxSByvrNCr+JNH0w9dr1cbab9FrnSn39oqGQjWoHiRUcZvij7FnAqdmw OBq1c0f1zwQ3q6s1K3Wh4TygYOGLABLdxTaBc4a7hBhYG6WgXAWKjSiKbceNMBcKG9EM29 BDAJB+en1ERxTZFZ/KewvW0Gi0HQy+M= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728642306; 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=VMssNf1Ju+sw1bhZpq8lk0Jjp7pzX4VBi27YvpYNCzI=; b=YRvUPBv9zP5NMDpejjomNmR8r4LWaBnl4hx2xdYhybq1yXwbBzJAAvDVDDvZWain3vUsMm UPNLH0Z70dRXJ812Ol179ZWeXUh9jGgAnyJFIJyl/6aDxQxCKF6tMFKV2c1KY+4nhE5285 LKVIvTg0BRgGetUilkIeSRDcILzjRaM= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-pXT2G1CgOGWkQX4PSZq0Wg-1; Fri, 11 Oct 2024 06:25:00 -0400 X-MC-Unique: pXT2G1CgOGWkQX4PSZq0Wg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4D2C11955F07; Fri, 11 Oct 2024 10:24:58 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B6E91955F42; Fri, 11 Oct 2024 10:24:52 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kvm@vger.kernel.org, David Hildenbrand , Andrew Morton , Hugh Dickins , Thomas Huth , "Matthew Wilcox (Oracle)" , Ryan Roberts , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Kefeng Wang Subject: [PATCH v1 1/2] mm: huge_memory: add vma_thp_disabled() and thp_disabled_by_hw() Date: Fri, 11 Oct 2024 12:24:44 +0200 Message-ID: <20241011102445.934409-2-david@redhat.com> In-Reply-To: <20241011102445.934409-1-david@redhat.com> References: <20241011102445.934409-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Stat-Signature: 8s5n6h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QX63b06zioOmRRX0LWHRIXoit+xEasWBZf22vmpWxAwnIAIBEWW30LFE9mC6wIBizyiuANbOAFS/QUQaH859N8DXpaAnxuBLEO2SizWsRTSQjaUHO21IbQSVDtI5WsFfllv+vYD3FLsFlAPq+iwujRZ/KqgJsVQJtO8K9sndBTV0/CdBnWndZd4MZQ1n2EkPwnAGOKuZNm+S5m1NzMNIuaAbszoY8N3Wxdo+NDO/6MRc/wdjbEn2PfJtAi/mgAc+pKk8PGaDLsKPyYivEwSGo6LXBJT8BNaXsGLfMzK866hte1q16PzbpJrq3mxglHmBzr/ZYriP05Kwp18zW1rXU63DouCNgb+qydysIRqj77lVnOL2guLG/3CiRb9ppYb8LNRZC1qUXks= 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: From: Kefeng Wang Add vma_thp_disabled() and thp_disabled_by_hw() helpers to be shared by shmem_allowable_huge_orders() and __thp_vma_allowable_orders(). Signed-off-by: Kefeng Wang [ rename to vma_thp_disabled(), split out thp_disabled_by_hw() ] Signed-off-by: David Hildenbrand Reviewed-by: Ryan Roberts --- include/linux/huge_mm.h | 18 ++++++++++++++++++ mm/huge_memory.c | 13 +------------ mm/shmem.c | 7 +------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 67d0ab3c3bba..ef5b80e48599 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -322,6 +322,24 @@ struct thpsize { (transparent_hugepage_flags & \ (1<vm_mm->flags); +} + +static inline bool thp_disabled_by_hw(void) +{ + /* If the hardware/firmware marked hugepage support disabled. */ + return transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED); +} + unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long addr, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 87b49ecc7b1e..2fb328880b50 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -109,18 +109,7 @@ unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, if (!vma->vm_mm) /* vdso */ return 0; - /* - * Explicitly disabled through madvise or prctl, or some - * architectures may disable THP for some mappings, for - * example, s390 kvm. - * */ - if ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return 0; - /* - * If the hardware/firmware marked hugepage support disabled. - */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_disabled_by_hw() || vma_thp_disabled(vma, vm_flags)) return 0; /* khugepaged doesn't collapse DAX vma, but page fault is fine. */ diff --git a/mm/shmem.c b/mm/shmem.c index 4f11b5506363..c5adb987b23c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1664,12 +1664,7 @@ unsigned long shmem_allowable_huge_orders(struct inode *inode, loff_t i_size; int order; - if (vma && ((vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) - return 0; - - /* If the hardware/firmware marked hugepage support disabled. */ - if (transparent_hugepage_flags & (1 << TRANSPARENT_HUGEPAGE_UNSUPPORTED)) + if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; global_huge = shmem_huge_global_enabled(inode, index, write_end,