Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4561505pxv; Tue, 20 Jul 2021 06:41:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwf9AY+ARMvDPcHTj4fY+s1xyJhL/ZKud67dzh3Quu6ni7ZKczep+BEWeQ0mbVrMUJYY4Cf X-Received: by 2002:a05:6402:692:: with SMTP id f18mr41600600edy.327.1626788502141; Tue, 20 Jul 2021 06:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626788502; cv=none; d=google.com; s=arc-20160816; b=PYnQm1tmEidGKjw7Z4x7312mlayKEl2tOW6ZFtfilm0PeGrvIwYhnPNU16XxLc4hRI QG695mJhPCDdJKShrrqCrsLViqM/5s3+K7WXmdb8dfEIwtJH884km1IsI+R4IDQU2rGc HTTcjMrsHEmSpoz+WjlzNWrVcOosbRxVd/rRLR2K5b2B4ckTvp4Dau0upuGQOaYmeebB THREhc23ZK9fX5OFOC0/io2MM1ZBs06JhxFHnzwVxQlEkoZyLz2eMzDYrDBayDATEbSe 67QxOF1hVNUvGgW5btKfHr3eLDIZWTHHY+nvLAEDqmJFZH0On2/RXcRYrdsYxp7QQJHg gPMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=FlZoTkPWMlVwab1IVmxj8hksmqfSz8jEiWzUKPoGYjc=; b=AKKws5RQFkRnLo14hX3eSmqeB5NIaKkgJki3zh9BN/yl29oW1IwIrTXYuFe12uu6N8 G+8BJUNc9nmxewnLratWTpotfcxiVJOQmjASwD1kU9IWYlNKiUhrO7wTGqZLU3TfunSz Y/r2JcQ4MP7LxG32cEDZExrSYNj38mHwj1pfni/XCoFmIbIZjHLYGmjDhqHipar40sFt xk2nOXJNK1IZzOgtgr8qZzJYDY/fKu8Zz7TMIP0ZpZ5f69+ZPqcDQzWaGn7sRbG5A/MA YY8uWSgqi/OwJJk5xNSDm7iYoU54JQBoEWMGgfVa1XmCkSYMW6sUTnJ5hfzsOj/7Wyib JiNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h9si23085356edw.501.2021.07.20.06.41.18; Tue, 20 Jul 2021 06:41:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237236AbhGTM6V (ORCPT + 99 others); Tue, 20 Jul 2021 08:58:21 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:33664 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238642AbhGTMza (ORCPT ); Tue, 20 Jul 2021 08:55:30 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0UgQyeEE_1626788156; Received: from e18g09479.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0UgQyeEE_1626788156) by smtp.aliyun-inc.com(127.0.0.1); Tue, 20 Jul 2021 21:36:06 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org Cc: LKML , Gao Xiang , Christoph Hellwig , "Darrick J . Wong" , Matthew Wilcox , Andreas Gruenbacher Subject: [PATCH v4] iomap: support tail packing inline read Date: Tue, 20 Jul 2021 21:35:54 +0800 Message-Id: <20210720133554.44058-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This tries to add tail packing inline read to iomap, which can support several inline tail blocks. Similar to the previous approach, it cleans post-EOF in one iteration. The write path remains untouched since EROFS cannot be used for testing. It'd be better to be implemented if upcoming real users care rather than leave untested dead code around. Cc: Christoph Hellwig Cc: Darrick J. Wong Cc: Matthew Wilcox Cc: Andreas Gruenbacher Signed-off-by: Gao Xiang --- v3: https://lore.kernel.org/r/20210719144747.189634-1-hsiangkao@linux.alibaba.com changes since v3: - update return value type of iomap_read_inline_data to int; - fix iomap_write_begin_inline() pointed out by Andreas. fs/iomap/buffered-io.c | 52 ++++++++++++++++++++++++++---------------- fs/iomap/direct-io.c | 11 +++++---- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 87ccb3438bec..0edc8bbb35d1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -205,25 +205,25 @@ struct iomap_readpage_ctx { struct readahead_control *rac; }; -static void +static int iomap_read_inline_data(struct inode *inode, struct page *page, - struct iomap *iomap) + struct iomap *iomap, loff_t pos) { - size_t size = i_size_read(inode); + unsigned int size, poff = offset_in_page(pos); void *addr; - if (PageUptodate(page)) - return; - - BUG_ON(page_has_private(page)); - BUG_ON(page->index); - BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data)); + /* inline source data must be inside a single page */ + BUG_ON(iomap->length > PAGE_SIZE - offset_in_page(iomap->inline_data)); + /* handle tail-packing blocks cross the current page into the next */ + size = min_t(unsigned int, iomap->length + pos - iomap->offset, + PAGE_SIZE - poff); addr = kmap_atomic(page); - memcpy(addr, iomap->inline_data, size); - memset(addr + size, 0, PAGE_SIZE - size); + memcpy(addr + poff, iomap->inline_data - iomap->offset + pos, size); + memset(addr + poff + size, 0, PAGE_SIZE - poff - size); kunmap_atomic(addr); - SetPageUptodate(page); + iomap_set_range_uptodate(page, poff, PAGE_SIZE - poff); + return PAGE_SIZE - poff; } static inline bool iomap_block_needs_zeroing(struct inode *inode, @@ -246,18 +246,18 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, unsigned poff, plen; sector_t sector; - if (iomap->type == IOMAP_INLINE) { - WARN_ON_ONCE(pos); - iomap_read_inline_data(inode, page, iomap); - return PAGE_SIZE; - } - - /* zero post-eof blocks as the page may be mapped */ iop = iomap_page_create(inode, page); + /* needs to skip some leading uptodate blocks */ iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen); if (plen == 0) goto done; + if (iomap->type == IOMAP_INLINE) { + plen = iomap_read_inline_data(inode, page, iomap, pos); + goto done; + } + + /* zero post-eof blocks as the page may be mapped */ if (iomap_block_needs_zeroing(inode, iomap, pos)) { zero_user(page, poff, plen); iomap_set_range_uptodate(page, poff, plen); @@ -589,6 +589,18 @@ __iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, int flags, return 0; } +static int iomap_write_begin_inline(struct inode *inode, loff_t pos, + struct page *page, struct iomap *srcmap) +{ + /* needs more work for the tailpacking case, disable for now */ + if (WARN_ON_ONCE(srcmap->offset != 0)) + return -EIO; + if (PageUptodate(page)) + return 0; + iomap_read_inline_data(inode, page, srcmap, 0); + return 0; +} + static int iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, struct page **pagep, struct iomap *iomap, struct iomap *srcmap) @@ -618,7 +630,7 @@ iomap_write_begin(struct inode *inode, loff_t pos, unsigned len, unsigned flags, } if (srcmap->type == IOMAP_INLINE) - iomap_read_inline_data(inode, page, srcmap); + status = iomap_write_begin_inline(inode, pos, page, srcmap); else if (iomap->flags & IOMAP_F_BUFFER_HEAD) status = __block_write_begin_int(page, pos, len, NULL, srcmap); else diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 9398b8c31323..ee6309967b77 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -379,22 +379,25 @@ iomap_dio_inline_actor(struct inode *inode, loff_t pos, loff_t length, { struct iov_iter *iter = dio->submit.iter; size_t copied; + void *dst = iomap->inline_data + pos - iomap->offset; - BUG_ON(pos + length > PAGE_SIZE - offset_in_page(iomap->inline_data)); + /* inline data must be inside a single page */ + BUG_ON(length > PAGE_SIZE - offset_in_page(iomap->inline_data)); if (dio->flags & IOMAP_DIO_WRITE) { loff_t size = inode->i_size; if (pos > size) - memset(iomap->inline_data + size, 0, pos - size); - copied = copy_from_iter(iomap->inline_data + pos, length, iter); + memset(iomap->inline_data + size - iomap->offset, + 0, pos - size); + copied = copy_from_iter(dst, length, iter); if (copied) { if (pos + copied > size) i_size_write(inode, pos + copied); mark_inode_dirty(inode); } } else { - copied = copy_to_iter(iomap->inline_data + pos, length, iter); + copied = copy_to_iter(dst, length, iter); } dio->size += copied; return copied; -- 2.24.4