From patchwork Mon Sep 28 17:54:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11804455 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 DFACD618 for ; Mon, 28 Sep 2020 17:55:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A0020208FE for ; Mon, 28 Sep 2020 17:55:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sent.com header.i=@sent.com header.b="JqPeyEE+"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ErH1HLnr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A0020208FE 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 BEFB1900003; Mon, 28 Sep 2020 13:55:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9C54A90000B; Mon, 28 Sep 2020 13:55:25 -0400 (EDT) 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 6BB99900006; Mon, 28 Sep 2020 13:55:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 2DDFC900007 for ; Mon, 28 Sep 2020 13:55:25 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E9399180AD801 for ; Mon, 28 Sep 2020 17:55:24 +0000 (UTC) X-FDA: 77313222168.21.party25_1a0e8d627183 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id C292118045C0D for ; Mon, 28 Sep 2020 17:55:24 +0000 (UTC) X-Spam-Summary: 1,0,0,3848ae9925b48487,d41d8cd98f00b204,zi.yan@sent.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1261:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3871:3872:4117:4321:4385:5007:6119:6120:6261:6653:6742:7576:7875:7901:7927:8957:10004:11026:11473:11658:11914:12043:12291:12296:12438:12555:12679:12683:12895:13894:14096:14110:14181:14721:21080:21627:21990:30054:30064,0,RBL:64.147.123.17:@sent.com:.lbl8.mailshell.net-62.18.0.100 64.100.201.100;04yrotugfxukymduasmoyjtnek3czycub8r55hzx6rcu8c6suu64zwjki834uxe.mkpqmd99me3hqc5tc8c1gdeqzhqutmjp3fmx3cmtakcwwrtdj89ae3c7q8443x3.6-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:24,LUA_SUMMARY:none X-HE-Tag: party25_1a0e8d627183 X-Filterd-Recvd-Size: 6455 Received: from wnew3-smtp.messagingengine.com (wnew3-smtp.messagingengine.com [64.147.123.17]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Sep 2020 17:55:24 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id A4C2CE21; Mon, 28 Sep 2020 13:55:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 28 Sep 2020 13:55:22 -0400 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=fm1; bh=8Oi70jGe8Gu0u ZIuNyP+QGtlOgK/mS4X4NyXkO0eQ0c=; b=JqPeyEE+MzNnOOMdegl5R7KikhSKS A9fna4KhQ3+IA70ib+vN5ROsqKjIAqa0zq/p4eel6y+/P7va8UaVMEOCj6JJvCFx uAGSnZreNkQydqM2Y5rz4FglzgHScixIuFqCvzn15qObfg7XjTprUklCtnt9DS6L i2/CGJ9XoXXF61SxuuqPBQ7mcspSUXHvl1cIfTvX37qnxtEcdrgULgXe7TKhnw0r XCJi6Fq2QjdutAVioEoSZ/CiuNN6Vuu+3Ca1nYD7tQhM7dfaPUo/RXNIgSB7hZqt VTKwQ0zmdS0bvwqW+bvizh4M+S0oVIBZ8rKlXp357HtjqYrWzuMyNutpg== 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= fm3; bh=8Oi70jGe8Gu0uZIuNyP+QGtlOgK/mS4X4NyXkO0eQ0c=; b=ErH1HLnr yCLslm/NxxyASe24LQ4KLQPAR4q4XlFMtcjyk53xoshrDh+eRnKiDyAEMhW63yzj +JUmQesUN3ynbjied11OwHUqmNwmAfB71HOABfDJPbjXZSCZWy5Ftwjd1qU47Ltq 0+BVt4/oC2RIHGvekoghQ5jogZk3EuZSz9CDzMx+uqL9irgsK7/MpLD2vI+sH0jy lookiLhIgGHNxUWs6Rr5Yh0OfMGZYeEpjVV0wv70IlbL4DNO4ggxHUbT27d6ICks SwiZoIweP+ITvHFjtOkd+7bcxPbGf12Mxpyz0j87wRn7AT+0q3ir8UhvRxzRwjKr HiTdcH+0aX3CXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdeigdeliecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeduhfffve ektdduhfdutdfgtdekkedvhfetuedufedtgffgvdevleehheevjefgtdenucfkphepuddv rdegiedruddtiedrudeigeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id BCA143064687; Mon, 28 Sep 2020 13:55:20 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: "Kirill A . Shutemov" , Roman Gushchin , Rik van Riel , Matthew Wilcox , Shakeel Butt , Yang Shi , Jason Gunthorpe , Mike Kravetz , Michal Hocko , David Hildenbrand , William Kucharski , Andrea Arcangeli , John Hubbard , David Nellans , linux-kernel@vger.kernel.org, Zi Yan Subject: [RFC PATCH v2 08/30] mm: thp: add PUD THP support for copy_huge_pud. Date: Mon, 28 Sep 2020 13:54:06 -0400 Message-Id: <20200928175428.4110504-9-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928175428.4110504-1-zi.yan@sent.com> References: <20200928175428.4110504-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 copy_huge_pud needs to allocate 1 PMD page table page and 512 PTE page table pages and deposit them when copying a PUD THP. It is similar to what we do at PUD THP page faults. Signed-off-by: Zi Yan --- mm/huge_memory.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 20a3d393d451..ea9fbedcda26 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1264,7 +1264,12 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, { spinlock_t *dst_ptl, *src_ptl; pud_t pud; - int ret; + pmd_t *pmd_pgtable = NULL; + int ret = -ENOMEM; + + pmd_pgtable = pmd_alloc_one_page_with_ptes(vma->vm_mm, addr); + if (unlikely(!pmd_pgtable)) + goto out; dst_ptl = pud_lock(dst_mm, dst_pud); src_ptl = pud_lockptr(src_mm, src_pud); @@ -1272,16 +1277,30 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, ret = -EAGAIN; pud = *src_pud; - if (unlikely(!pud_trans_huge(pud) && !pud_devmap(pud))) - goto out_unlock; /* - * When page table lock is held, the huge zero pud should not be - * under splitting since we don't split the page itself, only pud to - * a page table. + * only transparent huge pud page needs extra page table pages for + * possible huge page split */ - if (is_huge_zero_pud(pud)) { - /* No huge zero pud yet */ + if (!pud_trans_huge(pud)) + pmd_free_page_with_ptes(dst_mm, pmd_pgtable); + + if (unlikely(!pud_trans_huge(pud) && !pud_devmap(pud))) + goto out_unlock; + + if (pud_trans_huge(pud)) { + struct page *src_page; + int i; + + src_page = pud_page(pud); + VM_BUG_ON_PAGE(!PageHead(src_page), src_page); + get_page(src_page); + page_dup_rmap(src_page, true); + add_mm_counter(dst_mm, MM_ANONPAGES, HPAGE_PUD_NR); + mm_inc_nr_pmds(dst_mm); + for (i = 0; i < (1<<(HPAGE_PUD_ORDER - HPAGE_PMD_ORDER)); i++) + mm_inc_nr_ptes(dst_mm); + pgtable_trans_huge_pud_deposit(dst_mm, dst_pud, virt_to_page(pmd_pgtable)); } pudp_set_wrprotect(src_mm, addr, src_pud); @@ -1292,6 +1311,7 @@ int copy_huge_pud(struct mm_struct *dst_mm, struct mm_struct *src_mm, out_unlock: spin_unlock(src_ptl); spin_unlock(dst_ptl); +out: return ret; }