From nobody Sat Feb 7 08:45:17 2026 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 BEAB983CCE; Thu, 21 Mar 2024 13:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027016; cv=none; b=Sj24iYLER9NBqkBaipwp7Mpa6oSezHqZkllmNTIKt4JVwSOhPdkXl6xX8jopjsnZuRnbWqsB1WqTDtgu9kqL1uAYxDGARCCCntaTt9wVWbrdHW4RPsM9E4MheUSUUzKxDj/cPIFmYQoBkoTNV8oNsTLZfNC/SPWjlbqpFSafazo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027016; c=relaxed/simple; bh=1e5/zesv6FbJxBfA8IWa548K58P7zE6KEyqInepG5HQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NeN+1HkPR6HubeLE75vnSpg+ataGe1NuXPgeDIVWom6U17fexpDP3loun78RnxqKSWoLWvuF7rT6qCxtPYBltNgfIYy3Yd2mp0TNqxmW4v8sX+vPXpTOYQDfW8Dag/PYvkC2s2b9OPhysUPRm7sPmjmonC1z4BVcF0cXvogk0LA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V0mBb6TM4z1h2cS; Thu, 21 Mar 2024 21:14:15 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 1E51B1400CB; Thu, 21 Mar 2024 21:16:50 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 21:16:49 +0800 From: Kefeng Wang To: Alexander Viro , Benjamin LaHaise , Christian Brauner , Jan Kara , , Matthew Wilcox CC: , , Kefeng Wang Subject: [PATCH v2 1/3] fs: aio: use a folio in aio_setup_ring() Date: Thu, 21 Mar 2024 21:16:38 +0800 Message-ID: <20240321131640.948634-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240321131640.948634-1-wangkefeng.wang@huawei.com> References: <20240321131640.948634-1-wangkefeng.wang@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) Content-Type: text/plain; charset="utf-8" Use a folio throughout aio_setup_ring() to remove calls to compound_head(), also use folio_end_read() to simultaneously mark the folio uptodate and unlock it. Signed-off-by: Kefeng Wang Reviewed-by: Matthew Wilcox (Oracle) --- fs/aio.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 9cdaa2faa536..60da236ad575 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -527,17 +527,19 @@ static int aio_setup_ring(struct kioctx *ctx, unsigne= d int nr_events) } =20 for (i =3D 0; i < nr_pages; i++) { - struct page *page; - page =3D find_or_create_page(file->f_mapping, - i, GFP_USER | __GFP_ZERO); - if (!page) + struct folio *folio; + + folio =3D __filemap_get_folio(file->f_mapping, i, + FGP_LOCK | FGP_ACCESSED | FGP_CREAT, + GFP_USER | __GFP_ZERO); + if (IS_ERR(folio)) break; - pr_debug("pid(%d) page[%d]->count=3D%d\n", - current->pid, i, page_count(page)); - SetPageUptodate(page); - unlock_page(page); =20 - ctx->ring_pages[i] =3D page; + pr_debug("pid(%d) [%d] folio->count=3D%d\n", current->pid, i, + folio_ref_count(folio)); + folio_end_read(folio, true); + + ctx->ring_pages[i] =3D &folio->page; } ctx->nr_pages =3D i; =20 --=20 2.27.0 From nobody Sat Feb 7 08:45:17 2026 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 E26BF84A35; Thu, 21 Mar 2024 13:16:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027015; cv=none; b=Dq46x20xXC2k5MvTXRhs8UUKVP9jdSEgE8o8+3UmoMslgvv09PVA4dmyzDhbp/ZkSM+ckPgfB5shNpyGHLGIzQTLbkG2EoHpd4xeYpegXkc19wK3T7/OdOv1ozLDbnN2uOz+xnYqbxq8BRFCoEbChzZjlY0svwnABYe05pDZH4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027015; c=relaxed/simple; bh=SHnQtw4dKc0R/ujzvDsJeNwStpWmku6bHV78paAk1vM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tYWO1FdkqDmYwbt+eDyt7hL5QYJ/+sS1IU/scHrBov44F7UNarGTJhGMVTHipB8adHs4Rsa7skpUlvKwsXlxu9IGRzcGgvxxZ900vul2cdSOCzKzaE0Gd6kK4S5TI+CNMcYX7qrXScXVp3WjOpZfYRbBFouBNHiLah2yIvBE+7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V0mF614tJz1GCJd; Thu, 21 Mar 2024 21:16:26 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 9E1E51A016C; Thu, 21 Mar 2024 21:16:50 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 21:16:50 +0800 From: Kefeng Wang To: Alexander Viro , Benjamin LaHaise , Christian Brauner , Jan Kara , , Matthew Wilcox CC: , , Kefeng Wang Subject: [PATCH v2 2/3] fs: aio: use a folio in aio_free_ring() Date: Thu, 21 Mar 2024 21:16:39 +0800 Message-ID: <20240321131640.948634-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240321131640.948634-1-wangkefeng.wang@huawei.com> References: <20240321131640.948634-1-wangkefeng.wang@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) Content-Type: text/plain; charset="utf-8" Use a folio throughout aio_free_ring() to remove calls to compound_head(), also move pr_debug after folio check to remove unnecessary print. Signed-off-by: Kefeng Wang Reviewed-by: Matthew Wilcox (Oracle) --- fs/aio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 60da236ad575..738654b58bfb 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -334,14 +334,15 @@ static void aio_free_ring(struct kioctx *ctx) put_aio_ring_file(ctx); =20 for (i =3D 0; i < ctx->nr_pages; i++) { - struct page *page; - pr_debug("pid(%d) [%d] page->count=3D%d\n", current->pid, i, - page_count(ctx->ring_pages[i])); - page =3D ctx->ring_pages[i]; - if (!page) + struct folio *folio =3D page_folio(ctx->ring_pages[i]); + + if (!folio) continue; + + pr_debug("pid(%d) [%d] folio->count=3D%d\n", current->pid, i, + folio_ref_count(folio)); ctx->ring_pages[i] =3D NULL; - put_page(page); + folio_put(folio); } =20 if (ctx->ring_pages && ctx->ring_pages !=3D ctx->internal_pages) { --=20 2.27.0 From nobody Sat Feb 7 08:45:17 2026 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 A099A84A24; Thu, 21 Mar 2024 13:16:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027017; cv=none; b=o0b5uNBSGLnUU+Cg4RL7nQeA+XFF4kbyyRyaEtPe/aUgcGbJRKpO0tzaxVUQTvgBR9O7k26rp+QnxSHUBpePd1OAQLHyqPblYh3IL8cbZ4aMd3vqsfnbFVCd8P3FNlbGfKflWFSUtqV8vX9jvmtjgouv44MZ7dLcoKhJOnYIhPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711027017; c=relaxed/simple; bh=NsumehlTMfAmBoVBz4fEeLWxZOo7jZMjeA+jl2erW6k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QDC83FyhRn2YIwAaT0ThDkrq5dlx72RJIxq/yrcsLZ4UK7xf3bV0CrKO+HkcYaFz2y6HTS7qNP+Qyhx/4+aU0qEYA/B+ziidq33fVgrOc2ybBnKIX+rAp55Ta8yl+7dKJ+ku72vmZeMlQAktxVjEBqv3UAusu0AR0Vz8MHq0lRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V0mBc6n98z1h39H; Thu, 21 Mar 2024 21:14:16 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 272291A0172; Thu, 21 Mar 2024 21:16:51 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 21 Mar 2024 21:16:50 +0800 From: Kefeng Wang To: Alexander Viro , Benjamin LaHaise , Christian Brauner , Jan Kara , , Matthew Wilcox CC: , , Kefeng Wang Subject: [PATCH v2 3/3] fs: aio: convert to ring_folios and internal_folios Date: Thu, 21 Mar 2024 21:16:40 +0800 Message-ID: <20240321131640.948634-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240321131640.948634-1-wangkefeng.wang@huawei.com> References: <20240321131640.948634-1-wangkefeng.wang@huawei.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-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) Content-Type: text/plain; charset="utf-8" Since aio use folios in most functions, convert ring/internal_pages to ring/internal_folios, let's directly use folio instead of page throughout aio to remove hidden calls to compound_head(), eg, flush_dcache_page(). Signed-off-by: Kefeng Wang Reviewed-by: Matthew Wilcox (Oracle) --- fs/aio.c | 62 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 738654b58bfb..fb22a17859c6 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -122,7 +122,7 @@ struct kioctx { unsigned long mmap_base; unsigned long mmap_size; =20 - struct page **ring_pages; + struct folio **ring_folios; long nr_pages; =20 struct rcu_work free_rwork; /* see free_ioctx() */ @@ -160,7 +160,7 @@ struct kioctx { spinlock_t completion_lock; } ____cacheline_aligned_in_smp; =20 - struct page *internal_pages[AIO_RING_PAGES]; + struct folio *internal_folios[AIO_RING_PAGES]; struct file *aio_ring_file; =20 unsigned id; @@ -334,20 +334,20 @@ static void aio_free_ring(struct kioctx *ctx) put_aio_ring_file(ctx); =20 for (i =3D 0; i < ctx->nr_pages; i++) { - struct folio *folio =3D page_folio(ctx->ring_pages[i]); + struct folio *folio =3D ctx->ring_folios[i]; =20 if (!folio) continue; =20 pr_debug("pid(%d) [%d] folio->count=3D%d\n", current->pid, i, folio_ref_count(folio)); - ctx->ring_pages[i] =3D NULL; + ctx->ring_folios[i] =3D NULL; folio_put(folio); } =20 - if (ctx->ring_pages && ctx->ring_pages !=3D ctx->internal_pages) { - kfree(ctx->ring_pages); - ctx->ring_pages =3D NULL; + if (ctx->ring_folios && ctx->ring_folios !=3D ctx->internal_folios) { + kfree(ctx->ring_folios); + ctx->ring_folios =3D NULL; } } =20 @@ -442,7 +442,7 @@ static int aio_migrate_folio(struct address_space *mapp= ing, struct folio *dst, idx =3D src->index; if (idx < (pgoff_t)ctx->nr_pages) { /* Make sure the old folio hasn't already been changed */ - if (ctx->ring_pages[idx] !=3D &src->page) + if (ctx->ring_folios[idx] !=3D src) rc =3D -EAGAIN; } else rc =3D -EINVAL; @@ -466,8 +466,8 @@ static int aio_migrate_folio(struct address_space *mapp= ing, struct folio *dst, */ spin_lock_irqsave(&ctx->completion_lock, flags); folio_migrate_copy(dst, src); - BUG_ON(ctx->ring_pages[idx] !=3D &src->page); - ctx->ring_pages[idx] =3D &dst->page; + BUG_ON(ctx->ring_folios[idx] !=3D src); + ctx->ring_folios[idx] =3D dst; spin_unlock_irqrestore(&ctx->completion_lock, flags); =20 /* The old folio is no longer accessible. */ @@ -517,11 +517,11 @@ static int aio_setup_ring(struct kioctx *ctx, unsigne= d int nr_events) nr_events =3D (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event); =20 - ctx->ring_pages =3D ctx->internal_pages; + ctx->ring_folios =3D ctx->internal_folios; if (nr_pages > AIO_RING_PAGES) { - ctx->ring_pages =3D kcalloc(nr_pages, sizeof(struct page *), - GFP_KERNEL); - if (!ctx->ring_pages) { + ctx->ring_folios =3D kcalloc(nr_pages, sizeof(struct folio *), + GFP_KERNEL); + if (!ctx->ring_folios) { put_aio_ring_file(ctx); return -ENOMEM; } @@ -540,7 +540,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned = int nr_events) folio_ref_count(folio)); folio_end_read(folio, true); =20 - ctx->ring_pages[i] =3D &folio->page; + ctx->ring_folios[i] =3D folio; } ctx->nr_pages =3D i; =20 @@ -573,7 +573,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned = int nr_events) ctx->user_id =3D ctx->mmap_base; ctx->nr_events =3D nr_events; /* trusted copy */ =20 - ring =3D page_address(ctx->ring_pages[0]); + ring =3D folio_address(ctx->ring_folios[0]); ring->nr =3D nr_events; /* user copy */ ring->id =3D ~0U; ring->head =3D ring->tail =3D 0; @@ -581,7 +581,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned = int nr_events) ring->compat_features =3D AIO_RING_COMPAT_FEATURES; ring->incompat_features =3D AIO_RING_INCOMPAT_FEATURES; ring->header_length =3D sizeof(struct aio_ring); - flush_dcache_page(ctx->ring_pages[0]); + flush_dcache_folio(ctx->ring_folios[0]); =20 return 0; } @@ -692,9 +692,9 @@ static int ioctx_add_table(struct kioctx *ctx, struct m= m_struct *mm) =20 /* While kioctx setup is in progress, * we are protected from page migration - * changes ring_pages by ->ring_lock. + * changes ring_folios by ->ring_lock. */ - ring =3D page_address(ctx->ring_pages[0]); + ring =3D folio_address(ctx->ring_folios[0]); ring->id =3D ctx->id; return 0; } @@ -1036,7 +1036,7 @@ static void user_refill_reqs_available(struct kioctx = *ctx) * against ctx->completed_events below will make sure we do the * safe/right thing. */ - ring =3D page_address(ctx->ring_pages[0]); + ring =3D folio_address(ctx->ring_folios[0]); head =3D ring->head; =20 refill_reqs_available(ctx, head, ctx->tail); @@ -1148,12 +1148,12 @@ static void aio_complete(struct aio_kiocb *iocb) if (++tail >=3D ctx->nr_events) tail =3D 0; =20 - ev_page =3D page_address(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); + ev_page =3D folio_address(ctx->ring_folios[pos / AIO_EVENTS_PER_PAGE]); event =3D ev_page + pos % AIO_EVENTS_PER_PAGE; =20 *event =3D iocb->ki_res; =20 - flush_dcache_page(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); + flush_dcache_folio(ctx->ring_folios[pos / AIO_EVENTS_PER_PAGE]); =20 pr_debug("%p[%u]: %p: %p %Lx %Lx %Lx\n", ctx, tail, iocb, (void __user *)(unsigned long)iocb->ki_res.obj, @@ -1166,10 +1166,10 @@ static void aio_complete(struct aio_kiocb *iocb) =20 ctx->tail =3D tail; =20 - ring =3D page_address(ctx->ring_pages[0]); + ring =3D folio_address(ctx->ring_folios[0]); head =3D ring->head; ring->tail =3D tail; - flush_dcache_page(ctx->ring_pages[0]); + flush_dcache_folio(ctx->ring_folios[0]); =20 ctx->completed_events++; if (ctx->completed_events > 1) @@ -1241,8 +1241,8 @@ static long aio_read_events_ring(struct kioctx *ctx, sched_annotate_sleep(); mutex_lock(&ctx->ring_lock); =20 - /* Access to ->ring_pages here is protected by ctx->ring_lock. */ - ring =3D page_address(ctx->ring_pages[0]); + /* Access to ->ring_folios here is protected by ctx->ring_lock. */ + ring =3D folio_address(ctx->ring_folios[0]); head =3D ring->head; tail =3D ring->tail; =20 @@ -1263,20 +1263,20 @@ static long aio_read_events_ring(struct kioctx *ctx, while (ret < nr) { long avail; struct io_event *ev; - struct page *page; + struct folio *folio; =20 avail =3D (head <=3D tail ? tail : ctx->nr_events) - head; if (head =3D=3D tail) break; =20 pos =3D head + AIO_EVENTS_OFFSET; - page =3D ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]; + folio =3D ctx->ring_folios[pos / AIO_EVENTS_PER_PAGE]; pos %=3D AIO_EVENTS_PER_PAGE; =20 avail =3D min(avail, nr - ret); avail =3D min_t(long, avail, AIO_EVENTS_PER_PAGE - pos); =20 - ev =3D page_address(page); + ev =3D folio_address(folio); copy_ret =3D copy_to_user(event + ret, ev + pos, sizeof(*ev) * avail); =20 @@ -1290,9 +1290,9 @@ static long aio_read_events_ring(struct kioctx *ctx, head %=3D ctx->nr_events; } =20 - ring =3D page_address(ctx->ring_pages[0]); + ring =3D folio_address(ctx->ring_folios[0]); ring->head =3D head; - flush_dcache_page(ctx->ring_pages[0]); + flush_dcache_folio(ctx->ring_folios[0]); =20 pr_debug("%li h%u t%u\n", ret, head, tail); out: --=20 2.27.0