From patchwork Tue May 10 20:32:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12845495 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 B8ACDC433EF for ; Tue, 10 May 2022 20:32:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 095448D0001; Tue, 10 May 2022 16:32:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 043F66B0075; Tue, 10 May 2022 16:32:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E26E68D0001; Tue, 10 May 2022 16:32:39 -0400 (EDT) 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 D2A586B0074 for ; Tue, 10 May 2022 16:32:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 96FEF60E0F for ; Tue, 10 May 2022 20:32:39 +0000 (UTC) X-FDA: 79450981638.18.201052D Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf27.hostedemail.com (Postfix) with ESMTP id CE1164009A for ; Tue, 10 May 2022 20:32:36 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id c14so166205pfn.2 for ; Tue, 10 May 2022 13:32:38 -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=+ZL8O1wtZrk4M8KM+4lA9arzBMXGuQKMerxUEh8SBcc=; b=Cm/LE0XiCVm4iQSaMhhk6SEWyk3ZLbJRizxoNhv2dwIoAGUW6OUbIlFpVRWFDVd+KJ tDijS4iL1LCE7RUxiQDG8ceLKIiFdpxoqOPKPsQ8fJ60COZnHB0TeV1gmiAUK1zO8lKu rGnqPBSroUwJb5DdX5+1NouNflwHRsycfhE+bADtLYEFf5MEwgVOJXV8GM7t4/X0rwy+ vjhBDlFpMwpLXGSopSg3hnB052xRKpzZ1yWzTvaj7OUIykFEh1yqaxoSLXXgyPU6bpro R9ousnLqVT4M00SDc5iktQjVNk6XLtNeFpUCWD5BCbIecF5hlp8UNNlJBKDj+9p1t1kI KioA== 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=+ZL8O1wtZrk4M8KM+4lA9arzBMXGuQKMerxUEh8SBcc=; b=c9irJvf+3lCNUvImGhqsnS11et6geqj0cUkNm2mtAmKoUl4gR0gwCD+s1raIzxdN0z wr8RbT1hJ8oiCZl1EY2WcDXPikb6QwfzmZgu1YCTO5bfrYgrjbbfr/sTJjcXUWGHvwAt dWR5q+Kls3+cpNudfTrJ8IEg8B/g/6vFXzTrb7sWMD69EyxRBef7ioolkJORmyBgrQb2 CZrWADCTx3N9dfK1pmi3ftpiGzTmSfL6G2RexlXvJAtlCI2myFaYJ0+EJh+aMZ8tPj80 uLjK4TYIaDK+rXDSMpAPT8HxGmDWH5ml422t31+4RXKnCuVdLFBAiKoXJu5VsNkb1ldf qiXA== X-Gm-Message-State: AOAM533NnrEsuANwq+F3wFwmpuv6wCyVOt9bsERazWkDv0pk+xNVa5ll JlmE2xAEMJ2FfnklTAIRjxw= X-Google-Smtp-Source: ABdhPJzaY/yOQRxh5ZIcbkcP6xwI7OojJbecUuTOd0gyxPyzQS2tg1L3ZqW2mh63GX5keJtw5JdcuA== X-Received: by 2002:a63:8543:0:b0:3ab:5afb:200c with SMTP id u64-20020a638543000000b003ab5afb200cmr17858732pgd.402.1652214757980; Tue, 10 May 2022 13:32:37 -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 v17-20020a1709028d9100b0015e8d4eb1d4sm58898plo.30.2022.05.10.13.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 13:32:36 -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: [mm-unstable v4 PATCH 0/8] Make khugepaged collapse readonly FS THP more consistent Date: Tue, 10 May 2022 13:32:14 -0700 Message-Id: <20220510203222.24246-1-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: CE1164009A X-Stat-Signature: kr8fi1x8zwh68d9cfdjum3pu56japa54 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Cm/LE0Xi"; spf=pass (imf27.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam09 X-HE-Tag: 1652214756-790795 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 v4: * Incorporated Vlastimil's comments for patch 6/8. * Reworked the commit log of patch 8/8 to make what the series fixed clearer. * Rebased onto mm-unstable tree. * Collected the acks from Vlastimil. v3: * Register mm to khugepaged in common mmap path instead of touching filesystem code (patch 8/8). * 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. 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 the behavior is inconsistent for "always" mode (https://lore.kernel.org/linux-mm/00f195d4-d039-3cf2-d3a1-a2c88de397a0@suse.cz/). The "always" mode means THP allocation should be tried all the time and khugepaged should try to collapse THP all the time. Of course the allocation and collapse may fail due to other factors and conditions. Currently file THP may not be collapsed by khugepaged even though all the conditions are met. That does break the semantics of "always" mode. So make sure readonly FS vmas are registered to khugepaged to fix the break. 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: make hugepage_vma_check() non-static 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 | 44 ++++++++++++++++++-------------------------- include/linux/sched/coredump.h | 3 ++- kernel/fork.c | 4 +--- mm/huge_memory.c | 15 ++++----------- mm/khugepaged.c | 61 ++++++++++++++++++++++++++----------------------------------- mm/mmap.c | 18 ++++++++++++------ mm/shmem.c | 12 ------------ 8 files changed, 77 insertions(+), 94 deletions(-)