From patchwork Mon Dec 4 14:21:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13478498 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 D723AC10F05 for ; Mon, 4 Dec 2023 14:22:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADB156B0121; Mon, 4 Dec 2023 09:22:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A87896B0128; Mon, 4 Dec 2023 09:22:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8DAAC6B0125; Mon, 4 Dec 2023 09:22:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 79C386B0121 for ; Mon, 4 Dec 2023 09:22:11 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46E01C02B5 for ; Mon, 4 Dec 2023 14:22:11 +0000 (UTC) X-FDA: 81529350462.18.B963083 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 725E640002 for ; Mon, 4 Dec 2023 14:22:09 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LAlUzxoT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701699729; 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=rWanwqicBfazF+1iBEpyOQZ25LJEujBQqHyMDlWvhqA=; b=MzWpbBj9bAMr88VzSTNnrne517137S0NmQS/Yxrs+M31zKnwPgJ2hqbRwQxfQzBQGzNz17 C4JXZEG9RWndkemFy5Xfw59BJpxAWcx+p7U1lZvSnoiFh4u2FDuB56R9VGxPdGoxWXAWfi CXj17GkDFBgKBGRYNyTRbx3kMYbsaFQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LAlUzxoT; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701699729; a=rsa-sha256; cv=none; b=GmaFwoVG0SC6wR0EvEiDuIscgAg/1Qmy7RqoX/KA/exs3goOiQZbqcrH05D6HVcn6hGaGb z4ci2iRMbarKBRwFcFdcTAtGgNkSs3L8jcaRqgU0y8gbChYv2r0zemc8m/CdzOvEG/vHx0 5qKsfGc3/Bp3s9ejBkkzVcayT6zdYcQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701699728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rWanwqicBfazF+1iBEpyOQZ25LJEujBQqHyMDlWvhqA=; b=LAlUzxoTyYLO0ukIM9henASMEmCRTRSh4aGJPKaCytwf4HCDnHzrRhaJXTryPDhxp3+QVN CJoyKXp8xctxkOMMePl2kFlSCCcxNMug8X7APeLBZPJcKg63S1G4ETcgewRLEwuIoFpP07 jF89SvjseSB7Ksw4MsjUQ4mliVFAx8s= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-zbIm8uHQNrW7J5QBtxdQDA-1; Mon, 04 Dec 2023 09:22:04 -0500 X-MC-Unique: zbIm8uHQNrW7J5QBtxdQDA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C48C2825E93; Mon, 4 Dec 2023 14:22:03 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.195.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF5FB2026D68; Mon, 4 Dec 2023 14:22:01 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Hugh Dickins , Ryan Roberts , Yin Fengwei , Mike Kravetz , Muchun Song , Peter Xu Subject: [PATCH RFC 08/39] mm/memory: page_add_file_rmap() -> folio_add_file_rmap_[pte|pmd]() Date: Mon, 4 Dec 2023 15:21:15 +0100 Message-ID: <20231204142146.91437-9-david@redhat.com> In-Reply-To: <20231204142146.91437-1-david@redhat.com> References: <20231204142146.91437-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Rspamd-Queue-Id: 725E640002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ry8t6eap5oz7phhdtnxuyj5h1t7kmy4j X-HE-Tag: 1701699729-462337 X-HE-Meta: U2FsdGVkX18ZAvIyyUvF1TCoYn2wAKjDDtue3xt45DnUqyc8k2Efq1n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N4KyIZGxnib5oJhKDFtVvwZiSOVTzvMiDBeSYZhn7f7spt5zA9699PzJ4nVP6gNPsXiCKWTpT7v8b5SEw== 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: Let's convert insert_page_into_pte_locked() and do_set_pmd(). While at it, perform some folio conversion. Signed-off-by: David Hildenbrand Reviewed-by: Yin Fengwei --- mm/memory.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 15325587cff01..be7fe58f7c297 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1845,12 +1845,14 @@ static int validate_page_before_insert(struct page *page) static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte, unsigned long addr, struct page *page, pgprot_t prot) { + struct folio *folio = page_folio(page); + if (!pte_none(ptep_get(pte))) return -EBUSY; /* Ok, finally just insert the thing.. */ - get_page(page); + folio_get(folio); inc_mm_counter(vma->vm_mm, mm_counter_file(page)); - page_add_file_rmap(page, vma, false); + folio_add_file_rmap_pte(folio, page, vma); set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot)); return 0; } @@ -4308,6 +4310,7 @@ static void deposit_prealloc_pte(struct vm_fault *vmf) vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) { + struct folio *folio = page_folio(page); struct vm_area_struct *vma = vmf->vma; bool write = vmf->flags & FAULT_FLAG_WRITE; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; @@ -4317,8 +4320,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) if (!transhuge_vma_suitable(vma, haddr)) return ret; - page = compound_head(page); - if (compound_order(page) != HPAGE_PMD_ORDER) + if (page != &folio->page || folio_order(folio) != HPAGE_PMD_ORDER) return ret; /* @@ -4327,7 +4329,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) * check. This kind of THP just can be PTE mapped. Access to * the corrupted subpage should trigger SIGBUS as expected. */ - if (unlikely(PageHasHWPoisoned(page))) + if (unlikely(folio_test_has_hwpoisoned(folio))) return ret; /* @@ -4351,7 +4353,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page) entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR); - page_add_file_rmap(page, vma, true); + folio_add_file_rmap_pmd(folio, page, vma); /* * deposit and withdraw with pmd lock held