From patchwork Sat Dec 24 08:20:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13081311 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 AB415C4332F for ; Sat, 24 Dec 2022 08:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1301294000B; Sat, 24 Dec 2022 03:20:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E03F94000A; Sat, 24 Dec 2022 03:20:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE97594000B; Sat, 24 Dec 2022 03:20:40 -0500 (EST) 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 DF73B94000A for ; Sat, 24 Dec 2022 03:20:40 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B1A67802A9 for ; Sat, 24 Dec 2022 08:20:40 +0000 (UTC) X-FDA: 80276503440.21.4A76A07 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf27.hostedemail.com (Postfix) with ESMTP id 2E76F40006 for ; Sat, 24 Dec 2022 08:20:38 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=O2Rgjytv; spf=pass (imf27.hostedemail.com: domain of 3VbamYwcKCIA3soiijiksskpi.gsqpmry1-qqozego.svk@flex--zokeefe.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3VbamYwcKCIA3soiijiksskpi.gsqpmry1-qqozego.svk@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=1671870039; 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=ihTDH6jZHdlVGdscYLo+1J1fOC8tjCOiHkEMZL35An0=; b=y/FytUjuot4Vw/K9uPSJxrztDCeRJSdc1E2WOelQjXypDaMDDU1Wh64hxnFIvPkaocWrgF asQ0l5bIx+7FRF0X4LE5YrjC15266E7oZSXcA0vZFAov2XP1s+BAfMylneOp4+PmfbwVKQ X4wYk9iFQNT958Nw8zBanN0KU/xSuBY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=O2Rgjytv; spf=pass (imf27.hostedemail.com: domain of 3VbamYwcKCIA3soiijiksskpi.gsqpmry1-qqozego.svk@flex--zokeefe.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=3VbamYwcKCIA3soiijiksskpi.gsqpmry1-qqozego.svk@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671870039; a=rsa-sha256; cv=none; b=DX5/IWaR7Nl5Kjpf/JGhNNJ7Ggd0E5A3nRbkDNzAOPkKlnJkNuqxKqYoPh5iGUh4HLnDk4 8wqQ/hbiU0cSqV4xpB00ErszC2n0KRAKE2d/QEii5yqhQGutvLYBBSNPUfQhUQss4A66LM HVZB69YaLD9B4OzKb6IYMjI8BrUuMBs= Received: by mail-pg1-f202.google.com with SMTP id s16-20020a632c10000000b0047084b16f23so3486236pgs.7 for ; Sat, 24 Dec 2022 00:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ihTDH6jZHdlVGdscYLo+1J1fOC8tjCOiHkEMZL35An0=; b=O2RgjytvDPz+6g9CFcczLL248lQ0CKGMUUPXSrAXNh49DWEMFH6BB2Lu/8S/m1Kd7R Bbsz01ZiRT223Syp1Eh8kai1+ObucV/135HjfhH/GAAJY7X6m0MNIIp+V8920RBGR8RY ft42nde+5+lSZI87XCDPY+KcgYaQE4nB4d1mZWFmGojxerVBeU6Wi9EA+5lLrc0hezdj rTwNYEsX9FdvJGxM1T5juuxMYPYcEZ4eDajArurOQ2qOcm79cw1AWS9I0uiItkwStEHd aYL4JlQ+/BpySpoV/dNjsTPOdw2ifprcV9CU3S2243eAiX/YA4qE6bWLcOQhevfRonxY BV3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ihTDH6jZHdlVGdscYLo+1J1fOC8tjCOiHkEMZL35An0=; b=ZZXQAP5t5YJH1erWoKUirp/paGxVFeqzUIBygSGGbsCEYyfNkgu9RsJacYoFNDptX6 zWYaDLUiQaZA8InOmOKDvP0l5QyBEtFGcNU8itETdoca8/z5NU460oeRUeuVnDZo0kMD ZhaKf8HYyhhSibjxlNTiItb1kk9IvPuYeQE7DxMkNQtMsLPSsPnijKqjLUjVGgUb1Hg9 8nKKHRf8rLTLjBxe/bp+LcHE7hfHpyaNJ1K/fwNNpE9FqE/cksmC0hYUylLLEQJ4XO5q PpUqQKq/dUuyAKpD77culDnsF8219fAukgQQ9pa1P/QOYUX7GcTfEOuRLDp4++AiExF9 c/1g== X-Gm-Message-State: AFqh2koD30VcCOnAqeJOq0ifeehIqq5O5c6PWkkwSaOSwLnqYQ5SGroU o6eK3qgu4bMwtvQhr+0KnZvN5rW+VMen39updsYM9xlINvE0zd6jnDR0DT3KYv9HdPpLe+T3Num ys3XaOD2sjn+a+TivHrNf2cYLz07Q8GqaH16yxLWgUfvcml+jA1S29+gEGOQ= X-Google-Smtp-Source: AMrXdXvdFmFXW5Qb97N0QrfYVlOEyfoUEa8iHxd87AV61GPshlomzetW6kZfirXu9H1n5bGTnaw2lWu62OEO X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90b:3015:b0:219:c8d5:27d7 with SMTP id hg21-20020a17090b301500b00219c8d527d7mr1200309pjb.141.1671870037941; Sat, 24 Dec 2022 00:20:37 -0800 (PST) Date: Sat, 24 Dec 2022 00:20:34 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221224082035.3197140-1-zokeefe@google.com> Subject: [PATCH v3 1/2] mm/MADV_COLLAPSE: don't expand collapse when vm_end is past requested end From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Yang Shi , "Zach O'Keefe" X-Stat-Signature: sdfj745ot9kjks5dfqtdmppk6opuj1su X-Rspam-User: X-Rspamd-Queue-Id: 2E76F40006 X-Rspamd-Server: rspam06 X-HE-Tag: 1671870038-32848 X-HE-Meta: U2FsdGVkX181wjQoxhycyBnWlqb4EUAT7mqRYRF3qdjLshFG6EbWK/SsrQ0ETEfsz7BiXbdOAKYsmmLLFYpQxBg/MHjE5o47LFigE6TFwjQfkwyDOPWjPkTDifu3pmnnQEoM5nxPctauJtdsJLivu3WCYdLEzy13Kjc1zeylw0gjJRFL3apjFmEV4uN1LfSEFxtFStiy0Mk3ZDOBYpXfeJZtaXE+lehlErxfQuEHmNbilN4Zh9YxtnqhSPrnD52IfZSeGMc3j/6AGcl/Blutiqz2LrWO0fYa45PMF+mfVqvQdso/FEvMBtffOYLnr+y7XatVhkMdrpdfpuFi/Hu8MOJsedrj/ahWeuE4ZuBubNxfAV9L8U3TqczzOyZCu9HgNlsz8a72W9G5gQKTdZdNWMk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ence: bulk X-Loop: owner-majordomo@kvack.org List-ID: MADV_COLLAPSE acts on one hugepage-aligned/sized region at a time, until it has collapsed all eligible memory contained within the bounds supplied by the user. At the top of each hugepage iteration we (re)lock mmap_lock and (re)validate the VMA for eligibility and update variables that might have changed while mmap_lock was dropped. One thing that might occur, is that the VMA could be resized, and as such, we refetch vma->vm_end to make sure we don't collapse past the end of the VMA's new end. However, it's possible that when refetching vma>vm_end that we expand the region acted on by MADV_COLLAPSE if vma->vm_end is greater than size+len supplied by the user. The consequence here is that we may attempt to collapse more memory than requested, possibly yielding either "too much success" or "false failure" user-visible results. An example of the former is if we MADV_COLLAPSE the first 4MiB of a 2TiB mmap()'d file, the incorrect refetch would cause the operation to block for much longer than anticipated as we attempt to collapse the entire TiB region. An example of the latter is that applying MADV_COLLPSE to a 4MiB file mapped to the start of a 6MiB VMA will successfully collapse the first 4MiB, then incorrectly attempt to collapse the last hugepage-aligned/sized region -- fail (since readahead/page cache lookup will fail) -- and report a failure to the user. Don't expand the acted-on region when refetching vma->vm_end. Fixes: 4d24de9425f7 ("mm: MADV_COLLAPSE: refetch vm_end after reacquiring mmap_lock") Reported-by: Hugh Dickins Signed-off-by: Zach O'Keefe Cc: Yang Shi Cc: stable@vger.kernel.org --- v2->v3: Add 'Cc: stable@vger.kernel.org' as per stable-kernel-rules. v1->v2: Updated changelog to make clear what user-visible issues this patch addresses, as well makes the case for backporting (Andrew Morton). While there aren't any stability risks, without this patch there exist trivial examples where MADV_COLLAPSE won't work; as such, this should be backported to stable 6.1.X to make MADV_COLLAPSE dependable in such cases. v1: https://lore.kernel.org/linux-mm/CAAa6QmRx_b2UCJWE2XZ3=3c3-_N3R4cDGX6Wm4OT7qhFC6U_SQ@mail.gmail.com/T/#m6c91da3cdbd9b1d1ebb29d415962deb158a2c658 --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 5cb401aa2b9d..b4d2ec0a94ed 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2649,7 +2649,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, goto out_nolock; } - hend = vma->vm_end & HPAGE_PMD_MASK; + hend = min(hend, vma->vm_end & HPAGE_PMD_MASK); } mmap_assert_locked(mm); memset(cc->node_load, 0, sizeof(cc->node_load)); From patchwork Sat Dec 24 08:20:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13081312 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 6E60CC4167B for ; Sat, 24 Dec 2022 08:20:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDE4A94000C; Sat, 24 Dec 2022 03:20:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8E6494000A; Sat, 24 Dec 2022 03:20:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5FFF94000C; Sat, 24 Dec 2022 03:20:42 -0500 (EST) 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 9797694000A for ; Sat, 24 Dec 2022 03:20:42 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6403B160996 for ; Sat, 24 Dec 2022 08:20:42 +0000 (UTC) X-FDA: 80276503524.13.F0772C6 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf02.hostedemail.com (Postfix) with ESMTP id B886580008 for ; Sat, 24 Dec 2022 08:20:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (imf02.hostedemail.com: domain of 3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.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=1671870040; 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=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=4iQUblXAzuX9l+6sSWzUckGD+3nEnnLLCez2PZ7XVx+7LvqxbfPXzurtvSrZzjSiDwNFCP 4ke/zdU74SdVb8fTebwiwNl9HChQx4d/ocSoR88GxlO6M4DFPRSuwz3PIK+yVYqcuBlcmC mic7FBgEYGzNURYoAVmoGcIdUr54p/w= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=YIdgdTDl; spf=pass (imf02.hostedemail.com: domain of 3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3V7amYwcKCII5uqkklkmuumrk.iusrot03-ssq1giq.uxm@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671870040; a=rsa-sha256; cv=none; b=v5ZB1oXWwqIsaDRJmqy4JmrZjfGOCYYuCnvGgJmmI+joQQSAJ+08xaIe6RccCEeLY4S5We L5JKHLTJlsSNNEbiC5UMmJIxQs1XQBTxbZ5NokgyQxP/He8++7vECNLOtFveE9+fDR6ufO vQ/SD7RhntH3f7A9pbQ5uBdwppvWHdU= Received: by mail-pl1-f201.google.com with SMTP id l14-20020a170902f68e00b001926bc70048so316727plg.2 for ; Sat, 24 Dec 2022 00:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=YIdgdTDlm/0rnNXmV/Ouxem7vSavubkjE/mlXtu3l2VNJp+VcHRwcxAqLRlRCht33T RjLRwnMH+83r29SKKJIBeQCmhsdRiiPnHm5RybHePQWkJtrnUBA8wvZoTReit57ZSQgj rb79t5GaIQFUYM+TelnB/YDfk3efw2LoXwE83oTT7NsNN0yVZUilRddaPER0eHid1zOn rFXxu33AQ1X9TIKISEarvlDOHXaIVzVHkuQDAvEdPao9/mUtIRnGOziez9pbYJtslSrk 9oofFPc8G704Z1XNJl+3ESz0Xb773tj4avam3C858QsEl+9wi5oCzl9RAxGV4CrpOS/U Na7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qHBgmM5FyY8tFESb+UZtZ7YHBNCfgMkVXvmSjVkn95c=; b=epxtoVmfFDS5JyuDyg9PB4zEo+AGOiClTmajMgqVZbs/S0oue/zXZjUXBZeLwSJRJi PANRMVnboa0vZjgr2P6qh/ymW+aLiIPZG9CXpv1B1hpwbBgv5O+A4MNm07oGA6dhXPr6 Mh3z69y2p5Dpb5i32uXr+9ccBlOEZCL/2xR5euyFubxwFM54J4R0aNDsDiUkkrUMgAI+ tjXWQ4UR0SMlAWrcBK/wjGc5xw/d4dFzixjTKTXfG4ZZIgTCEOodgMJHB5jEVVWfDQAI Vij9Fbnj8lzAjJGYUB2dIsi//UzZsjFNxfz/9Jx4Zr2MhvZAWFnzwUPOGv/eLp2ddlxE yJIg== X-Gm-Message-State: AFqh2koycrae1PO8TlMgxh8w/Ai+RajwEZ0hGQGmS9yiqyO+4TpBZJ56 Bi5se6I8hEBMRI+FAzpp9UlH1SL5h637hyDBR9EKS6F1j02l5KVEkCr//pk0PfdqLp5oPV4zqLV PaAtaRoQLOpCsuiBrskj65yLajKChvplaSO3QtJC/FJIsW03l0XSFfR7us0I= X-Google-Smtp-Source: AMrXdXtpnA9oa+kcg8UCtzsH2+zbPi8cE8h5FFqA3g8bAXygXEp5KA+R6LlQvnatJIrsuUCVCjwgqNmjUsVJ X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90a:f018:b0:21a:150d:fe63 with SMTP id bt24-20020a17090af01800b0021a150dfe63mr1313517pjb.73.1671870039401; Sat, 24 Dec 2022 00:20:39 -0800 (PST) Date: Sat, 24 Dec 2022 00:20:35 -0800 In-Reply-To: <20221224082035.3197140-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221224082035.3197140-1-zokeefe@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221224082035.3197140-2-zokeefe@google.com> Subject: [PATCH v3 2/2] mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE From: "Zach O'Keefe" To: linux-mm@kvack.org Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , Yang Shi , "Zach O'Keefe" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B886580008 X-Stat-Signature: hhmehhn8tts9xwizjqgwgud1botctd5a X-Rspam-User: X-HE-Tag: 1671870040-516118 X-HE-Meta: U2FsdGVkX18fy4FJOYE9Wv+C8jn0ozZLXPwr2RN0fAX9CoLuEG5DquVu4MbHMN+eAa8w5QRDl61Sw752gGADSHaC+364otLjwnFPE39G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xNtXSdqBBnMLUfG2E9bKYT5kvfDfuq82r/M7VJsz98WlpWGHw1Cqx9sd37dyLbb9+Nk3tWWUbHbpuwzfZoj4Up6lq5kofHa1QNkmLrtT0zE8hqvACpYAjq3n+3MDAg5HKar4OPmlDHg3LjOvPwzGad0DkN04CRdYpJm0tkngGjwToH95FagJ8OblNUhytWrbLQCj08sHoCDoC0PSYr+2b+86B 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: SHMEM_HUGE_DENY is for emergency use by the admin, to disable allocation of shmem huge pages if, for example, a dangerous bug is found in their usage: see "deny" in Documentation/mm/transhuge.rst. An app using madvise(,,MADV_COLLAPSE) should not be allowed to override it: restore its precedence over shmem_huge_force. Restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE. Fixes: 7c6c6cc4d3a2 ("mm/shmem: add flag to enforce shmem THP in hugepage_vma_check()") Suggested-by: Hugh Dickins Signed-off-by: Zach O'Keefe Cc: Yang Shi Cc: stable@vger.kernel.org --- v2->v3: Add 'Cc: stable@vger.kernel.org' as per stable-kernel-rules. v1->v2: Update changelog, and add note explaining rationale for backporting (Andrew Morton). Request to backport this to 6.1.X stable. We'd like SHMEM_HUGE_DENY to take precedence over MADV_COLLAPSE. If we make this change later, it will be a userspace API change. As such, 6.1 cannot be allowed to continue as-is, and we should fix up the code there. --- mm/shmem.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c301487be5fb..0005ab2c29af 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -478,12 +478,10 @@ bool shmem_is_huge(struct vm_area_struct *vma, struct inode *inode, if (vma && ((vma->vm_flags & VM_NOHUGEPAGE) || test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags))) return false; - if (shmem_huge_force) - return true; - if (shmem_huge == SHMEM_HUGE_FORCE) - return true; if (shmem_huge == SHMEM_HUGE_DENY) return false; + if (shmem_huge_force || shmem_huge == SHMEM_HUGE_FORCE) + return true; switch (SHMEM_SB(inode->i_sb)->huge) { case SHMEM_HUGE_ALWAYS: