From patchwork Thu Mar 17 23:48:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12784674 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 54372C433F5 for ; Thu, 17 Mar 2022 23:48:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C817D8D0003; Thu, 17 Mar 2022 19:48:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C30718D0001; Thu, 17 Mar 2022 19:48:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD0EF8D0003; Thu, 17 Mar 2022 19:48:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 9B0A08D0001 for ; Thu, 17 Mar 2022 19:48:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4C51F22EF7 for ; Thu, 17 Mar 2022 23:48:37 +0000 (UTC) X-FDA: 79255520274.08.B59ED81 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf06.hostedemail.com (Postfix) with ESMTP id D109F180004 for ; Thu, 17 Mar 2022 23:48:36 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id t2so8098287pfj.10 for ; Thu, 17 Mar 2022 16:48:36 -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:mime-version :content-transfer-encoding; bh=RyzclAfIr+1FEbAjXUVMbsyC4Y6KT1lKsbzt7mnyN1k=; b=B+POt2+357+jg0w3MH9VzPkPpg2huHa1LaNJSdbtOFdDBE2P3b1/uiLCzvO4mowKri M+JCXnJkM88uH/IGF+8NCbtX0ERJoEeYXQ9EPwKQohwD73STyK9TlLjE4LZXknrMgkgB nUB6CQyck+w+BGd2Q2zOvJQ8WySSa8Qd1Q1Y66mlYkLiybT1I0GyT6toTY+GYsaPjqxU iYmiIEBV62087RuWTv0hq5f0ajY+Ej15hcloLXZKdX7//4QCvGeX3Q4PKJj0RVUwuH1H 89VDc+E+cnTvOjS2CzSCsABFiVpnKpYSmDv4+b+KG9pEMTKiiSafhVZHN5J8QRnZUFQr 0rmQ== 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:mime-version :content-transfer-encoding; bh=RyzclAfIr+1FEbAjXUVMbsyC4Y6KT1lKsbzt7mnyN1k=; b=1CKEs9/kjKGN+7Y42gOfJHDyU/adyjDR+Jgyvj4oC8TKGzHpq/g9CPxEMt0Jwo0qWE Ov92RhvtQghsnYaX1N9kvOSVHmoK3vOs/30ecWyfnQ9hTuJh1xzmevn5fyY8IXiDMq1u noEUm2eaovmnDzG31YDrB8E/G2OniUGLCbZKmJ2TsgexYIZs54XkgDY1W5wSX8rpfAJg tnKuAxTFT4XupVXkpeo6ZFOudfDdk0lV2BwkXLajdHNYV8WrMEGdAWTo/c9RDCIAjXov q/suKrwll5mXUzuJbso3Okxbi86RmFVYhg4KJY+h9Ym9Ni+GA1WKnVCUwxUVgpfaYjuC tkZw== X-Gm-Message-State: AOAM5326orgIdVOGoc675yf/Yupol9//6xGvEZ2gYAh6ixrRz32I6vsF byloMUfoAbsSxOi1KbMDJrQ= X-Google-Smtp-Source: ABdhPJysc5kigtJLM1MC/aHUAOynsRRlp97FjWauCN2Z2NpoLEeaoc2CDwBJJfBhTRZVPCVjCAa+rQ== X-Received: by 2002:a63:1b66:0:b0:37c:728a:e06f with SMTP id b38-20020a631b66000000b0037c728ae06fmr5594295pgm.458.1647560915746; Thu, 17 Mar 2022 16:48:35 -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 o7-20020aa79787000000b004f8e44a02e2sm8581329pfp.45.2022.03.17.16.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 16:48:35 -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, akpm@linux-foundation.org, tytso@mit.edu, adilger.kernel@dilger.ca, darrick.wong@oracle.com Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 0/8] Make khugepaged collapse readonly FS THP more consistent Date: Thu, 17 Mar 2022 16:48:19 -0700 Message-Id: <20220317234827.447799-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: D109F180004 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=B+POt2+3; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Stat-Signature: 6498soyib6af7qsisci6i1nxg8f8tk45 X-Rspamd-Server: rspam04 X-HE-Tag: 1647560916-637962 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: Changelog v2: * Collected reviewed-by tags from Miaohe Lin. * Fixed build error for patch 4/8. The readonly FS THP relies on khugepaged to collapse THP for suitable vmas. But it is kind of "random luck" for khugepaged to see the readonly FS vmas (see report: https://lore.kernel.org/linux-mm/00f195d4-d039-3cf2-d3a1-a2c88de397a0@suse.cz/) since currently the vmas are registered to khugepaged when: - Anon huge pmd page fault - VMA merge - MADV_HUGEPAGE - Shmem mmap If the above conditions are not met, even though khugepaged is enabled it won't see readonly FS vmas at all. MADV_HUGEPAGE could be specified explicitly to tell khugepaged to collapse this area, but when khugepaged mode is "always" it should scan suitable vmas as long as VM_NOHUGEPAGE is not set. So make sure readonly FS vmas are registered to khugepaged to make the behavior more consistent. Registering the vmas in mmap path seems more preferred from performance point of view since page fault path is definitely hot path. The patch 1 ~ 7 are minor bug fixes, clean up and preparation patches. The patch 8 converts ext4 and xfs. We may need convert more filesystems, but I'd like to hear some comments before doing that. Tested with khugepaged test in selftests and the testcase provided by Vlastimil Babka in https://lore.kernel.org/lkml/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/ by commenting out MADV_HUGEPAGE call. b/fs/ext4/file.c | 4 +++ b/fs/xfs/xfs_file.c | 4 +++ b/include/linux/huge_mm.h | 9 +++++++ b/include/linux/khugepaged.h | 69 +++++++++++++++++++++---------------------------------------- b/include/linux/sched/coredump.h | 3 +- b/kernel/fork.c | 4 --- b/mm/huge_memory.c | 15 +++---------- b/mm/khugepaged.c | 71 ++++++++++++++++++++++++++++++++++++++++++++------------------- b/mm/shmem.c | 14 +++--------- 9 files changed, 102 insertions(+), 91 deletions(-) Acked-by: Song Liu