From patchwork Thu Nov 19 16:05:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11918159 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 71E8DC56201 for ; Thu, 19 Nov 2020 16:07:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D576A24721 for ; Thu, 19 Nov 2020 16:06:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="CpLtsr98"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wqb5mKKB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D576A24721 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=sent.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 117366B0075; Thu, 19 Nov 2020 11:06:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 079B66B0078; Thu, 19 Nov 2020 11:06:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D28AE6B007B; Thu, 19 Nov 2020 11:06:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 967B76B0075 for ; Thu, 19 Nov 2020 11:06:45 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 29527181AEF23 for ; Thu, 19 Nov 2020 16:06:45 +0000 (UTC) X-FDA: 77501645970.15.knot37_500812627344 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 878201814BA03 for ; Thu, 19 Nov 2020 16:06:40 +0000 (UTC) X-HE-Tag: knot37_500812627344 X-Filterd-Recvd-Size: 8427 Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Nov 2020 16:06:39 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id 48A33EB3; Thu, 19 Nov 2020 11:06:37 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 19 Nov 2020 11:06:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:reply-to:mime-version :content-transfer-encoding; s=fm2; bh=dLIW2nC3tgzPsBDCQkc84OS0Xh 6vYPtftB1fXGqMVrI=; b=CpLtsr98SAgyFocJmYPq07EdmM+nUV6FzPJYWWJgge uiXti30M5OSRaoBzKg8GnTsPYzK7g/gAggENapK7Qv6HB+BWTPTLtAuZdjv1qj4R U4uqWKKTPBpxzWpdrNznwrWVmIINwble7/Li2stsRfMGyeFJRyPFkde874AzqLxy jHFDMKnrtdRniFI+2m0BZ/D/zjzDPn/46mkcROetBbhhmW02fGSSpKaMkxj37Ik0 skRr5u+cobycP44DTQnm4RZ5XYdCRBcPSLAiTg+FGPxT0lwXn+jFjUmpxcYS1S78 VQIHWK2m/qAzD6eAsynV/gUt6tUlNoNcLPyG2ihElECg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:reply-to:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=dLIW2n C3tgzPsBDCQkc84OS0Xh6vYPtftB1fXGqMVrI=; b=Wqb5mKKBMz+CgrkhqAIS+c 6n0qS28piVAUuYE/2lAlkXyh/V7AEJpkYp1T3T72GQwP6Aud1J4dB3SG5IacDL3m Xo6Rr4iXB4citonkIzWgxRtadEbZXAv7kxZ4zhV12XCUikTtngRdTaomCOx2af3m AZkCShsQ2rC26YZNlunpo+WrtwgCVdbexfwaA3xDFjtQ2P5rlYHkpgzW/WynQW/e 1vnI/Onl9XyuDHVcjBTGgGqvnKSv2MDfkYE9d1JTDS7bJKpQ3lytRinmgR6JumCm vpyGgWR8gEzK5aOpOX6Q8QIR9AXOsURux6MMmx028q5GuEkWzM7EhmIYjWGemufg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefjedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfforhgggfestdhqredtredttdenucfhrhhomhepkghiucgjrghn uceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepgeegieehgf effeffleefgeevueegvdffteffhefhkeevvddtjedvudeljeetvdegnecuffhomhgrihhn pehkvghrnhgvlhdrohhrghdpihhnfhhrrgguvggrugdrohhrghenucfkphepuddvrdegie druddtiedrudeigeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhl fhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id 8953D3064AAA; Thu, 19 Nov 2020 11:06:35 -0500 (EST) From: Zi Yan To: linux-mm@kvack.org, Matthew Wilcox , "Kirill A . Shutemov" Cc: Roman Gushchin , Andrew Morton , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Yang Shi , Michal Hocko , John Hubbard , Ralph Campbell , David Nellans , Zi Yan Subject: [PATCH 0/7] Split huge pages to any lower order pages and selftests. Date: Thu, 19 Nov 2020 11:05:58 -0500 Message-Id: <20201119160605.1272425-1-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 Reply-To: Zi Yan MIME-Version: 1.0 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: From: Zi Yan Hi all, With Matthew's THP in pagecache patches[1], we will be able to handle any size pagecache THPs, but currently split_huge_page can only split a THP to order-0 pages. This can easily erase the benefit of having pagecache THPs, when operations like truncate might want to keep pages larger than order-0. In response, here is the patches to add support for splitting a THP to any lower order pages. In addition, this patchset prepares for my PUD THP patchset[2], since splitting a PUD THP to multiple PMD THPs can be handled by split_huge_page_to_list_to_order function added by this patchset, which reduces a lot of redundant code without just replicating split_huge_page for PUD THP. To help the tests of splitting huge pages, I added a new debugfs interface at /split_huge_pages_in_range_pid, so developers can split THPs in a given range from a process with the given pid by writing ",,," to the interface. I also added a new test program to test 1) splitting PMD THPs, 2) splitting PTE-mapped THPs, 3) splitting pagecache THPs to any lower order, 4) truncating a pagecache THP to a page with a lower order, and 5) punching holes in a pagecache THP to cause splitting THPs to lower order THPs. The patchset is on top of Matthew's pagecache/next tree[3]. * Patch 1 is cherry-picked from Matthew's recent xarray fix [4] just to make sure Patch 3 to 7 can run without problem. I let Matthew decide how it should get picked up. * Patch 2 is self-contained and can be merged if it looks OK. Comments and/or suggestions are welcome. ChangeLog === From RFC: 1. Fixed debugfs to handle splitting PTE-mapped THPs properly and added stats for split THPs. 2. Added a new test case for splitting PTE-mapped THPs. Each of the four PTEs points to a different subpage from four THPs and used kpageflags to check whether a PTE points to a THP or not (AnonHugePages from smap does not show PTE-mapped THPs). 3. mem_cgroup_split_huge_fixup() takes order instead of nr. 4. split_page_owner takes old_order and new_order instead of nr and new_order. 5. Corrected __split_page_owner declaration and fixed its implementation when splitting a THP to a new order. 6. Renamed left to remaining in truncate_inode_partial_page(). 7. Use VM_BUG_ON instead of WARN_ONCE when splitting a THP to the unsupported order-0 and splitting anonymous THPs to non-zero orders. 8. Added punching holes in a file as a new pagecache THP split test case, which uncovered an xarray bug. [1] https://lore.kernel.org/linux-mm/20201029193405.29125-1-willy@infradead.org/ [2] https://lore.kernel.org/linux-mm/20200928175428.4110504-1-zi.yan@sent.com/ [3] https://git.infradead.org/users/willy/pagecache.git/shortlog/refs/heads/next [4] https://git.infradead.org/users/willy/xarray.git Matthew Wilcox (Oracle) (1): XArray: Fix splitting to non-zero orders Zi Yan (6): mm: huge_memory: add new debugfs interface to trigger split huge page on any page range. mm: memcg: make memcg huge page split support any order split. mm: page_owner: add support for splitting to any order in split page_owner. mm: thp: split huge page to any lower order pages. mm: truncate: split thp to a non-zero order if possible. mm: huge_memory: enable debugfs to split huge pages to any order. include/linux/huge_mm.h | 8 + include/linux/memcontrol.h | 5 +- include/linux/page_owner.h | 10 +- lib/test_xarray.c | 26 +- lib/xarray.c | 4 +- mm/huge_memory.c | 219 ++++++-- mm/internal.h | 1 + mm/memcontrol.c | 6 +- mm/migrate.c | 2 +- mm/page_alloc.c | 2 +- mm/page_owner.c | 13 +- mm/swap.c | 1 - mm/truncate.c | 29 +- tools/testing/selftests/vm/.gitignore | 1 + tools/testing/selftests/vm/Makefile | 1 + .../selftests/vm/split_huge_page_test.c | 479 ++++++++++++++++++ 16 files changed, 742 insertions(+), 65 deletions(-) create mode 100644 tools/testing/selftests/vm/split_huge_page_test.c --- 2.28.0