From patchwork Fri Aug 18 21:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13358321 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 9D809EE4997 for ; Fri, 18 Aug 2023 21:15:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B71F7940065; Fri, 18 Aug 2023 17:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2089940012; Fri, 18 Aug 2023 17:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0EAA940065; Fri, 18 Aug 2023 17:15:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 92739940012 for ; Fri, 18 Aug 2023 17:15:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 650561CA380 for ; Fri, 18 Aug 2023 21:15:40 +0000 (UTC) X-FDA: 81138482040.25.4D8392E Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf16.hostedemail.com (Postfix) with ESMTP id 89A27180024 for ; Fri, 18 Aug 2023 21:15:38 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=vSbdup0x; spf=pass (imf16.hostedemail.com: domain of 3ed_fZAcKCOQfUQKKLKMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--zokeefe.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3ed_fZAcKCOQfUQKKLKMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692393338; 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:in-reply-to: references:dkim-signature; bh=sGETMcHxX4ObOscRub16vn6iyArRP5Rx2JOMy3tD22A=; b=PNb5AJpOuO3+ZlQICX3+bmriJZk4Gw7v34QcK+377QgQrK2IZSuw19Lp2MjQsI5mfZ1WHY P3fssTGzWEEf77yJTX5XDdxDFqnMyhoQ2VVz8BCjYjKusMW/Yy62/kfU0zMPy2XpgtxX+5 ZIYU3YggOM2727NxZr/AWQAsdzRxH/M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692393338; a=rsa-sha256; cv=none; b=NnFrJaApcGUga8FXhP83ww3+aKZLx2KYGgC1TLRsM/DMmjIoSCBgTGV9FLvKFlGGKcRXf6 9NSNWMV1BOHxWpO8bY0wDveR0jzNbpcQylgQNMb0lvTL6U9tov6puo43/7KVvSDr15ZGLh nyRjwFo24Yw/L6IfwBHlXefqAO7rGJ8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=vSbdup0x; spf=pass (imf16.hostedemail.com: domain of 3ed_fZAcKCOQfUQKKLKMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--zokeefe.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3ed_fZAcKCOQfUQKKLKMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-58cb845f2f2so18170877b3.1 for ; Fri, 18 Aug 2023 14:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692393337; x=1692998137; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=sGETMcHxX4ObOscRub16vn6iyArRP5Rx2JOMy3tD22A=; b=vSbdup0x7pGjyjrNke14G4in3KiGeWdp4C7AlnPlh/Lg7LYay3noXqdk/7Gcojvnt2 L0vkg2689+eOisj9cKCuTIq+KWznoxDM5VVTukZmH0UMuIlHVqVaQqlzZm3qqllE5YDp 35IB3uNTL0gtKhwkbXm5z91LkXftDfMleqWBl0LNlWUXbWMFBdk2wyBRu6NL28gssioI HR292kurg9MD0vMGhusRI0jKaChKQiWBvE2lJSPVk8qSc9woxhc1j+AawmuwX4RjDtyi 0qY4PSqSJhHL+JqSpyoIRqVNMtHahxAiI4GvGa3cODRQkVSocnC+0/CDUaNTF6+W1Fv/ OXUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692393337; x=1692998137; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=sGETMcHxX4ObOscRub16vn6iyArRP5Rx2JOMy3tD22A=; b=LYGgz0U7TsICI3WCmu5bn3vpnskLjIu6rE43CVT3k1SYdz0wpsYLjI4zd2zGpTi/Fy 4aL7eGZdyjLqxqg8mY9jbifpROVhZzoJIL2BLvXkXs8fL2xz4yxposyKe/5X7ynm14tm ql9SCRtPan/P5P2JQJkDjzlRK+Puo6E9PYxrWsbCh10vDLX+Ilo6ocyX3WP3JmOAPQr+ W+46/pcOGQ2f93uPrbt/RJ79LEk8vUS82gm0kjqjVAgBmoLaZAsAwgWQNY32WJFc769D UmILwCFwjLc4iH8pgHWsKMNdmg0qO928wHeLaZjz9zI+Mv+MqO8c6qk3O8sj+5FLzcOS WK4w== X-Gm-Message-State: AOJu0Yz2PppZ4NLCVslL4PLPVyPQYu4Zi9KrPF5RbW4AQRdRrlb9boYT pQutQzG0t4ix+yJfK1IoFFt1mf9u356orizrAkmwWuUh81MyrwO5xL9NvdnQHYkFDDOjbS18RYz ceqmF9x6cWR7JJwsS2hVEeJ2l31tskR6tZaa4Mxagp7DRz2Yg2AvB8RxsFZo= X-Google-Smtp-Source: AGHT+IGHFmw+z6ECEaVn7NDn8YhvRcI3CTcWzU7lbkAR2EO4ibelUVluW979zggJYCVEk4uuoqNHxpwkE5el X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a81:ad0f:0:b0:58c:8c9f:c05a with SMTP id l15-20020a81ad0f000000b0058c8c9fc05amr3143ywh.9.1692393337591; Fri, 18 Aug 2023 14:15:37 -0700 (PDT) Date: Fri, 18 Aug 2023 14:15:32 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230818211533.2523697-1-zokeefe@google.com> Subject: [PATCH v2 1/2] mm/thp: fix "mm: thp: kill __transhuge_page_enabled()" From: "Zach O'Keefe" To: linux-mm@kvack.org, Yang Shi Cc: linux-kernel@vger.kernel.org, "Zach O'Keefe" , Saurabh Singh Sengar X-Rspamd-Queue-Id: 89A27180024 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: f83z5o7u3sm9aez4czmfpxqfgxhdua1c X-HE-Tag: 1692393338-64962 X-HE-Meta: U2FsdGVkX18AaKYypNqEZ6WgzPDPIZBedYmVLlC1xJMi39ivemZpH/ZUZX9plA+8zowu3SVtijhI2T8IKM9dCk5wyHdvkaBnkJUBgpzB4iWPl4OD6ko0NEOCS3Gfo/ZluvOzN971GDb4zvf3JyBR8aimCjnKTRy4y8oK46Lex24YX+PxBEuw2PldqBROZ9guCiG93RqaOllDpXeBHy2pfJUgojyY4sFY0Up56Jjxa4DkJvZTjbw4mLbRptKr4IqiXd6ZG/oBGeBP8uTQfQu5UKZ51bKK1eH9/YHx1oHgYDyKP1gJHDlAMftgT1eTFdqax7D+dn4ihhCapYnn3Y6TbAzBIVeaiE61M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/H16cVoLcTPUk+esYjmmN0+RcowZcshso8cnrpxA6VQC6QVrQrwDCuvuifzmj1DKGIjcvyeK3Rc2ya1ideua6Ei68HS2HkZEzORcG7dK/MB8lODHuU0nTpsMeEZKCKPXjk47v7+zC+Ujftk1QLSJWLAkcz4kum+oLogUE1PfVOmewRO1rdxOk6NdCAEBZWF22BXQDH5RfynAlfrXwPiPJvkjnBUhE2DZ751HQl7TsveGfxRBgbXmSWCE8Iaz9D9G9naSrWzwUsLBXb9tKCmEbmhRI7sVUtzcQR8iXnKmKh8FLTwQO5gWrQs9H79xPDMzKjoWiaxi4dje8FQQdSubG0 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: The 6.0 commits: commit 9fec51689ff6 ("mm: thp: kill transparent_hugepage_active()") commit 7da4e2cb8b1f ("mm: thp: kill __transhuge_page_enabled()") merged "can we have THPs in this VMA?" logic that was previously done separately by fault-path, khugepaged, and smaps "THPeligible" checks. During the process, the semantics of the fault path check changed in two ways: 1) A VM_NO_KHUGEPAGED check was introduced (also added to smaps path). 2) We no longer checked if non-anonymous memory had a vm_ops->huge_fault handler that could satisfy the fault. Previously, this check had been done in create_huge_pud() and create_huge_pmd() routines, but after the changes, we never reach those routines. During the review of the above commits, it was determined that in-tree users weren't affected by the change; most notably, since the only relevant user (in terms of THP) of VM_MIXEDMAP or ->huge_fault is DAX, which is explicitly approved early in approval logic. However, there is at least one occurrence where an out-of-tree driver that used VM_HUGEPAGE|VM_MIXEDMAP with a vm_ops->huge_fault handler, was broken. Remove the VM_NO_KHUGEPAGED check when not in collapse path and give any ->huge_fault handler a chance to handle the fault. Note that we don't validate the file mode or mapping alignment, which is consistent with the behavior before the aforementioned commits. Fixes: 7da4e2cb8b1f ("mm: thp: kill __transhuge_page_enabled()") Reported-by: Saurabh Singh Sengar Signed-off-by: Zach O'Keefe Cc: Yang Shi Reviewed-by:Yang Shi . --- Changed from v1[1]: - [Saurabhi] Allow ->huge_fault handler to handle fault, if it exists [1] https://lore.kernel.org/linux-mm/CAAa6QmQw+F=o6htOn=6ADD6mwvMO=Ow_67f3ifBv3GpXx9Xg_g@mail.gmail.com/ --- mm/huge_memory.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index eb3678360b97..cd379b2c077b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -96,11 +96,11 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags, return in_pf; /* - * Special VMA and hugetlb VMA. + * khugepaged special VMA and hugetlb VMA. * Must be checked after dax since some dax mappings may have * VM_MIXEDMAP set. */ - if (vm_flags & VM_NO_KHUGEPAGED) + if (!in_pf && !smaps && (vm_flags & VM_NO_KHUGEPAGED)) return false; /* @@ -128,12 +128,15 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags, !hugepage_flags_always()))) return false; - /* Only regular file is valid */ - if (!in_pf && file_thp_enabled(vma)) - return true; - if (!vma_is_anonymous(vma)) - return false; + return in_pf ? + /* + * Trust that ->huge_fault() handlers know + * what they are doing in fault path. + */ + !!vma->vm_ops->huge_fault : + /* Only regular file is valid in collapse path */ + file_thp_enabled(vma); if (vma_is_temporary_stack(vma)) return false; From patchwork Fri Aug 18 21:15:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13358322 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 0255FEE4999 for ; Fri, 18 Aug 2023 21:15:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F67E940071; Fri, 18 Aug 2023 17:15:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A73F940012; Fri, 18 Aug 2023 17:15:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24769940071; Fri, 18 Aug 2023 17:15:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0ED0B940012 for ; Fri, 18 Aug 2023 17:15:44 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C4967140831 for ; Fri, 18 Aug 2023 21:15:43 +0000 (UTC) X-FDA: 81138482166.15.2910C13 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf08.hostedemail.com (Postfix) with ESMTP id 02CDE16002B for ; Fri, 18 Aug 2023 21:15:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=JDIkLrwO; spf=pass (imf08.hostedemail.com: domain of 3fd_fZAcKCOgjYUOOPOQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--zokeefe.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3fd_fZAcKCOgjYUOOPOQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692393342; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Jem4cROi9qphCIk8SA3V6xQmrxAyRIHLARImADDaneY=; b=HXgXgiFYVCAKL0X556+tscwGjN5djGJ/HJyHWXo+QzNFuH5rIh19sqkDQ1lDYfnD+aBDwG 3Wyr7TiDCK3ipbyS+MCrSBbQUBQmL1OmRCdkrHFMJYnRL9BTWEJUKOMkjk7sfpf+oHmbhW n3rT5vlswCa3oo7qAdXKpqMp4B75Yxc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692393342; a=rsa-sha256; cv=none; b=x5P+SuIA9+waND/4tXJQjX/WqokcVwj/MiVCBBeTFTyVkPonKvo444qdc9vgo5nV5GqX20 vPdrdtopDXRMJ6RUhW6IdSYFWacgSLmhMebBib6VS4rQid8LAtRrzju2lOHhpA/iUaLUm3 xYZyNhal8z0Wiq7h9TPo/Wb/t/W5/zk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=JDIkLrwO; spf=pass (imf08.hostedemail.com: domain of 3fd_fZAcKCOgjYUOOPOQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--zokeefe.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3fd_fZAcKCOgjYUOOPOQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d62a7776f69so1551518276.3 for ; Fri, 18 Aug 2023 14:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692393341; x=1692998141; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Jem4cROi9qphCIk8SA3V6xQmrxAyRIHLARImADDaneY=; b=JDIkLrwOMLZTuos/xJL8m9DbQKbG5PZAeRI5YmFAkVnFqfqKDRmkNWTjR2ydHBchos ZwTUsGsPPeler78kiUryIeo+RZX0H/nGn4Wh1lTy4LUyNCGaMaZj2YkkUicNShAMrqN+ Mle1SCWpxQdxQYeTzmN22S1/kcb2tzw1FzKE+hwzaHLpJGsGK5HJMQOt8sXNOa3NdZr/ 9gJ5cK8ifGCDq0MEuvKm/zb4JSPPMTfG4vX4uWTt7JpEmgL2moGX7M+hCugQqZ70m/nn B5bDYj8LHyHcZw0pr5uB7dkV3BuQybQmFnu79C1Kof2qjh71mdNoj20PPf81kF/WAFRU m3aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692393341; x=1692998141; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jem4cROi9qphCIk8SA3V6xQmrxAyRIHLARImADDaneY=; b=gZEMOaMMZ9U40zWzF0OcD8ltGayW1hmZoOlwCSJ/jHMBJwoa92A1dL0c7dCHWNjgjy bh0AtDtL3JRfxRoAzxzFm+Kajuo6Iv8+oVAjZKLg8Fs2uLUQefO2jMvKtZSE3y9LURUz U9uwGZvMXImERcgXI4k4XimhBWOs6xxecPFMhwbrf0ZhXoYTQp61/+Yr6whjhryzBKV9 oqPM2yz3M0vHkVQGpwoYWnBgrNQ95Dgw8bdWfj2OGOvdcr+X+GGhLWpIxDWTyhfLW7b8 edmZyY0LoSdXVuQss63QVHf/0HCtMzar4vUFkmtClu+IisnAAvGnsj+bN+K1tCvFaPXs YQwQ== X-Gm-Message-State: AOJu0YwVo6af9waEcWH9AcYaoly+LOtEZ1axJGrQdlPBT50vVe367yuR cfpWgT6hQ+OifRzrTBHdIcxk+45N24MzIbtzoE++CU3cofhWTEg09eZwmDtsXNpS8CymXHraqK5 isXv/L0YTepja3B498orzhVOuHaLLzkUv/HSzHnjVYKoVLez7qAq1QFTAqho= X-Google-Smtp-Source: AGHT+IGRa2stsy8QZJfi6RdwZ3CiSQz8GGgelTAbogELSmuy2F7S/d9Slg4Cg25/asaaViD4egyWmEAMAlQi X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6902:290:b0:d48:c04:f256 with SMTP id v16-20020a056902029000b00d480c04f256mr3251ybh.11.1692393341040; Fri, 18 Aug 2023 14:15:41 -0700 (PDT) Date: Fri, 18 Aug 2023 14:15:33 -0700 In-Reply-To: <20230818211533.2523697-1-zokeefe@google.com> Mime-Version: 1.0 References: <20230818211533.2523697-1-zokeefe@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230818211533.2523697-2-zokeefe@google.com> Subject: [PATCH v2 2/2] smaps: set THPeligible if file mapping supports large folios From: "Zach O'Keefe" To: linux-mm@kvack.org, Yang Shi Cc: linux-kernel@vger.kernel.org, "Zach O'Keefe" , Matthew Wilcox X-Rspamd-Queue-Id: 02CDE16002B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: kx1fqke76m86xdjmcd3kyzwtnnjdybec X-HE-Tag: 1692393341-238741 X-HE-Meta: U2FsdGVkX18q6ZRAsbY9Lgv6OFTXFo/4+mOo2rdKPrVcXdUiEsfnpr3MKHouMK/iZB6LfzGzPL5DDlSoR7AZZC++3eKCGC4NoFCjwvcyxaS+4g5k1KnnEi8SM+TT4Q2k16zUgKLO2GhTJdA+gleEpZJJco/I61H3fTd1eAVwOHyMDzf0RMpVHIpO7xwGlpwXVLdEPtjermIaL+0SYeq4zfj4JTpYKKH1ZKwc8JXo7z5HxywMuke8wd1Tw5GjIkyvM9CHKUyCcNTzfd/zqh7+rcq2wTxxMKrO2pOtRb2W9AGYX1XJ3shZajRLFSxNKKCsRoJvlfpz+Dhhqz0Sw22Dk9Pirs52XSzBtfb4teUib9ISDnicB3UTuwiWkkp5rpSStyn+jrBw/bf41qQjIzzbLePY4eo07BcGzLdDd10ppyIA74u3vF5ctGE07KhbGfkTV+A5qJTfmWlXHFXYT0gn9O3wXBGbFq/9S0oeepHsGb1Lmk87tW7y1Y2QFr9HgmRe16oHzN3gIPMVxk2kRiLLo0oaLW+HaIeaP7dkWTqSEd90mUr6I7iDuH9SzTQkzt1i3uSzl2EjSkFKJBWhbxE0slG6Dx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Ts= 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: File-backed memory can be backed by THPs either through collapse, when CONFIG_READ_ONLY_THP_FOR_FS is enabled, or through fault, when the filesystem supports large folio mappings. Currently, smaps only knows about the former, so teach it about the latter. Signed-off-by: Zach O'Keefe Cc: Matthew Wilcox --- mm/huge_memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cd379b2c077b..d8d6e83820f3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -136,7 +136,16 @@ bool hugepage_vma_check(struct vm_area_struct *vma, unsigned long vm_flags, */ !!vma->vm_ops->huge_fault : /* Only regular file is valid in collapse path */ - file_thp_enabled(vma); + file_thp_enabled(vma) || + /* + * THPeligible bit of smaps should surface the + * possibility of THP through fault if the filesystem + * supports it. We don't check this in fault path, + * because we want to fallback to the actual ->fault() + * handler to make the decision. + */ + (smaps && vma->vm_file && + mapping_large_folio_support(vma->vm_file->f_mapping)); if (vma_is_temporary_stack(vma)) return false;