From patchwork Tue Aug 17 08:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12440831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC327C4320A for ; Tue, 17 Aug 2021 08:14:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88FE460F22 for ; Tue, 17 Aug 2021 08:14:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 88FE460F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 220F96B006C; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CF9A6B0072; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 097286B0073; Tue, 17 Aug 2021 04:14:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id E07876B006C for ; Tue, 17 Aug 2021 04:14:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 91772181AC544 for ; Tue, 17 Aug 2021 08:14:33 +0000 (UTC) X-FDA: 78483860826.12.0C70D28 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf09.hostedemail.com (Postfix) with ESMTP id 477C13005530 for ; Tue, 17 Aug 2021 08:14:33 +0000 (UTC) Received: by mail-qt1-f177.google.com with SMTP id x5so7942089qtq.13 for ; Tue, 17 Aug 2021 01:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=DbxPYfIkUPggZAsAtUCUkg6hl6OjGtFlTtB9svwXDrQ=; b=MDYcRkXC9AzT6oic9Y7EK7P1oSIPrdRZWVwOjHsGLa0HsxCTUKzB+DS0sGLQjGY/9S e8e61iUUn8EsNT83aYltwJUcWEOHDUw/LXFBiZ453w5uthUmSUmdnFQbljDGEUQ9IbUt i2Ga/mi050hZMvUnlMdgWb4cjPD2weaNZUWBLmfKuUQ0JbseitjMlkdmG0Ecuq3Q7G9c TtWRWYq0W1t9gmpAABN+fQEqNoBoBZ/A1ozRzCbtl6t09dVevv0k1Uyt5gqORKWINAcn 0WsBBncQjV0O+CFNnf3eEuLfDDwXo15Bno8lhGwndXWjNXHHbLiIhoCmij6Et44IbzLx CbfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=DbxPYfIkUPggZAsAtUCUkg6hl6OjGtFlTtB9svwXDrQ=; b=ugyaD4/YECbandJucaNc3qyDDC9AfMZ2XDpcD/X/t6w2fsYzpxdF9t61AkSpMhp80O ex2Q9uFz58VGgPEhfo2WRUCwUb8YUQ/EQFYmgYCqhu3/RwCcsxUmsjsuXvb90gzuvLPa mwp1Tkmtj5ivxknf20VN/v9JMkE2l67IkH3KuaAyd8a0ZWZDwfZy4ah1q9qK3GReDoIV 8FLJqepOAf2Trq5TL7XrzeNHC3FWni4A1qG/QIYMoOJR4bzRjAgNYnnAhlmPloxTcb/e VG2Vq4NQAcf0IEgmhqZH9nIRkjZEcu/QGrk3EYiVC5PSxhr1335zYyGqfOPIVcHojY9K co5A== X-Gm-Message-State: AOAM532an/EThyRz7ik5IB7l4w53tX7X09otRUwk4dNoCaM6RgIQ2G5S Sddb7mOE23swUZM9vFyzuMYMSQ== X-Google-Smtp-Source: ABdhPJzvjRKbcrqPoj6rWq+pXSIKfeRz0vrhFSmbk/werhszUnq0bvTCdRv0bGfj0WZ24e/T5B6N3Q== X-Received: by 2002:a05:622a:255:: with SMTP id c21mr1947762qtx.128.1629188072480; Tue, 17 Aug 2021 01:14:32 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x21sm891928qkf.76.2021.08.17.01.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 01:14:31 -0700 (PDT) Date: Tue, 17 Aug 2021 01:14:29 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Shakeel Butt , "Kirill A. Shutemov" , Yang Shi , Miaohe Lin , Mike Kravetz , Michal Hocko , Rik van Riel , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/9] huge tmpfs: move shmem_huge_enabled() upwards In-Reply-To: Message-ID: <16fec7b7-5c84-415a-8586-69d8bf6a6685@google.com> References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 477C13005530 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=MDYcRkXC; spf=pass (imf09.hostedemail.com: domain of hughd@google.com designates 209.85.160.177 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: xthhday5cnmrshz178x6mis5cq6x6ud8 X-HE-Tag: 1629188073-912662 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_enabled() is about to be enhanced into shmem_is_huge(), so that it can be used more widely throughout: before making functional changes, shift it to its final position (to avoid forward declaration). Signed-off-by: Hugh Dickins Reviewed-by: Yang Shi --- mm/shmem.c | 72 ++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c6fa6f4f2db8..740d48ef1eb5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -476,6 +476,41 @@ static bool shmem_confirm_swap(struct address_space *mapping, static int shmem_huge __read_mostly; +bool shmem_huge_enabled(struct vm_area_struct *vma) +{ + struct inode *inode = file_inode(vma->vm_file); + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); + loff_t i_size; + pgoff_t off; + + if ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false; + if (shmem_huge == SHMEM_HUGE_FORCE) + return true; + if (shmem_huge == SHMEM_HUGE_DENY) + return false; + switch (sbinfo->huge) { + case SHMEM_HUGE_NEVER: + return false; + case SHMEM_HUGE_ALWAYS: + return true; + case SHMEM_HUGE_WITHIN_SIZE: + off = round_up(vma->vm_pgoff, HPAGE_PMD_NR); + i_size = round_up(i_size_read(inode), PAGE_SIZE); + if (i_size >= HPAGE_PMD_SIZE && + i_size >> PAGE_SHIFT >= off) + return true; + fallthrough; + case SHMEM_HUGE_ADVISE: + /* TODO: implement fadvise() hints */ + return (vma->vm_flags & VM_HUGEPAGE); + default: + VM_BUG_ON(1); + return false; + } +} + #if defined(CONFIG_SYSFS) static int shmem_parse_huge(const char *str) { @@ -3995,43 +4030,6 @@ struct kobj_attribute shmem_enabled_attr = __ATTR(shmem_enabled, 0644, shmem_enabled_show, shmem_enabled_store); #endif /* CONFIG_TRANSPARENT_HUGEPAGE && CONFIG_SYSFS */ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool shmem_huge_enabled(struct vm_area_struct *vma) -{ - struct inode *inode = file_inode(vma->vm_file); - struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); - loff_t i_size; - pgoff_t off; - - if ((vma->vm_flags & VM_NOHUGEPAGE) || - test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - return false; - if (shmem_huge == SHMEM_HUGE_FORCE) - return true; - if (shmem_huge == SHMEM_HUGE_DENY) - return false; - switch (sbinfo->huge) { - case SHMEM_HUGE_NEVER: - return false; - case SHMEM_HUGE_ALWAYS: - return true; - case SHMEM_HUGE_WITHIN_SIZE: - off = round_up(vma->vm_pgoff, HPAGE_PMD_NR); - i_size = round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >= HPAGE_PMD_SIZE && - i_size >> PAGE_SHIFT >= off) - return true; - fallthrough; - case SHMEM_HUGE_ADVISE: - /* TODO: implement fadvise() hints */ - return (vma->vm_flags & VM_HUGEPAGE); - default: - VM_BUG_ON(1); - return false; - } -} -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - #else /* !CONFIG_SHMEM */ /*