From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.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 8F12073451 for ; Mon, 6 Jan 2025 02:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736129727; cv=none; b=ZY1+1gVhh6HKk+9hx3v7DLhRqWVLfHL0oIexvLt+pEDez014Oe9GdRPAx6ag/4Nno/hOTvnkGNHbM3UE0igZWKZHWTZwj0yolAL4O3/a2R328EN3cM7jJmh2xWj/mwusa7j/sYiXF0vlozAPKMPkEXU+cNsq9LPnEm6ADQ46eOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736129727; c=relaxed/simple; bh=rw36xXBj4ZL5c9J1v1r+oc/ldIr4Ek2uCaeNyCCUDbY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XzxCysb5d9hjMp9ij3nnKQ0oXJ9ucVhGbeRwMMQ05ej8w66t7MM9CxSfMCnQyd/Fb6og9n1uw5S3Jd1J537YkQ9IigMmYfBF4MH27XlVtzvRbhzgR+U2+RFkbDEBosDcvg+WXqCwO9vMwudlzCrqufTYj4mSUMc+Q88iLswTCk4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=I7AQMyZP; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="I7AQMyZP" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1736129719; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=1Scjx0e8WJu8kptreuXG60CMeDXRLZbo67QLe/C3F0g=; b=I7AQMyZPbi3TuSeRmStxJ4+QpWkSIf1ERO9iScxdZfsyi8FibWdMz0BlJ4xDjmEmqN83muPB4PLUOmCXu7hkjmTcKgc3hiDpXTMvudGas7AFyseSWIFQ7CKJaZ3i9Ub0e1yWSJo1sO3bGh/t+6E8MJnwy3lUCuxEGVJaRLmQGGo= Received: from 30.221.128.186(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WMzsuzC_1736129718 cluster:ay36) by smtp.aliyun-inc.com; Mon, 06 Jan 2025 10:15:18 +0800 Message-ID: <19cfa3ca-ee9e-4017-b34b-11073064dea5@linux.alibaba.com> Date: Mon, 6 Jan 2025 10:15:15 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v5 3/4] erofs: apply the page cache share feature To: Hongzhen Luo , linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org References: <20250105151208.3797385-1-hongzhen@linux.alibaba.com> <20250105151208.3797385-4-hongzhen@linux.alibaba.com> From: Gao Xiang In-Reply-To: <20250105151208.3797385-4-hongzhen@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2025/1/5 23:12, Hongzhen Luo wrote: ... > > diff --git a/fs/erofs/data.c b/fs/erofs/data.c > index 0cd6b5c4df98..fb08acbeaab6 100644 > --- a/fs/erofs/data.c > +++ b/fs/erofs/data.c > @@ -5,6 +5,7 @@ > * Copyright (C) 2021, Alibaba Cloud > */ > #include "internal.h" > +#include "pagecache_share.h" > #include > #include > > @@ -370,12 +371,21 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, > */ > static int erofs_read_folio(struct file *file, struct folio *folio) > { > - return iomap_read_folio(folio, &erofs_iomap_ops); > + int ret, pcshr; > + > + pcshr = erofs_pcshr_read_begin(file, folio); > + ret = iomap_read_folio(folio, &erofs_iomap_ops); > + erofs_pcshr_read_end(file, folio, pcshr); > + return ret; > } > > static void erofs_readahead(struct readahead_control *rac) > { > - return iomap_readahead(rac, &erofs_iomap_ops); > + int pcshr; > + > + pcshr = erofs_pcshr_readahead_begin(rac); > + iomap_readahead(rac, &erofs_iomap_ops); > + erofs_pcshr_readahead_end(rac, pcshr); > } > > static sector_t erofs_bmap(struct address_space *mapping, sector_t block) > diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c > index d4b89407822a..0b070f4b46b8 100644 > --- a/fs/erofs/inode.c > +++ b/fs/erofs/inode.c > @@ -5,6 +5,7 @@ > * Copyright (C) 2021, Alibaba Cloud > */ > #include "xattr.h" > +#include "pagecache_share.h" > #include > > static int erofs_fill_symlink(struct inode *inode, void *kaddr, > @@ -212,7 +213,9 @@ static int erofs_fill_inode(struct inode *inode) > switch (inode->i_mode & S_IFMT) { > case S_IFREG: > inode->i_op = &erofs_generic_iops; > - if (erofs_inode_is_data_compressed(vi->datalayout)) > + if (erofs_pcshr_fill_inode(inode) == 0) > + inode->i_fop = &erofs_pcshr_fops; > + else if (erofs_inode_is_data_compressed(vi->datalayout)) > inode->i_fop = &generic_ro_fops; > else > inode->i_fop = &erofs_file_fops; > diff --git a/fs/erofs/pagecache_share.c b/fs/erofs/pagecache_share.c > index 703fd17c002c..22172b5e21c7 100644 > --- a/fs/erofs/pagecache_share.c > +++ b/fs/erofs/pagecache_share.c > @@ -22,6 +22,7 @@ struct erofs_pcshr_counter { > > struct erofs_pcshr_private { > char fprt[PCSHR_FPRT_MAXLEN]; > + struct mutex mutex; > }; > > static struct erofs_pcshr_counter mnt_counter = { > @@ -84,6 +85,7 @@ static int erofs_fprt_set(struct inode *inode, void *data) > if (!ano_private) > return -ENOMEM; > memcpy(ano_private, data, sizeof(size_t) + *(size_t *)data); > + mutex_init(&ano_private->mutex); > inode->i_private = ano_private; > return 0; > } > @@ -226,3 +228,64 @@ const struct file_operations erofs_pcshr_fops = { > .get_unmapped_area = thp_get_unmapped_area, > .splice_read = filemap_splice_read, > }; > + > +int erofs_pcshr_read_begin(struct file *file, struct folio *folio) > +{ > + struct erofs_inode *vi; > + struct erofs_pcshr_private *ano_private; > + > + if (!(file && file->private_data)) > + return 0; > + > + vi = file->private_data; > + if (vi->ano_inode != file_inode(file)) > + return 0; > + > + ano_private = vi->ano_inode->i_private; > + mutex_lock(&ano_private->mutex); > + folio->mapping->host = &vi->vfs_inode; you shouldn't change `folio->mapping->host` directly. > + return 1; > +} > + > +void erofs_pcshr_read_end(struct file *file, struct folio *folio, int pcshr) > +{ > + struct erofs_pcshr_private *ano_private; > + > + if (pcshr == 0) > + return; > + > + ano_private = file_inode(file)->i_private; > + folio->mapping->host = file_inode(file); you shouldn't change `folio->mapping->host` directly and then switch back. It's too hacky. > + mutex_unlock(&ano_private->mutex); > +} > + > +int erofs_pcshr_readahead_begin(struct readahead_control *rac) > +{ > + struct erofs_inode *vi; > + struct file *file = rac->file; > + struct erofs_pcshr_private *ano_private; > + > + if (!(file && file->private_data)) > + return 0; > + > + vi = file->private_data; > + if (vi->ano_inode != file_inode(file)) > + return 0; > + > + ano_private = file_inode(file)->i_private; > + mutex_lock(&ano_private->mutex); > + rac->mapping->host = &vi->vfs_inode; Same here. Thanks, Gao Xiang