From patchwork Mon Apr 22 07:02:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13637715 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 1A2A1C4345F for ; Mon, 22 Apr 2024 07:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 569846B0088; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5190A6B008A; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 412A16B008C; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 23F726B0088 for ; Mon, 22 Apr 2024 03:03:05 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8707F160B10 for ; Mon, 22 Apr 2024 07:03:04 +0000 (UTC) X-FDA: 82036275888.06.60C9C4E Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by imf23.hostedemail.com (Postfix) with ESMTP id AFAC5140011 for ; Mon, 22 Apr 2024 07:03:01 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=d9H7dXA3; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713769382; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iA51Bkqzy9zcXZ9S3Nkg6q/BBso18kv2IFiMWpEhGCs=; b=VnD08C9cwwnaK+0KAcV9n4slEyBoUY5uPloMBbdENmEdLDIRvfBUSH8wmFIGxvhMragxLd dr/02CKYi8oVLQpKSlVssoyhuKwgjmlzA3kkWiuGgrsWJFMLZwygqcf72w5s7YAvdgFtej y/4H0auplB52rpvqb/KD0Ov25Nq9FQQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713769382; a=rsa-sha256; cv=none; b=IUVIlHMxnWZkCbgFCTZifVF/vDcWtPmQ2q+euCVNynpHFdbFVv2s7pimUJa0G5qBpu0ojy 9G9Xn0eDm4jqXcHQgSTI32BVgi7X5zi72Y/E451nvXhhd8rHmGxEsO5sFX3mDE12xhJ/Xe +Bhocli6hpWvugotVhBYcvWVYRAQiAs= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=d9H7dXA3; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1713769378; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=iA51Bkqzy9zcXZ9S3Nkg6q/BBso18kv2IFiMWpEhGCs=; b=d9H7dXA3OkN5DMCvZyHjmmKv7zMP+IdJ9zqkOuoZ0p+W8tBIIEhqlgSceJJq1t1yms1JHJ2VSlMYTqaz2Au6/rREcdgMlWllo4gONZI28TaeFugKCrksHHLgAiAl2M0XWaegw8q2PG7XtPQTDGlwjijQnre9x+n77yV/drgkE6s= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0W5.T-Y-_1713769375; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W5.T-Y-_1713769375) by smtp.aliyun-inc.com; Mon, 22 Apr 2024 15:02:57 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/5] mm: memory: extend finish_fault() to support large folio Date: Mon, 22 Apr 2024 15:02:39 +0800 Message-Id: <358aefb1858b63164894d7d8504f3dae0b495366.1713755580.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: mxo5gb9n8zs1muqgudzjoet8z4numpjz X-Rspamd-Queue-Id: AFAC5140011 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713769381-714974 X-HE-Meta: U2FsdGVkX188HN7dYdHOI6cJiDVEO3Df0pADI/V1PK9JeLfM7R+nllY2BLak8K/juRTyXakxM8B4b8AsmAIi/yEDRHzfPpd5yK4ORa39ZPV1JmQ3dlrfTLGoluXyuCpuAcjlK8Dx0M8xB1eOwjU2APDMBPIF2oBvHE+SBVhFfE0dCTLGV5D+wT3qivkAlWU4uzmEnG01WWT7esIR1AV+rLegn6HDUFw/UbaSdLCMyYpvXmblWhOGwL8j5XgY9dn1Jhp2TwTmDjB4zwlB+QMs0UipAd4IMRgP3GP3rUvyIIcPdpEfYg7v/QxddLZKNDnCSsUxzIBiUYvnqYM2E6JXUHKvhylgS7MadD2sDGWbW8ktb0y0TSklHx2wzgN/aizilkzp3fAfifqkuMxy3BP8TxkVv4TqPahQOfCJ5lS3XMwLW2pykCnRuotyUZWadw2Nty0PLUbSTzApQDwWGutV3FI9rzQbplXPaflzcnzVXYi8Vcv1aSvAwjU/x/S64dBFgeIC8o8Tm8/KAkygs3Hm6wv8n8NJSSvKUoeQKR9UKttjSg2ZqLvtYoxLso10k3ZDnImaonebX3h1aQq6vkep+0wamSIWJB8S/QyVIqKIqK8LchdjM/fWG/4YCQ03FkwL1eDTTV4Kg6us4Ufr6kMYAjxbVOy86zQXlfs5TtpY96eClNmWKQoa2//6crrZxKolQLn0DqT8sE2b5KbymuxdPChjD5uliMX01zcaClj2iDXJ7+dM0G2KXikMWrb3U+gWgDpkkO0Q3wiEZKAJWq7fz5fvJxNzfkrvtL2tR7GYjTEfclSugS3rnn7LPprQ8YwAY6ZaKsdsD82ExmOKM4WLLfoblYv10hOAAHiwiEqhY3t/0ZzbWat5XEX6b/u+Hao6Ms9zFaUfNabvwiZs0eBKU61KyPuCztnYk+KrpbSOyyvAbkHg+L7lQPjFPfsiB58K7SrG56n7QYW9LVUmbZq Q2vJE9sW fgD/uSHbgbZxAuJdbyxMBxZ6ttuLg2a2kPrn7puWc3cbjU27ebdBCzGOiyqbO0iANACwiWI7LiwhrLRRFGEtGedbswteDVY74PIRr56zy4VfDfpvEt1uqswE5ngONPzY9eLtJPRAkT9o9WefLIQ17pVsYheaHBbfCE85+tjFDLHuKoOPk4OtamGaQIq1ShqVsyfdHqHy16OskYjxjSeO6Pgt85bKnXEmn87I6ZWm5kUKB5KUjydK3cgHHtMcbI1gBfIFzvdFZQo7if+zznijRTTUnG34U8QZ1cm1/nUZIif1zuiBqSOv5Uo3O34kWoomD7p5d 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: List-Subscribe: List-Unsubscribe: Add large folio mapping establishment support for finish_fault() as a preparation, to support multi-size THP allocation of anonymous shared pages in the following patches. Signed-off-by: Baolin Wang --- mm/memory.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b6fa5146b260..094a76730776 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4766,7 +4766,10 @@ vm_fault_t finish_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct page *page; + struct folio *folio; vm_fault_t ret; + int nr_pages, i; + unsigned long addr; /* Did we COW the page? */ if ((vmf->flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) @@ -4797,22 +4800,30 @@ vm_fault_t finish_fault(struct vm_fault *vmf) return VM_FAULT_OOM; } + folio = page_folio(page); + nr_pages = folio_nr_pages(folio); + addr = ALIGN_DOWN(vmf->address, nr_pages * PAGE_SIZE); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + addr, &vmf->ptl); if (!vmf->pte) return VM_FAULT_NOPAGE; /* Re-check under ptl */ - if (likely(!vmf_pte_changed(vmf))) { - struct folio *folio = page_folio(page); - - set_pte_range(vmf, folio, page, 1, vmf->address); - ret = 0; - } else { + if (nr_pages == 1 && vmf_pte_changed(vmf)) { update_mmu_tlb(vma, vmf->address, vmf->pte); ret = VM_FAULT_NOPAGE; + goto unlock; + } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) { + for (i = 0; i < nr_pages; i++) + update_mmu_tlb(vma, addr + PAGE_SIZE * i, vmf->pte + i); + ret = VM_FAULT_NOPAGE; + goto unlock; } + set_pte_range(vmf, folio, &folio->page, nr_pages, addr); + ret = 0; + +unlock: pte_unmap_unlock(vmf->pte, vmf->ptl); return ret; }