From mboxrd@z Thu Jan 1 00:00:00 1970 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 DD9DFC3DA6E for ; Thu, 4 Jan 2024 00:21:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 701FD6B0206; Wed, 3 Jan 2024 19:21:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B2946B0208; Wed, 3 Jan 2024 19:21:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A1AF6B020A; Wed, 3 Jan 2024 19:21:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4C53A6B0206 for ; Wed, 3 Jan 2024 19:21:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1825840824 for ; Thu, 4 Jan 2024 00:21:12 +0000 (UTC) X-FDA: 81639723984.22.5C98B19 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id C9727120002 for ; Thu, 4 Jan 2024 00:21:09 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XfZEe2HS; spf=pass (imf29.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704327670; a=rsa-sha256; cv=none; b=PXOAlGTb9mD0iqc1LWm0KuKNgEvLpOTo1knporIRgJqGREIM2cwdXeAdje3VnKp11Hu6tp 8zB20l9oATKNFTXfXJldJYsabzynU0uBSe8Pl5ZTdC6lPyRZI2z/AVIygjXNU9Ri585NUN V97lb0eaob5RnEkJIXTnbPQiLIyhXno= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XfZEe2HS; spf=pass (imf29.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704327670; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZMekwh6/VXyVBLkcYc6F9IB7kKVJHmFQ3yLg6HCzIPI=; b=i+cWaSuwuBUQhn1pQ13nBlOWFEE5JhOAOjkcvKeTvx0Zr7ZlatRFMtUSaNHiPoAES5hxo1 dR/Ney4Cif0dwW+85W18IrjZBgJADP+S82Aip4/kK0TWVNHE3amqoMX59PInengl3e/6gw vfrHBoC4tMn8eCBj1Of2Nm+PicmsjBA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9CE50CE13A2; Thu, 4 Jan 2024 00:21:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3A7CC433C9; Thu, 4 Jan 2024 00:21:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704327665; bh=6L1/GxZRr5i5NZtIy00q/HS8HPj+3JD6Nq2ciV6p14M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XfZEe2HSmiBbJ9/88Rr5bstB0Bx4g4YcOhDLic56LFMBL/nX9YbyInKzEl/iB4rU6 ptuuryMwms8m1vcCKecYhMaWe/f90s30EZLta0iasHn+MC2k80jrV6M2ArNakF4Yqn I21EAzybs60GkS0U5+5Hz9R6S+OOX+exvkGUynITRzSNgZzOWAGcB6ZzPl+j9jolAs boL8JAzdEi2o0HR4Dhzia51f9lI8D7hZWZoUhOy853l9TxKPIZdvD1GXd+MNDLcdkf TXZxQJgm1M8/SyIG7I229NSZJjOPJHXETuIFjWg7aL9F6J3I9U93qNvx6jY02ke5sD GiSh2H+DGCjiA== Date: Wed, 3 Jan 2024 16:21:05 -0800 From: "Darrick J. Wong" To: Christoph Hellwig Cc: Chandan Babu R , Hugh Dickins , Andrew Morton , linux-xfs@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 15/15] xfs: use xfile_get_page and xfile_put_page in xfile_obj_load Message-ID: <20240104002105.GI361584@frogsfrogsfrogs> References: <20240103084126.513354-1-hch@lst.de> <20240103084126.513354-16-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103084126.513354-16-hch@lst.de> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C9727120002 X-Stat-Signature: wsqng9f34qcok4fsao7ud4jehaotc54r X-Rspam-User: X-HE-Tag: 1704327669-95694 X-HE-Meta: U2FsdGVkX1/f3Jm2Gq92AoCyZXrB71yo/fOIrPa9uNRfCwmurXEGMchKGLPvuCzx4QA4zAILmuJYrhzRJ5pJp2bDLi/aOHRSfBalBNDF0PnLLTbeXepG62NKRwwGnEoyonqlikF35FTBbMczpi+4aLhzCQbR4yjYsny8sJnEQjYyhGW5fbbSOmkqIQIPCAQZgtWcnAIUfaoE3fg3tSC5k019XTmx20Mnl50UJvkkB8LXZo5fL6EsjfdHvMZINFdri3Fbg9SImCh3tuZ1hy8JESGm6sgVABoolkHmvGlF0EqF1DTAcQz/QrpMjiGV7rKZ0cu3RD37T+p/0Be8VuXLjn8IVG1tJ/NtIS3I2Mq3/JGjbgDOblrZ4qyw6EG+bHfLn1budEDdVivUCiRf1h9qZNHRrqN8FZFnTEnw4Lm3Um/JbFw8nj4ucgojO9y86JslR/agHJ1/8ZYDd95xNdPoisdSbwrrAGtibPYq7EXaMSWUh/shKysz+xwNqPP9dCafq2XnGbsqZyK6Yg0ISJgbdQKwTYfq7CpDL9J6yLEMUarr65zNlh5+nnZC1cXkNrgUKZpW2rzTAcdyRrvg5rvw5ewBO0QDsbbISO6AMTsFef1trDjPH4lPIF0kkWgGgH3v7veXSGqk6C//ofk8l8QqPi/xvNgYGG2uEz3wsfsz1ypCqYBOU241DiZlDgEOsn7lrZdWiZlWt5s0s0yZ2SbGnaIB1Ihhou3x5vM63o2q0Vep90ZOwJwjdCZ78qay1N6Io2ZYcP1Oeqq3/BnGsbBDCSITkQzOws2F20erVXCSDrUoz0+zXRx//UVepSuB9/L5bzAmaUO4HBMJK2aDdbBDamOwkGblF2cldRjm4Q/pPSvxjtGjX81YtMCUPmd0AtQhCA1A5BNdJdr5uPP8l0xP5NvmwoZ6N5mO2BsScAM/q6wHt9G7cASf4WDPK27zw6HDx7YXU8I3NMfACHI9pVj DOzbOUoe B75WWhJOFxdZCg3aaGD0Q8wBQtHPmcSKe/F4jeKl/4/QZcckQNvj9S7GpY/QhSNX5xsBrMJXLXrydW9dNCZMWdp/VlixcfvAbSqIKmDTu3ceZP/FL2uICL+dV3dFdh4s1Z/9eDs8+Ti++x0Dz2AUXhFE39pjUdOc/GDJEOM6wwatM9d1GPeyEIG3EPv9Z5GYE9xrlTe1QhbNXUkyXsPYxe83sT77vQYnEP/giYW1EMAwDGHT2cTqhNUO/F6n8qQysSxM7Z5XyD70LERsdfXPrYQdGNGTEM7O/z/1e 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: On Wed, Jan 03, 2024 at 08:41:26AM +0000, Christoph Hellwig wrote: > Switch xfile_obj_load to use xfile_get_page and xfile_put_page to access > the shmem page cache. The former uses shmem_get_folio(..., SGP_READ), > which returns a NULL folio for a hole instead of allocating one to > optimize the case where the caller is reading from a whole and doesn't > want to a zeroed folio to the page cache. > > Signed-off-by: Christoph Hellwig > --- > fs/xfs/scrub/xfile.c | 51 +++++++++++--------------------------------- > 1 file changed, 12 insertions(+), 39 deletions(-) > > diff --git a/fs/xfs/scrub/xfile.c b/fs/xfs/scrub/xfile.c > index 987b03df241b02..3f9e416376d2f7 100644 > --- a/fs/xfs/scrub/xfile.c > +++ b/fs/xfs/scrub/xfile.c > @@ -34,13 +34,6 @@ > * xfiles assume that the caller will handle all required concurrency > * management; standard vfs locks (freezer and inode) are not taken. Reads > * and writes are satisfied directly from the page cache. > - * > - * NOTE: The current shmemfs implementation has a quirk that in-kernel reads > - * of a hole cause a page to be mapped into the file. If you are going to > - * create a sparse xfile, please be careful about reading from uninitialized > - * parts of the file. These pages are !Uptodate and will eventually be > - * reclaimed if not written, but in the short term this boosts memory > - * consumption. Awright, this goes away finally! Reviewed-by: Darrick J. Wong --D > */ > > /* > @@ -117,58 +110,38 @@ xfile_obj_load( > size_t count, > loff_t pos) > { > - struct inode *inode = file_inode(xf->file); > - struct address_space *mapping = inode->i_mapping; > - struct page *page = NULL; > - unsigned int pflags; > - int error = 0; > - > if (count > MAX_RW_COUNT) > return -ENOMEM; > - if (inode->i_sb->s_maxbytes - pos < count) > + if (file_inode(xf->file)->i_sb->s_maxbytes - pos < count) > return -ENOMEM; > > trace_xfile_obj_load(xf, pos, count); > > - pflags = memalloc_nofs_save(); > while (count > 0) { > + struct page *page; > unsigned int len; > > len = min_t(ssize_t, count, PAGE_SIZE - offset_in_page(pos)); > - > - /* > - * In-kernel reads of a shmem file cause it to allocate a page > - * if the mapping shows a hole. Therefore, if we hit ENOMEM > - * we can continue by zeroing the caller's buffer. > - */ > - page = shmem_read_mapping_page_gfp(mapping, pos >> PAGE_SHIFT, > - __GFP_NOWARN); > - if (IS_ERR(page)) { > - error = PTR_ERR(page); > - if (error != -ENOMEM) { > - error = -ENOMEM; > - break; > - } > - > + page = xfile_get_page(xf, pos, len, 0); > + if (IS_ERR(page)) > + return -ENOMEM; > + if (!page) { > + /* > + * No data stored at this offset, just zero the output > + * buffer. > + */ > memset(buf, 0, len); > goto advance; > } > - > - /* > - * xfile pages must never be mapped into userspace, so > - * we skip the dcache flush. > - */ > memcpy(buf, page_address(page) + offset_in_page(pos), len); > - put_page(page); > - > + xfile_put_page(xf, page); > advance: > count -= len; > pos += len; > buf += len; > } > - memalloc_nofs_restore(pflags); > > - return error; > + return 0; > } > > /* > -- > 2.39.2 > >