Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3522059pxv; Mon, 26 Jul 2021 06:06:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkHCChHI8s5nLKl84f6EuSsV8kGbRs/TKbMPYfnmygjw9GViH09d6oOQXfRxAT9AQG0cCI X-Received: by 2002:a17:906:d182:: with SMTP id c2mr17449059ejz.111.1627304775530; Mon, 26 Jul 2021 06:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627304775; cv=none; d=google.com; s=arc-20160816; b=nPxMMRV9TDw65r22KFd2VRewYLR43rOr7ek7oDYdgvdu1sJpsAhX9LLQaUNcI4/yaN wNoPoNSEit0CVkqhlhGvSEw8cgirrOJPJqBq50mWOvnmg+ck3ZnF68GGGU73qxCu8LIh UwODGVMICYm/YIvqShaQMaSpC+08/7u/81u8DxFsTKoJwdH2x67aI2UpSz9y5NY14RRf k/XIJdgG8f1whT9k1tuaBOQKsjFCBxb6EGzp1r1xsuoFB0oGoLWG8FNDL1gQyLNZgNRr UYizz7arrY+fU6MWjGwVyXFXSdoQ7sETGHcw4X40C3dUiiP93Fz5aaM9tOQBhFzz0AeG qFPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=IGNIpIsmHVsxBMU4UuRo09+EWFGkpjab3tHKGtaAqJI=; b=LHovp0Dq+jUiwu1KaFZxI1XEDv5HgQk5jSjUZwKpqpYKffshicqQZ3+EtvS2Wi21GU p2FUEQXeregtxR+l14KXlomLz55KWnzo3T9B+6ei97ID+LO7tfYy3FquZldbvwIV8OT9 owI2zKYtzI3QyVYRwIeQYVXRRM38RfXzdHQY3KWAHWwjJJ0u2S/BkFU/qyytstSf5fw4 9089Pe/NWmhPUAkDY8atyNGxAeer6xhZlMcyAxVLrfBZ4/Kh0WVC3UTxGYQPokYel9Z5 lgdiVND54S7A+0gW1oj5F3QQ3ZgsLUSp8/4Zp/7zTJPNh7bgslVahpbxk/Mrosm73iEU Lm5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="VETI/bNI"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g24si7387782eds.521.2021.07.26.06.05.52; Mon, 26 Jul 2021 06:06:15 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="VETI/bNI"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232955AbhGZMXA (ORCPT + 99 others); Mon, 26 Jul 2021 08:23:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38903 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232702AbhGZMXA (ORCPT ); Mon, 26 Jul 2021 08:23:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627304608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=IGNIpIsmHVsxBMU4UuRo09+EWFGkpjab3tHKGtaAqJI=; b=VETI/bNIjI+DY1843n+Kr23O9DWk3dNS4wpWIecmIs8A7sIQzUYIj9nKFnNJEqMlaPQbUJ SG5Inj38NkYlUJIOIuxhfjoX4xlOelTd+8xyn/WgOLEadm8qgh20NmTkYboN5nl6SArAU9 lZvf8dvx7bI+316+SAUAqAfiaqR+GKo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-149-0jIP-PS5NHKlL3Nqyz4Cdg-1; Mon, 26 Jul 2021 09:03:26 -0400 X-MC-Unique: 0jIP-PS5NHKlL3Nqyz4Cdg-1 Received: by mail-wr1-f70.google.com with SMTP id o11-20020a5d474b0000b02901533f8ed22cso3242819wrs.22 for ; Mon, 26 Jul 2021 06:03:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IGNIpIsmHVsxBMU4UuRo09+EWFGkpjab3tHKGtaAqJI=; b=tjEY9D0FBlLbsJyYP1XNwavo7iYErjPG31SrMyWpUt0mx3ADeO7lvHOLd1mFqphapA vUxHorRqgMoWBUwUZVEqbFIEs7xtMHRFoO1llfUDUGz1SZLT7yNhMdbZfkHjkEe4Q1VS yyl1/5nAt0ZJq6xQL+GL4X9t+Pfny/zux9NhqcUO++FRLVdVOZTineOvaZMibh4g1N+8 qk16vtDF1UUYRDNsocdPVjtAHOuvDxevMbIehbWMSMp3bk0xaM9BM3nd4LzkUtEtD36z b8atYKSAlH3EfxHrMy8jjWrSlelL0+KzpGubGlUoLybATJ/xhJaEU+PaxO3p4h+QRb6y JLUA== X-Gm-Message-State: AOAM5302MxEtd0/q2CoEb3jteX+Em/yLFLWMiMqAL3cDcoL4SK/2bkIy 620JzcjR797gKPqMPIYJT9VKJk46OHJBbuxkgzG1bo+zVWnQg6SuO1FI7vrSILPj2eiHt8BgvVS AKhi7v1nYsmDXjdnmHTWVJls8uZEtvVHqYziL54ia X-Received: by 2002:a1c:2282:: with SMTP id i124mr17049204wmi.166.1627304605647; Mon, 26 Jul 2021 06:03:25 -0700 (PDT) X-Received: by 2002:a1c:2282:: with SMTP id i124mr17049182wmi.166.1627304605390; Mon, 26 Jul 2021 06:03:25 -0700 (PDT) MIME-Version: 1.0 References: <20210723174131.180813-1-hsiangkao@linux.alibaba.com> <20210725221639.426565-1-agruenba@redhat.com> <20210726110611.459173-1-agruenba@redhat.com> In-Reply-To: From: Andreas Gruenbacher Date: Mon, 26 Jul 2021 15:03:14 +0200 Message-ID: Subject: Re: [PATCH v7] iomap: make inline data support more flexible To: Matthew Wilcox Cc: Gao Xiang , Christoph Hellwig , "Darrick J . Wong" , Huang Jianan , linux-erofs@lists.ozlabs.org, linux-fsdevel , LKML , Andreas Gruenbacher Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 26, 2021 at 2:33 PM Matthew Wilcox wrote: > On Mon, Jul 26, 2021 at 01:06:11PM +0200, Andreas Gruenbacher wrote: > > @@ -671,11 +683,11 @@ static size_t iomap_write_end_inline(struct inode *inode, struct page *page, > > void *addr; > > > > WARN_ON_ONCE(!PageUptodate(page)); > > - BUG_ON(pos + copied > PAGE_SIZE - offset_in_page(iomap->inline_data)); > > + BUG_ON(!iomap_inline_data_size_valid(iomap)); > > > > flush_dcache_page(page); > > addr = kmap_atomic(page); > > - memcpy(iomap->inline_data + pos, addr + pos, copied); > > + memcpy(iomap_inline_data(iomap, pos), addr + pos, copied); > > kunmap_atomic(addr); > > > > mark_inode_dirty(inode); > > Only tangentially related ... why do we memcpy the data into the tail > at write_end() time instead of at writepage() time? I see there's a > workaround for that in gfs2's page_mkwrite(): > > if (gfs2_is_stuffed(ip)) { > err = gfs2_unstuff_dinode(ip); > > (an mmap store cannot change the size of the file, so this would be > unnecessary) Not sure if an additional __set_page_dirty_nobuffers is needed in that case, but doing the writeback at writepage time should work just as well. It's just that gfs2 did it at write time historically. The un-inlining in gfs2_page_mkwrite() could probably also be removed. I can give this a try, but I'll unfortunately be AFK for the next couple of days. > Something like this ... > > diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c > index 87ccb3438bec..3aeebe899fc5 100644 > --- a/fs/iomap/buffered-io.c > +++ b/fs/iomap/buffered-io.c > @@ -665,9 +665,10 @@ static size_t __iomap_write_end(struct inode *inode, loff_t pos, size_t len, > return copied; > } > > -static size_t iomap_write_end_inline(struct inode *inode, struct page *page, > - struct iomap *iomap, loff_t pos, size_t copied) > +static int iomap_write_inline_data(struct inode *inode, struct page *page, > + struct iomap *iomap) > { > + size_t size = i_size_read(inode) - page_offset(page); You surely mean inode->i_size - iomap->offset. > void *addr; > > WARN_ON_ONCE(!PageUptodate(page)); > @@ -675,11 +676,10 @@ static size_t iomap_write_end_inline(struct inode *inode, struct page *page, > > flush_dcache_page(page); > addr = kmap_atomic(page); > - memcpy(iomap->inline_data + pos, addr + pos, copied); > + memcpy(iomap->inline_data, addr, size); > kunmap_atomic(addr); > > - mark_inode_dirty(inode); > - return copied; > + return 0; > } > > /* Returns the number of bytes copied. May be 0. Cannot be an errno. */ > @@ -691,9 +691,7 @@ static size_t iomap_write_end(struct inode *inode, loff_t pos, size_t len, > loff_t old_size = inode->i_size; > size_t ret; > > - if (srcmap->type == IOMAP_INLINE) { > - ret = iomap_write_end_inline(inode, page, iomap, pos, copied); > - } else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { > + if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { > ret = block_write_end(NULL, inode->i_mapping, pos, len, copied, > page, NULL); > } else { > @@ -1314,6 +1312,9 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, > > WARN_ON_ONCE(iop && atomic_read(&iop->write_bytes_pending) != 0); > > + if (wpc->iomap.type == IOMAP_INLINE) > + return iomap_write_inline_data(inode, page, iomap); > + > /* > * Walk through the page to find areas to write back. If we run off the > * end of the current map or find the current map invalid, grab a new > @@ -1328,8 +1329,6 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, > error = wpc->ops->map_blocks(wpc, inode, file_offset); > if (error) > break; > - if (WARN_ON_ONCE(wpc->iomap.type == IOMAP_INLINE)) > - continue; > if (wpc->iomap.type == IOMAP_HOLE) > continue; > iomap_add_to_ioend(inode, file_offset, page, iop, wpc, wbc, > Thanks, Andreas