From patchwork Sat Dec 24 08:12:02 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: 13081291 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 0E2B1C4167B for ; Sat, 24 Dec 2022 08:12:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33122940009; Sat, 24 Dec 2022 03:12:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E14B900004; Sat, 24 Dec 2022 03:12:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A8F2940009; Sat, 24 Dec 2022 03:12:20 -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 0A9FC900004 for ; Sat, 24 Dec 2022 03:12:20 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 529AE809E6 for ; Sat, 24 Dec 2022 08:12:18 +0000 (UTC) X-FDA: 80276482356.14.5922E4C Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf03.hostedemail.com (Postfix) with ESMTP id C137C20008 for ; Sat, 24 Dec 2022 08:12:16 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KvJVzUtz; spf=pass (imf03.hostedemail.com: domain of 3X7SmYwcKCIY9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3X7SmYwcKCIY9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@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=1671869536; 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=CLNnJd70ppyA/NycQ0X3RpMhQCUPbfoR/CeGZ2SECtc=; b=WIYjLrnit9Rmd92PKybwjVXayiEjGakn91QwzTKi98089uPYczv6ozH0AhnLb8m6QPu6Nl QhlY3h1IkijMJVNSPHYTZKMxJB2V5bP85u6Jk+Ca2oMWM2RhXK7dMpE6OYm+TADT2yZdNq kItbppGDoeVeIqusDSZ9lnvFUi7Oerw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=KvJVzUtz; spf=pass (imf03.hostedemail.com: domain of 3X7SmYwcKCIY9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3X7SmYwcKCIY9yuoopoqyyqvo.mywvsx47-wwu5kmu.y1q@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671869536; a=rsa-sha256; cv=none; b=78hNGZcPb8XbTUYGh7eW/W24YO3FzCwbQkWLH0lQn88cvBeYCeliM22Z+7DR9O28c3dwuP Q2jQ2wCSJDBCNLEB/OdVsUk723qOiw+koev8fWKlcQ2ktq/A25NzXo5VMAzyOXseiFVEqi 5r9pUwI6Jn8r/NpLqPA4kH+v3freOMM= Received: by mail-pl1-f202.google.com with SMTP id o5-20020a170903210500b0018f9edbba6eso4806792ple.11 for ; Sat, 24 Dec 2022 00:12:16 -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=CLNnJd70ppyA/NycQ0X3RpMhQCUPbfoR/CeGZ2SECtc=; b=KvJVzUtz4kTrA5zSMYZsEaF5rzMBMjUkNdUpmskBApF6t9+qSaYHK35X8ZMt7v36Va TiOrYOTKQS+jN5D9i7C+qkRZ3j0fulIHp72+Uc328W/QtqOseEMLXqvEfy9tf6Jemgg9 aR2dN1MvkwRKrALxrMBa50w7wHDzxmZbGJTXfWY8snWJ7yZO81TKhba1pp1Z1GyYVyZv 25si/eIHF48gJEGGDDO/Pw24iQWOgduzQY6FY2yGjdRJvQkhz7YR3+LsX5BkI0vnYkJy 6+p6ss7S7BcyxnCJFmie3egThN21Rwq7OUUrgGzL2zr/81XUjihHEiiq8Uy1h/y6s6kt yKmA== 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=CLNnJd70ppyA/NycQ0X3RpMhQCUPbfoR/CeGZ2SECtc=; b=UatxHeJaOH0XvVLztxtFnrQwpA9nd50PjsoQvQnJjV4U7BG8R5woBAk8gppWu1GYHd VA5maAA+yz35jCw3TnKgpgo8jMxYV+r0UZmCUQGG4X4AtpfwCC4CZQCn0+qhdXKaEmDZ cGJL2aIv7tk2OxRCHQ+jIAd1AEtvYPjwvPrie5EoASdPAqrWqx0VW67mK9X+k6ZrecQV HLw4TK45oG/8Mq5Fb525IoaHR9xfDPYjfBUThjWTemrcFT3KiA7EGEpkFM8pNkEpfd61 X1svFA9Gr9xdYVgboOVAnb9TtzZHn0YciIetDROXgeHj0rhhZJDMLTkZONfeT84iRR8Y sdyw== X-Gm-Message-State: AFqh2kqOR+ceYibgSUDCQO3XLqK5Dm+SwUDIhRn7BMY5lwGY9XaWG0Jq gbEnFatOTwjnfD4mutrdpAmxgifpJVer4pBoFxFtll9V7g7IjjbMDIrgLlQmtgByDDPwaO4VoVw FHx2CzkPHkp3cnVqiarkd+XWgOXojxRT06lJ8DvKNXzlLM9PxbMdtOoAWlAw= X-Google-Smtp-Source: AMrXdXvlobVQR1nR7URHxL5LDAGlAhiApaUyxcnX2240pREAOBx3+kodfs1Ymkh1gJJFeZfRR/8gHJLc9Tyc X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:ce06:b0:188:fd3f:cb06 with SMTP id k6-20020a170902ce0600b00188fd3fcb06mr614142plg.23.1671869535430; Sat, 24 Dec 2022 00:12:15 -0800 (PST) Date: Sat, 24 Dec 2022 00:12:02 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221224081203.3193960-1-zokeefe@google.com> Subject: [PATCH v2 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C137C20008 X-Rspam-User: X-Stat-Signature: jnqwsroohmiwn484e7oxcny4f1j4cpqk X-HE-Tag: 1671869536-942243 X-HE-Meta: U2FsdGVkX19XYve38/EYS9MXCPCJVuCDyhAgOQCIZH/K6TpjwKTtxHiCV9rWYIb6wj1gdkTqffEd1gLRZpR9NqI0jvl7pYA4VTLPhLvgB/IUQf0C6vwEU6JqXEXO8ElTPK6zNTXkmpS9ea+BQ5qI7Jv8PT9BmO2zxfiYF5llsYNxbZSgz1coexAq6okf+3RXGwo72zkbGI6fqAE0WeL+WjdpwxNb09Wgf45qN4Gbd9fbkuNQOqi4M11yg2NNlIHQc+uGWsD2gPFzeElfGaRQtJ2XHfoCAdrqnfIWVoAKeoBKohtIN13S8A9eioCxVWmeML1+wBP8kSwqcCCW0NcDl+EgCL/xO7h/Dngi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1.2.4 Sender: owner-linux-mm@kvack.org Precedence: 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 --- 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:12:03 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: 13081290 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 6C3FAC4332F for ; Sat, 24 Dec 2022 08:12:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0F72900004; Sat, 24 Dec 2022 03:12:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9983294000A; Sat, 24 Dec 2022 03:12:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86047900006; Sat, 24 Dec 2022 03:12:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 79ECB900004 for ; Sat, 24 Dec 2022 03:12:21 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4D70BC0691 for ; Sat, 24 Dec 2022 08:12:21 +0000 (UTC) X-FDA: 80276482482.27.A6EDC9B Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf19.hostedemail.com (Postfix) with ESMTP id B7A2D1A0005 for ; Sat, 24 Dec 2022 08:12:19 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IQNrJhCR; spf=pass (imf19.hostedemail.com: domain of 3YrSmYwcKCIkC1xrrsrt11tyr.p1zyv07A-zzx8npx.14t@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3YrSmYwcKCIkC1xrrsrt11tyr.p1zyv07A-zzx8npx.14t@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=1671869539; 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=ItQBUrV0EvZiYOjtPn9RtcHJwdM5uCOC63vNEO/Cgn4=; b=Edv0MGTxm6BGH7Y782wij5RARDSeLpudycqM5DQmoIeMwXcVHwSvqe0IUND6tndOYeJc0m YafhI+y3qV+4Kj94P781H/zylx0OaG6d2J24qySheMmU4br/uBCiQQwrf32RfMygFpVm1m Imp6Ak7PVeYc1kk+xxJNNAygkokO4tw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=IQNrJhCR; spf=pass (imf19.hostedemail.com: domain of 3YrSmYwcKCIkC1xrrsrt11tyr.p1zyv07A-zzx8npx.14t@flex--zokeefe.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3YrSmYwcKCIkC1xrrsrt11tyr.p1zyv07A-zzx8npx.14t@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671869539; a=rsa-sha256; cv=none; b=Ao25tfH9PDIWhMETq2sLCRGcB2X4sScwDO2eMhcI4HHdQsgMVhEnoMwDqR6q9j1ai0Jm36 URuFz9OxdbKK0lagGM4DOnUTiAm0w5h/cU6M20fplqazJkdFtcVe6qLqdgApsXEF1p6fPj 0QXkVXSVDXPSr6sThogpnQ+CF96lLp8= Received: by mail-pf1-f202.google.com with SMTP id cp23-20020a056a00349700b005775c52dbceso3604327pfb.21 for ; Sat, 24 Dec 2022 00:12:19 -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=ItQBUrV0EvZiYOjtPn9RtcHJwdM5uCOC63vNEO/Cgn4=; b=IQNrJhCRWbch37b0zxiQ63klwB/GGCz0T3Ti+BnTbJFnWDAuKxZuxygKiPLeM+O0AR w/T2lFf+mrPfJE/QEm2dA04gLVnrUB0sjvh4mOGQ0L26Qki+z+qwi+gk41DAtyORCPyd xTjFieSO7GBH4ut5SB0J3jEXfQ7FMh3pxSwPoz/OHCGFw8TSmZKZxwP/JCiLOnektegW Vmxhwp1NU8QaK6s+ZiVaZ0vSUG4se+Ch/6vOTg54/jZg8pz+Dwnszf0rzMCW3udUjA4S 5zQdWNFo64+OlvLPScP5CEMif/f89OuQZi8ioPTgb23fkNwP4zciNWW7SJXWpZ/mQDF8 0MUQ== 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=ItQBUrV0EvZiYOjtPn9RtcHJwdM5uCOC63vNEO/Cgn4=; b=x0VuWjVrIVE3qzYFxfwq35rETIjdURmQlAVAcHp59qEbjrlq/k8RhtUZYc1G6jpjF0 im/olcYYGuMvagfT2Gd0HnCd7/eC4HPYmEajD4mZVjaDGBVNDizldM/IsY5UpNzBiVJN JYJiglLssAEcBmhDmKizCa63/L4e+nZdRYZfXDngOCDk25H927eU+jtn0e6zHt39ZQHR JfsrF31Ed1/UE4Xfv6cKi1wF9VVeMxpkzi5lUapylVo71s/j3XMCSmcBfBm8MEVilESt FJQ/y5ENOb3oX5TfjNCaq3Jh98lPgKdmgbgZeQnYxhGRDLOs46ltEi7rVWXRaBfOMfgN ED0A== X-Gm-Message-State: AFqh2kpyP/IPZGzj5hWFUIg0xM2HPXy6PsyD3SYpvoYDnRC3Wd1ucj4d +yZHCINW95HoMvZW3NcCclUT7gQG8yfKo59jiqdWMPZZ7In6JMM/zfaTPJHN6JRfoGKgVp4lHta aaifk0vakTpJ0/RnRVb3tkbDiFVMyibKCeZldL61T/IOVcFG+rKsLUcTJ9Ck= X-Google-Smtp-Source: AMrXdXsO97Tf6V+s4D4bpX/S6mjRj56+jxyaaHemqoaz8G5Nwc8Bqz8Sa7QxAErbsdzR57ehavEIxWJ9q3OD X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:c10a:b0:189:cf7a:b564 with SMTP id 10-20020a170902c10a00b00189cf7ab564mr893175pli.8.1671869538392; Sat, 24 Dec 2022 00:12:18 -0800 (PST) Date: Sat, 24 Dec 2022 00:12:03 -0800 In-Reply-To: <20221224081203.3193960-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221224081203.3193960-1-zokeefe@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221224081203.3193960-2-zokeefe@google.com> Subject: [PATCH v2 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: B7A2D1A0005 X-Stat-Signature: quk9r9ssfb43tr9obydhuqeho3adri3s X-Rspam-User: X-HE-Tag: 1671869539-315411 X-HE-Meta: U2FsdGVkX19f4D8cQorEjo9kjesD/hzjw/aBgzKFaJecz08Jb9JFTczOLThncdmoz7E3vIyhisvobx6sDZZYaoSRteNbUUySRZ7st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oSUwsWYkR/yL5iTxUTw2OXLJyhkV1VCmJYB99bnLARTVYM+xAa59sRldLKHH2oryaTbCwlbFfMKuLntvOsu2ARO7LDwNrssnIzHWGmE9NyX209xLatyWikT3zyjCVyWSZre2uAKu/+tP9H1IFDl9MBqMMlZW+fPwhqAwAYh8wqP1pfwiiqsurFycDCyby6bmFW5rebqg7fvm2SE70Mors6XqLMWp4Cad6bYo2QYnigv 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 --- 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: