From patchwork Wed Nov 11 20:40:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11898515 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C767921 for ; Wed, 11 Nov 2020 20:41:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F949208FE for ; Wed, 11 Nov 2020 20:41:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="G28shBuM"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jbfenD4g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F949208FE 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 DAA486B0070; Wed, 11 Nov 2020 15:40:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D284F6B0072; Wed, 11 Nov 2020 15:40:46 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86C9F6B0073; Wed, 11 Nov 2020 15:40:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 178A86B0070 for ; Wed, 11 Nov 2020 15:40:46 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A88EF180AD801 for ; Wed, 11 Nov 2020 20:40:45 +0000 (UTC) X-FDA: 77473306050.30.fall63_0711c8e27300 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 7D34D180B3C8E for ; Wed, 11 Nov 2020 20:40:45 +0000 (UTC) X-Spam-Summary: 1,0,0,8952cd76c081b386,d41d8cd98f00b204,zi.yan@sent.com,,RULES_HIT:41:355:379:541:560:800:960:973:988:989:1260:1261:1311:1314:1345:1359:1437:1513:1515:1521:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3872:4117:4250:5007:6119:6120:6261:6653:6742:7576:7875:7901:8957:10004:11026:11658:11914:12043:12291:12296:12438:12555:12679:12895:13161:13229:14096:14181:14721:21080:21324:21627:21990:30034:30054:30064,0,RBL:64.147.123.26:@sent.com:.lbl8.mailshell.net-62.18.0.100 64.100.201.100;04y88s4h543a6iunqwq8ne8m6i6zeycw64pt6b93rqt7rmui4k3iws743d7uo1h.aiz1rc6seujnmhpyxiy43nepiir5xgw5nykx6wa8jznqrtyzxqg6htnzxh935jp.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:70,LUA_SUMMARY:none X-HE-Tag: fall63_0711c8e27300 X-Filterd-Recvd-Size: 6128 Received: from wnew1-smtp.messagingengine.com (wnew1-smtp.messagingengine.com [64.147.123.26]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Nov 2020 20:40:44 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id E2A62B45; Wed, 11 Nov 2020 15:40:41 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 11 Nov 2020 15:40:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; s=fm2; bh=Ao4OQzNEMkLUB rt8fQw2khsG2IVAwlRTCnIBOCh4AzI=; b=G28shBuMvus0pki1eu5Vkq4Grf0lO b34p4MR90hWIeKICBMvCssewrtQ3rLrRBNfzSeNDp8ARtpsflL2oo4bOWjrCn+yc 5h8y8K9DzFYRM7yR7Crb7VnlIDqYG8S4BcAm9KYa5T5WNZk/m9zmepDofqC2iIFw Mx+dQAq4ftmG7+MBAYkKeY+TAbfGGeQ8wdJ5yDSfvxnFsPVvErvKk3rAAFMN5j3I N99KJvcP2cyos451wXIsc0x18J/TJPA9ZWarZ3IuIYg6jA5UYqcXp6+bQeHbKxoY +S5KmSrMhCjlJbjGKkAKAdsfOboH99oQUy6pr5p0hDflQqOZfniVT9zuw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:reply-to:subject :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=Ao4OQzNEMkLUBrt8fQw2khsG2IVAwlRTCnIBOCh4AzI=; b=jbfenD4g zwnLr0RWKlmTz1To0IBFs7Tld1sqLWJrUZUm6le2AJdhi7D86YBjXf3zfOsb0MA0 mtuq6K+t8lFOht4xCpVZD2h4+y8T1EDzKqJpRDiqSMdt3Y3V6VkvsEs/tO6ZgVYq /HuJD2sQm2vAO+PVYD3s825UenK0atu7XqIgJYBhtQBxIL5o8gunwGLwMLMPk4zO VAXc9rpf2P1OA2lKGbKN7ssGONkwVZRHcg0xllPNrR8icvmUZjZAbauP5qHu4nyS 6nOiZXuVxzrbbOEVFoG577eKcQeuSFGD0z3I//Q3dYGJjHMq58N00tkA7VzJGizq OlJ/lIa8FV6dsw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddvtddgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepieejue dvueduuefhgefhheeiuedvtedvuefgieegveetueeiueehtdegudehfeelnecukfhppedu vddrgeeirddutdeirdduieegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id ED343328006B; Wed, 11 Nov 2020 15:40:40 -0500 (EST) From: Zi Yan To: linux-mm@kvack.org, Matthew Wilcox Cc: "Kirill A . Shutemov" , 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: [RFC PATCH 5/6] mm: truncate: split thp to a non-zero order if possible. Date: Wed, 11 Nov 2020 15:40:07 -0500 Message-Id: <20201111204008.21332-6-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201111204008.21332-1-zi.yan@sent.com> References: <20201111204008.21332-1-zi.yan@sent.com> 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 To minimize the number of pages after a truncation, when truncating a THP, we do not need to split it all the way down to order-0. The THP has at most three parts, the part before offset, the part to be truncated, the part left at the end. Use the non-zero minimum of them to decide what order we split the THP to. Signed-off-by: Zi Yan --- mm/truncate.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 20bd17538ec2..6d8e3c6115bc 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -237,7 +237,7 @@ int truncate_inode_page(struct address_space *mapping, struct page *page) bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end) { loff_t pos = page_offset(page); - unsigned int offset, length; + unsigned int offset, length, left, min_subpage_size = PAGE_SIZE; if (pos < start) offset = start - pos; @@ -248,6 +248,7 @@ bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end) length = length - offset; else length = end + 1 - pos - offset; + left = thp_size(page) - offset - length; wait_on_page_writeback(page); if (length == thp_size(page)) { @@ -267,7 +268,24 @@ bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t end) do_invalidatepage(page, offset, length); if (!PageTransHuge(page)) return true; - return split_huge_page(page) == 0; + + /* + * find the non-zero minimum of offset, length, and left and use it to + * decide the new order of the page after split + */ + if (offset && left) + min_subpage_size = min_t(unsigned int, + min_t(unsigned int, offset, length), + left); + else if (!offset) + min_subpage_size = min_t(unsigned int, length, left); + else /* !left */ + min_subpage_size = min_t(unsigned int, length, offset); + + min_subpage_size = max_t(unsigned int, PAGE_SIZE, min_subpage_size); + + return split_huge_page_to_list_to_order(page, NULL, + ilog2(min_subpage_size/PAGE_SIZE)) == 0; } /*