Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp146901lqo; Wed, 27 Mar 2024 09:06:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUguffG9SaW/rVfviD7/YT+AWHlYjBQmhs52IYU2uFKODKsMK7CPtypwHCBHmvIl4VTiG/h9CyW3SJjoR3NmHDclBHGu9ra2B2R44QQ5g== X-Google-Smtp-Source: AGHT+IHCpZCTS50waL0dgGF3VRsa/7n1aRDv7ZCaWnRi5LSZFTHOlNCfRkTQz46sVpUDJjCSL/ez X-Received: by 2002:a05:6a20:8403:b0:1a3:a85c:44a5 with SMTP id c3-20020a056a20840300b001a3a85c44a5mr400052pzd.31.1711555617143; Wed, 27 Mar 2024 09:06:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711555617; cv=pass; d=google.com; s=arc-20160816; b=HpCYkyTqcbuvlTRHDSgIxoJBJfOcZ+fgImPZafVU4/sYXwH8o3QFt6HvCgUFg1itWU QMqvnXqsg+urWeCHyg4jQwTBiPjFPXx+d5fIxIP3e8GI7sjmWUQolnBxmICC4A3WbjcH mVeuVfjyb3t2DGUKHdrArT2Y/mjkf9LVU8T8zCs/LlXwaknrYss8n2J8edi0vhIlr0n1 eJcrdmeoEKKaXXYp8Hafk7bLLzPIsSgZCKaIkhGyImBiTJ59OegPqPqjRVX/H4u/RnaU XPdl8yp8pFhZV/G7Ap7DsY051BSetcmFMejAp3Ij/RQ0UwlbS+wmkMFeChtmFYLFeb6P WPkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QDTtuz/iBLnx3uLIw0aNQbjjBf12gK6PRqFn//yUSp8=; fh=p7RkI4LDDIEoVBWNTwm9p7Un7JeD8nFwO62GtPf6Kl8=; b=ARBBEVFsw8vbr7RuMkz+kFlel1dGeaW4iUgYR7m8cbwxvqBxLM6ogMr3uvoqzjULF9 zUnU4xS7YsbcXFa+bwsaPT51JwAJHsharz0i54D4v+lZboftt3S9syutU7LwF5qfMTqt MYk8T9lowgLEjIxsXqTBywCztyuEDXMBdWjliVw4Ec9zUr4SdQwPbpTOiQOai2g1nZGM 2YdbbfDtK853ScdWoFn/Dt6lGV5ncD0j7qzRv7FYF2+grLkE1t/ijfBA8caRVUZO6xIJ sOQumacf1FRp9/PmJoEGkYzzgZqAn4XOBo/DDoO7hn1y915k5OaztEv969Mxo5f0WjIh PC5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aNYvmzAK; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-121503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u10-20020a63470a000000b005e42b4bb9dasi11967503pga.213.2024.03.27.09.06.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aNYvmzAK; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-121503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B2EDBB35462 for ; Wed, 27 Mar 2024 15:29:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 391FD13C8E8; Wed, 27 Mar 2024 15:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aNYvmzAK" 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 ADABE139CEE for ; Wed, 27 Mar 2024 15:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711553036; cv=none; b=TsGnehcMcEb4e9KPOxOiOs+2NB/6uRMRC8LunkS6cW3D9RplL1UsfG4YVRSycKnRaCE8JoJCvXoyuShQFk/BB2tU7svSyxaaib4mzgFMAPxnjw7H1pQyor1RqSGl4UAJdlvsfsWm0zggZ8mKY6p+fLX6Fxw3Mwg73Ug2nGpI4Ec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711553036; c=relaxed/simple; bh=wYNV9XWYyUBPvblVuYGjSnaJhu/4sp2LbBGj9uz8/A0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hy+Szy3GMgO+ISH1ZURfWglJ+Ft+lGNNMUXoU4C4EO/2PDCRUw1trLAynVCtDDoPTpfoZyFGs6Z1jGVcdZQC0u0TMURD8UZWKmqyHCyHmuxF30+ipH5L3QF77oXZkufDhv8JJO4+zHArCT5jIKkKK6jMRUfjziDtSdewMpabUjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aNYvmzAK; arc=none smtp.client-ip=170.10.133.124 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553033; 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=QDTtuz/iBLnx3uLIw0aNQbjjBf12gK6PRqFn//yUSp8=; b=aNYvmzAKlSyQST73WTN7Llka5855qjn3W0tnjCYXF3ev8g+Os8ArLxA5L9BPti4cPlHlVL RTVypN3eIIKQmSj6HHMHQVUYUouaKuQpWJkEmgdoUIeM1DtTjWjYjbciV679YYxZyizV83 vrKNrxAh+i0Hmvj1LEOKdJttXBz+f+E= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-454-vv9_xcttO3WQUO-wAAoQyQ-1; Wed, 27 Mar 2024 11:23:52 -0400 X-MC-Unique: vv9_xcttO3WQUO-wAAoQyQ-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-69672754479so14006746d6.1 for ; Wed, 27 Mar 2024 08:23:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553031; x=1712157831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QDTtuz/iBLnx3uLIw0aNQbjjBf12gK6PRqFn//yUSp8=; b=Uobm3suYA3NP10I3+9iR+KqHMG1qsaOjsGufSXhRiDorOT3CHHUmUFDbZ1mC/imr5F r1+3ia+MfnGun+LF5ZcXViYkmLQmej0sIYVJ4rzTX3mpQkTE5sRbU6Ko5nuaHBnMUCVy gw9FIopFm9YSH3iO62KYPo/+LwQIp5bKSCF1KDLFcgDwTBfK+WlOqDMQwboTPtwsdKjE CTND76ORAr7pPuDCR1LY+Mpnr4WUDFrPuvuGTxARPOss17H/dkU8YRJ1ieB2QWfi6vgr Kfw8AYOR0k3z0wkC14wNn0cYI/y0mz2QvOUm4gmV8xSGZEkQDcqHK3Rc2CuGyU1gekzx DQ7w== X-Forwarded-Encrypted: i=1; AJvYcCULyBuuhGrL8ayRijbylhPUTlTTPfZPom9Kck3YhhZQCWNeD6l23h8eZrc4Ehc/40SSrM0wxdfxgQwrz7a2WXfihx3VK8o2BkoDjunk X-Gm-Message-State: AOJu0YzWKU+NYzc6e1NBFzMyijAxfbIOLe7pWkcnxkaYLYlRYGuFPruM P6/lqYQkcb71KlJKLsBYIio0jzZDWCXSvgQ+YYf9pRcgWUtHIhIHnP3HSz8sKA3XFfCRTAsvPLt nfJImNkMDeBKmj8Zf9FJh8GjG8sfVH7LZmT/vgwDs6LSu0YturqrdhRk/ZWX9QQ== X-Received: by 2002:a05:6214:2b86:b0:690:de72:316f with SMTP id kr6-20020a0562142b8600b00690de72316fmr14582151qvb.1.1711553030743; Wed, 27 Mar 2024 08:23:50 -0700 (PDT) X-Received: by 2002:a05:6214:2b86:b0:690:de72:316f with SMTP id kr6-20020a0562142b8600b00690de72316fmr14582105qvb.1.1711553030174; Wed, 27 Mar 2024 08:23:50 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:49 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 07/13] mm/gup: Refactor record_subpages() to find 1st small page Date: Wed, 27 Mar 2024 11:23:26 -0400 Message-ID: <20240327152332.950956-8-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-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: 8bit 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. Reviewed-by: Jason Gunthorpe 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 db35b056fc9a..c2881772216b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2779,13 +2779,16 @@ static int __gup_device_huge_pud(pud_t pud, pud_t *pudp, unsigned long addr, } #endif -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; + start_page = nth_page(page, (addr & (sz - 1)) >> PAGE_SHIFT); for (nr = 0; addr != end; nr++, addr += PAGE_SIZE) - pages[nr] = nth_page(page, nr); + pages[nr] = nth_page(start_page, nr); return nr; } @@ -2820,8 +2823,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))); - page = nth_page(pte_page(pte), (addr & (sz - 1)) >> PAGE_SHIFT); - refs = record_subpages(page, addr, end, pages + *nr); + page = pte_page(pte); + refs = record_subpages(page, sz, addr, end, pages + *nr); folio = try_grab_folio(page, refs, flags); if (!folio) @@ -2894,8 +2897,8 @@ static int gup_huge_pmd(pmd_t orig, pmd_t *pmdp, unsigned long addr, pages, nr); } - page = nth_page(pmd_page(orig), (addr & ~PMD_MASK) >> PAGE_SHIFT); - refs = record_subpages(page, addr, end, pages + *nr); + page = pmd_page(orig); + refs = record_subpages(page, PMD_SIZE, addr, end, pages + *nr); folio = try_grab_folio(page, refs, flags); if (!folio) @@ -2938,8 +2941,8 @@ static int gup_huge_pud(pud_t orig, pud_t *pudp, unsigned long addr, pages, nr); } - page = nth_page(pud_page(orig), (addr & ~PUD_MASK) >> PAGE_SHIFT); - refs = record_subpages(page, addr, end, pages + *nr); + page = pud_page(orig); + refs = record_subpages(page, PUD_SIZE, addr, end, pages + *nr); folio = try_grab_folio(page, refs, flags); if (!folio) @@ -2978,8 +2981,8 @@ static int gup_huge_pgd(pgd_t orig, pgd_t *pgdp, unsigned long addr, BUILD_BUG_ON(pgd_devmap(orig)); - page = nth_page(pgd_page(orig), (addr & ~PGDIR_MASK) >> PAGE_SHIFT); - refs = record_subpages(page, addr, end, pages + *nr); + page = pgd_page(orig); + refs = record_subpages(page, PGDIR_SIZE, addr, end, pages + *nr); folio = try_grab_folio(page, refs, flags); if (!folio) -- 2.44.0