From patchwork Mon Apr 4 20:02:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12800665 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 9C86EC433F5 for ; Mon, 4 Apr 2022 20:05:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7ECA68D0005; Mon, 4 Apr 2022 16:03:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79D308D0001; Mon, 4 Apr 2022 16:03:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63F288D0005; Mon, 4 Apr 2022 16:03:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 573EB8D0001 for ; Mon, 4 Apr 2022 16:03:20 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 25647120F81 for ; Mon, 4 Apr 2022 20:03:10 +0000 (UTC) X-FDA: 79320270540.03.16173FA Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf07.hostedemail.com (Postfix) with ESMTP id A413740017 for ; Mon, 4 Apr 2022 20:03:09 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id z16so10016563pfh.3 for ; Mon, 04 Apr 2022 13:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BXLHEFwxWdm5e2nqHirZ7xmXS6hF3uNKov0CWo+0WO8=; b=YHcz6zZf1ucCYQxs+BMo39i9t7OYROE0FpXZIgsWDaCsFsP9IDsqC4+3466mFNuIoG XKIxMX/EeLaGaDSkKXYDFXgr8HlDPlMuePpgvGfBZZzWdJZVhx0N+ih7KKqf5szrrHnG U2wo/VL4ygXkXvcglMVPrPHRDkifd17EqbT23AB19ccgs8/Bx2WixuZmCXKcJXjImMCi 9pRUoe3dQlpums5on1sx94iJXwq3mFhiR9L5ujIOE0fwiTJFVJbx9Nq/TPSCPK9/I2yE laPfy1lMXdXzUfgdglhd6cCi38CCqOWi0XfaDResSt6TIo2znuOjhuUfNN/4SJFyrfBA f7AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BXLHEFwxWdm5e2nqHirZ7xmXS6hF3uNKov0CWo+0WO8=; b=hB32OgnwLrhU9G6/jNRZ420bbCuRzyuzauuhW7YB/R/yo22PlSQGgQF9slaxETDihz rdilzDCMdNNG+o54S9DAuInlx63SmByA+c726chd8rQ4hoaVmUU65ybeLkAMlQR9RLgJ 52LNiQA5D4M4QII7uI6lcNI2CriHnbJXrusQVNntLZzKNJO19ADU4H5xcBYc7SeIZzYn s2uJMzFq4JojhxWVXqwXTYN9Wm/t6QOgeAsODMwD5yXDLcIuZrcLYYXXfYD6JTI5I/Bb daEWCmLJPEd5edl8PRpVefY/8e4rsCuaEIXBtw0xCpx45xzlA8MuTAJEASyqDF1C+ktD pzpQ== X-Gm-Message-State: AOAM532o/RoTQvakIbPA4xj/9diAnexhVhHKpb2HprkxJph3Pk56pFQV rx8iIb6B/IEhR2499dP7blk= X-Google-Smtp-Source: ABdhPJyagGXZMLfLFwAcYGG46fuX5fs53R3Ia/YY5p1GvsQ1lu5ZQE6+/01O8gqaGg7avP+BtQr8dA== X-Received: by 2002:a63:2ad0:0:b0:398:31d7:9955 with SMTP id q199-20020a632ad0000000b0039831d79955mr1273444pgq.198.1649102588645; Mon, 04 Apr 2022 13:03:08 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id bw17-20020a056a00409100b004fadad3b93esm12779295pfb.142.2022.04.04.13.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:03:08 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, songliubraving@fb.com, riel@surriel.com, willy@infradead.org, ziy@nvidia.com, tytso@mit.edu, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 4/8] mm: thp: only regular file could be THP eligible Date: Mon, 4 Apr 2022 13:02:46 -0700 Message-Id: <20220404200250.321455-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220404200250.321455-1-shy828301@gmail.com> References: <20220404200250.321455-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A413740017 X-Stat-Signature: 8db4xsng3y95tsmu4zs4gxrqybcao4fc Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YHcz6zZf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: X-HE-Tag: 1649102589-61433 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: Since commit a4aeaa06d45e ("mm: khugepaged: skip huge page collapse for special files"), khugepaged just collapses THP for regular file which is the intended usecase for readonly fs THP. Only show regular file as THP eligible accordingly. And make file_thp_enabled() available for khugepaged too in order to remove duplicate code. Acked-by: Song Liu Signed-off-by: Yang Shi Acked-by: Vlastimil Babka --- include/linux/huge_mm.h | 14 ++++++++++++++ mm/huge_memory.c | 11 ++--------- mm/khugepaged.c | 9 ++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 2999190adc22..62a6f667850d 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -172,6 +172,20 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) return false; } +static inline bool file_thp_enabled(struct vm_area_struct *vma) +{ + struct inode *inode; + + if (!vma->vm_file) + return false; + + inode = vma->vm_file->f_inode; + + return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) && + (vma->vm_flags & VM_EXEC) && + !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode); +} + bool transparent_hugepage_active(struct vm_area_struct *vma); #define transparent_hugepage_use_zero_page() \ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2fe38212e07c..183b793fd28e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -68,13 +68,6 @@ static atomic_t huge_zero_refcount; struct page *huge_zero_page __read_mostly; unsigned long huge_zero_pfn __read_mostly = ~0UL; -static inline bool file_thp_enabled(struct vm_area_struct *vma) -{ - return transhuge_vma_enabled(vma, vma->vm_flags) && vma->vm_file && - !inode_is_open_for_write(vma->vm_file->f_inode) && - (vma->vm_flags & VM_EXEC); -} - bool transparent_hugepage_active(struct vm_area_struct *vma) { /* The addr is used to check if the vma size fits */ @@ -86,8 +79,8 @@ bool transparent_hugepage_active(struct vm_area_struct *vma) return __transparent_hugepage_enabled(vma); if (vma_is_shmem(vma)) return shmem_huge_enabled(vma); - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) - return file_thp_enabled(vma); + if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma)) + return true; return false; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 964a4d2c942a..609c1bc0a027 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -464,13 +464,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return false; /* Only regular file is valid */ - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && - (vm_flags & VM_EXEC)) { - struct inode *inode = vma->vm_file->f_inode; - - return !inode_is_open_for_write(inode) && - S_ISREG(inode->i_mode); - } + if (file_thp_enabled(vma)) + return true; if (!vma->anon_vma || vma->vm_ops) return false;