From mboxrd@z Thu Jan 1 00:00:00 1970 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_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 E37E4C6369E for ; Thu, 19 Nov 2020 16:06:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EF8D22253 for ; Thu, 19 Nov 2020 16:06:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="O+FbeQZV"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QxKk4jGi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EF8D22253 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 843E36B0071; Thu, 19 Nov 2020 11:06:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81C4D6B0072; Thu, 19 Nov 2020 11:06:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70CE46B0075; Thu, 19 Nov 2020 11:06:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 3F59B6B0071 for ; Thu, 19 Nov 2020 11:06:42 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DECB31EF1 for ; Thu, 19 Nov 2020 16:06:41 +0000 (UTC) X-FDA: 77501645802.21.crib04_2c1318a27344 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id B5B3D180458CA for ; Thu, 19 Nov 2020 16:06:41 +0000 (UTC) X-HE-Tag: crib04_2c1318a27344 X-Filterd-Recvd-Size: 6343 Received: from wnew2-smtp.messagingengine.com (wnew2-smtp.messagingengine.com [64.147.123.27]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Thu, 19 Nov 2020 16:06:40 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id 4C3739A7; Thu, 19 Nov 2020 11:06:38 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 19 Nov 2020 11:06:39 -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=2kAA7JKtM0LAG LniO91Baa3+LL5SEw62I50GNU8Qx8M=; b=O+FbeQZVoV7W8KIaKkXLaGiTMIsop DmnkQYD+8L+63x7o6MyZgIuTLRxGqFNEr8dODmcXkV1ouvJWGsfRmwz39u9dz3bR lTxE5vuI8AP4hX8r50ZicCwB9OIOszq2VeKz9E6u59iGUUHy2+jzkkGD0k+GrL7a yQskYbF0+Zv/VOWFW0UAEKkx0zNTmKTxMbu7z/MnHsgYDMJd/tRyN6BuybBQ4rz/ q2Sf+K3YNtLKr1+oacLZTCFnX9yNjbxpYkT1d6DHzDq7JiCo5462PO26bYHrbuOx Y1b55JN+MZzyVSwQStXSDoHWZfqhzBkvPui8OsIF48d/lJiiIAR61NEhQ== 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=2kAA7JKtM0LAGLniO91Baa3+LL5SEw62I50GNU8Qx8M=; b=QxKk4jGi +Ux36MDxnvR1hin/0kHifq4oqgG2YX70h8w0x68zowUSvCTqjms9t3Es8pHr/tZl UTE/gOgoh/qrNRK2aRNWPJV5Zd0ey0Mji7PhviLWDeP2CMLRNCANnmPYH0vdiRii kzclPTuemaTRjPWlcTVD2GTq6BKptncn0s/E2RmJ8Xe61v1lOY6tS9VwoZee1BRs DZysnvCxDH49ktYecBjMSI2OL/WYpUSJe+JXlf5+no9ulzi3hgglT9e/DLJuAh9r Rcpl7sbMyYoyy2OMAQN8jKapVAMNyE1BV23FtpmetMsgI9xH8N8wb1rHgoQN6wG7 fPYRQVbi3AOzRg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefjedgkeefucetufdoteggodetrfdotf 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 4652D3064AB9; Thu, 19 Nov 2020 11:06:37 -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 6/7] mm: truncate: split thp to a non-zero order if possible. Date: Thu, 19 Nov 2020 11:06:04 -0500 Message-Id: <20201119160605.1272425-7-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201119160605.1272425-1-zi.yan@sent.com> References: <20201119160605.1272425-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 20bd17538ec2..2e93d702f2c6 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -237,7 +237,9 @@ int truncate_inode_page(struct address_space *mapping, = struct page *page) bool truncate_inode_partial_page(struct page *page, loff_t start, loff_t e= nd) { loff_t pos =3D page_offset(page); - unsigned int offset, length; + unsigned int offset, length, remaining, min_subpage_size =3D PAGE_SIZE; + unsigned int new_order; + =20 if (pos < start) offset =3D start - pos; @@ -248,6 +250,7 @@ bool truncate_inode_partial_page(struct page *page, lof= f_t start, loff_t end) length =3D length - offset; else length =3D end + 1 - pos - offset; + remaining =3D thp_size(page) - offset - length; =20 wait_on_page_writeback(page); if (length =3D=3D thp_size(page)) { @@ -267,7 +270,29 @@ bool truncate_inode_partial_page(struct page *page, lo= ff_t start, loff_t end) do_invalidatepage(page, offset, length); if (!PageTransHuge(page)) return true; - return split_huge_page(page) =3D=3D 0; + + /* + * find the non-zero minimum of offset, length, and remaining and use it + * to decide the new order of the page after split + */ + if (offset && remaining) + min_subpage_size =3D min_t(unsigned int, + min_t(unsigned int, offset, length), + remaining); + else if (!offset) + min_subpage_size =3D min_t(unsigned int, length, remaining); + else /* remaining =3D=3D 0 */ + min_subpage_size =3D min_t(unsigned int, length, offset); + + min_subpage_size =3D max_t(unsigned int, PAGE_SIZE, min_subpage_size); + + new_order =3D ilog2(min_subpage_size/PAGE_SIZE); + + /* order-1 THP not supported, downgrade to order-0 */ + if (new_order =3D=3D 1) + new_order =3D 0; + + return split_huge_page_to_list_to_order(page, NULL, new_order) =3D=3D 0; } =20 /* --=20 2.28.0