From patchwork Mon Apr 4 20:02:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12800661 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 115AFC433F5 for ; Mon, 4 Apr 2022 20:03:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7777D6B0071; Mon, 4 Apr 2022 16:03:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 726E56B0073; Mon, 4 Apr 2022 16:03:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EE526B0074; Mon, 4 Apr 2022 16:03:14 -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 510736B0071 for ; Mon, 4 Apr 2022 16:03:14 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1F405244F3 for ; Mon, 4 Apr 2022 20:03:04 +0000 (UTC) X-FDA: 79320270288.04.328E5F8 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf30.hostedemail.com (Postfix) with ESMTP id 870E98002E for ; Mon, 4 Apr 2022 20:03:03 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id q19so9224426pgm.6 for ; Mon, 04 Apr 2022 13:03:03 -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=g1/S18NSrxN6AWy6KL3HCZnERr6pCTHzLQu/VSnzK2M=; b=Mwnt+Nq2EZKGxVmu8ajENw2WLVM+PMP8Pob4xNoQ9sJszM+9hd34t1sIDnV/JVKWc5 aIDg3KNtFuuL8pds0a0t4HMMv6NdG8/Ob2k3eOaVEzLQu/lgBUbaSwJM8lQH851qPI2C Uvu2USNa1ts9IlrQGSu6wJ7ucpOBHLBcZogtcuYedGIWWrd56NR35kHqBt12SIP00A9W 6K9FokVb73EcTl/zPpH9YSjS6HsTO1dCfJIFaweMLYOHR7XOoBohWAPOTz8QKw47pABm LXEX7pa4IRUch8OMc+3f+1TxlVdWQrjf/xVdlfeCiIUJaGvPRLBDiCy1GWcowr8GQ5qL cMvA== 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=g1/S18NSrxN6AWy6KL3HCZnERr6pCTHzLQu/VSnzK2M=; b=vOfB/jx3Ypv1creUAXt2Pu7iY1Mp3sh6ZIlGcTe7mfroaos+ZE421FOmuClc96N5Cm tamrZRzD6+qhEtjMM7aN1YoU8B9aeLuqNJas/lcAuu3FKV6OBQ9KxPwzJxnNhfHDekIb ChpLvyxEhVSk7hourKr6Q/KK/5Jot/fUaW3zEepGHTf68hJqRrzgCd0xEeb8ZhzlkF9z 6NCXCb6+uuajbM12k9mvRqmuGTLbJCeTWgCiytrcK4af4tphQQOffpm+NJDo/kgfL8PV IoD7P7StoqaHuq/cvZyijCNzH0xUS3W18hXATCg5obosqvs9xsqmjXCSQe7IPwxUomAS 9TnA== X-Gm-Message-State: AOAM532GbEdx1NQlpciQ5fmO3Si9Oj1jIGxCoob8QB4bgEw3/gaWi7MZ E0fALDZ/QEDsXoVhaIMd+XU= X-Google-Smtp-Source: ABdhPJzPk7RPw96v5iy70ANgZhWcNVAx23WdjIeS0iVP13r1Jp4hzjPAyCQz5SV25F0Q678GhpbdCQ== X-Received: by 2002:a65:6d06:0:b0:399:1485:6288 with SMTP id bf6-20020a656d06000000b0039914856288mr1331167pgb.346.1649102582351; Mon, 04 Apr 2022 13:03:02 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:03:01 -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 0/8] Make khugepaged collapse readonly FS THP more consistent Date: Mon, 4 Apr 2022 13:02:42 -0700 Message-Id: <20220404200250.321455-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Stat-Signature: 7etwsjfww51idncop1tk5zwwwr5wb56h Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Mwnt+Nq2; spf=pass (imf30.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 870E98002E X-HE-Tag: 1649102583-197718 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 v3: * Register mm to khugepaged in common mmap path instead of touching filesystem code (patch 8/8) suggested by Ted. * New patch 7/8 cleaned up and renamed khugepaged_enter_vma_merge() to khugepaged_enter_vma(). * Collected acked-by from Song Liu for patch 1 ~ 6. * Rebased on top of 5.18-rc1. * Excluded linux-xfs and linux-ext4 list since the series doesn't touch fs code anymore, but keep linux-fsdevel posted. 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 suitable vmas in common mmap path, that could cover both readonly FS vmas and shmem vmas, so removed the khugepaged calls in shmem.c. The patch 1 ~ 7 are minor bug fixes, clean up and preparation patches. The patch 8 is the real meat. 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. Yang Shi (8): sched: coredump.h: clarify the use of MMF_VM_HUGEPAGE mm: khugepaged: remove redundant check for VM_NO_KHUGEPAGED mm: khugepaged: skip DAX vma mm: thp: only regular file could be THP eligible mm: khugepaged: make khugepaged_enter() void function mm: khugepaged: move some khugepaged_* functions to khugepaged.c mm: khugepaged: introduce khugepaged_enter_vma() helper mm: mmap: register suitable readonly file vmas for khugepaged include/linux/huge_mm.h | 14 ++++++++++++ include/linux/khugepaged.h | 59 ++++++++++++--------------------------------------- include/linux/sched/coredump.h | 3 ++- kernel/fork.c | 4 +--- mm/huge_memory.c | 15 ++++--------- mm/khugepaged.c | 76 +++++++++++++++++++++++++++++++++++++----------------------------- mm/mmap.c | 14 ++++++++---- mm/shmem.c | 12 ----------- 8 files changed, 88 insertions(+), 109 deletions(-)