From nobody Sat Dec 27 15:11:11 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D9C11C89 for ; Tue, 19 Dec 2023 07:57:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HXSDbslq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702972644; 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=4pxuQ+zeUrZD43W0p30SCM4P3ajCE4Euxhqhb6PE8fI=; b=HXSDbslqmmhmUOJ5i6ilK+Jw0AKj4MScBwMEn1RmCCcyqYNAV707cl/ip3hiRMhtABXnFn 1hQLOiuS+kfrd6oQ6SyBhF1aNm0LjdItJETu/4zd9oagNRNDQZnNbCkgJcDP/oem+LG7Ln BWC+cHNvuzMVlH5B1NPR7umvClwGshQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-O_LLgdEzO2yAjxB50bIomw-1; Tue, 19 Dec 2023 02:57:17 -0500 X-MC-Unique: O_LLgdEzO2yAjxB50bIomw-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 94A54837221; Tue, 19 Dec 2023 07:57:16 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id B40302026D66; Tue, 19 Dec 2023 07:57:05 +0000 (UTC) From: peterx@redhat.com To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Matthew Wilcox , Christophe Leroy , Lorenzo Stoakes , David Hildenbrand , Vlastimil Babka , Mike Kravetz , Mike Rapoport , Christoph Hellwig , John Hubbard , Andrew Jones , linux-arm-kernel@lists.infradead.org, Michael Ellerman , "Kirill A . Shutemov" , linuxppc-dev@lists.ozlabs.org, Rik van Riel , linux-riscv@lists.infradead.org, Yang Shi , James Houghton , "Aneesh Kumar K . V" , Andrew Morton , Jason Gunthorpe , Andrea Arcangeli , peterx@redhat.com, Axel Rasmussen Subject: [PATCH 07/13] mm/gup: Refactor record_subpages() to find 1st small page Date: Tue, 19 Dec 2023 15:55:32 +0800 Message-ID: <20231219075538.414708-8-peterx@redhat.com> In-Reply-To: <20231219075538.414708-1-peterx@redhat.com> References: <20231219075538.414708-1-peterx@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 Content-Type: text/plain; charset="utf-8" From: Peter Xu All the fast-gup functions take a tail page to operate, always need to do page mask calculations before feeding that into record_subpages(). Merge that logic into record_subpages(), so that it will do the nth_page() calculation. Signed-off-by: Peter Xu --- mm/gup.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index bb5b7134f10b..82d28d517d0d 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2767,13 +2767,16 @@ static int __gup_device_huge_pud(pud_t pud, pud_t *= pudp, unsigned long addr, } #endif =20 -static int record_subpages(struct page *page, unsigned long addr, - unsigned long end, struct page **pages) +static int record_subpages(struct page *page, unsigned long sz, + unsigned long addr, unsigned long end, + struct page **pages) { + struct page *start_page; int nr; =20 + start_page =3D nth_page(page, (addr & (sz - 1)) >> PAGE_SHIFT); for (nr =3D 0; addr !=3D end; nr++, addr +=3D PAGE_SIZE) - pages[nr] =3D nth_page(page, nr); + pages[nr] =3D nth_page(start_page, nr); =20 return nr; } @@ -2808,8 +2811,8 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz,= unsigned long addr, /* hugepages are never "special" */ VM_BUG_ON(!pfn_valid(pte_pfn(pte))); =20 - page =3D nth_page(pte_page(pte), (addr & (sz - 1)) >> PAGE_SHIFT); - refs =3D record_subpages(page, addr, end, pages + *nr); + page =3D pte_page(pte); + refs =3D record_subpages(page, sz, addr, end, pages + *nr); =20 folio =3D try_grab_folio(page, refs, flags); if (!folio) @@ -2882,8 +2885,8 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsi= gned long addr, pages, nr); } =20 - page =3D nth_page(pmd_page(orig), (addr & ~PMD_MASK) >> PAGE_SHIFT); - refs =3D record_subpages(page, addr, end, pages + *nr); + page =3D pmd_page(orig); + refs =3D record_subpages(page, PMD_SIZE, addr, end, pages + *nr); =20 folio =3D try_grab_folio(page, refs, flags); if (!folio) @@ -2926,8 +2929,8 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsi= gned long addr, pages, nr); } =20 - page =3D nth_page(pud_page(orig), (addr & ~PUD_MASK) >> PAGE_SHIFT); - refs =3D record_subpages(page, addr, end, pages + *nr); + page =3D pud_page(orig); + refs =3D record_subpages(page, PUD_SIZE, addr, end, pages + *nr); =20 folio =3D try_grab_folio(page, refs, flags); if (!folio) @@ -2966,8 +2969,8 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsi= gned long addr, =20 BUILD_BUG_ON(pgd_devmap(orig)); =20 - page =3D nth_page(pgd_page(orig), (addr & ~PGDIR_MASK) >> PAGE_SHIFT); - refs =3D record_subpages(page, addr, end, pages + *nr); + page =3D pgd_page(orig); + refs =3D record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); =20 folio =3D try_grab_folio(page, refs, flags); if (!folio) --=20 2.41.0