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 X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A106C2D0C9 for ; Wed, 11 Dec 2019 14:39:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 071D920836 for ; Wed, 11 Dec 2019 14:39:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="ItJvVAGS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 071D920836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 776886B326E; Wed, 11 Dec 2019 09:39:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 726BD6B326F; Wed, 11 Dec 2019 09:39:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 616736B3270; Wed, 11 Dec 2019 09:39:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0112.hostedemail.com [216.40.44.112]) by kanga.kvack.org (Postfix) with ESMTP id 4BB236B326E for ; Wed, 11 Dec 2019 09:39:27 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id E08CC2498 for ; Wed, 11 Dec 2019 14:39:26 +0000 (UTC) X-FDA: 76253118732.13.angle98_182fda61f0a55 X-HE-Tag: angle98_182fda61f0a55 X-Filterd-Recvd-Size: 7225 Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Dec 2019 14:39:26 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id x184so1918840pfb.3 for ; Wed, 11 Dec 2019 06:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=JIZ0Z2kz72zIQNA6G4bYzFn40yhbQ+MQB3rkdPMRBVA=; b=ItJvVAGSLpP2Qi+JlwGHdyO1sjXtP2FS1mtHFHhX0wx1Yd51DPvWT7RxgPM5kfmFl2 z5h+0QPmcrpRx8D481hiFimlEXuB5e3/Q6Mh5auXLERPFLAXVjjcMTLPfVAJyc4iOcMu NAkddftDmeAyKALkUXIbLZnXkhOA/BzyOz2aSS6ZWODXr2fObOUeB9Pxrul75Zw5LO3o fmvHxpomY5OKDtxH7sLGXx4OFI2EsHcqHnjaG5I9VQpCzMCU0anGQuibyLwlqOFDNEqY NIoPj5cAsWz3bed/Ph/aApEzac2HTpk/om2JSCJPmteYqBbDC4EpQIDy1A4FoTYmNhxv iVig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JIZ0Z2kz72zIQNA6G4bYzFn40yhbQ+MQB3rkdPMRBVA=; b=ctwGhy5dDzds0jHTauBOOlXUh55khW0axcNqlSHBMkaOnqAz6fQhcy90th0RHSyYmu U/fe7CcAR/SaWvufzG8BniiPq1KrpTQfljL1ju9AtPXaBgJLXSerBOY9QQb6Qrq0bxin sBJRPkQIv9Mvjo3k1cVp7+8iHxiUP05DpZlXA4L9qBVHtbvfnwFQgS9h8gNr0IMu9q1p G6RfuNl6BCS79pqLDehkN3DM1V9lexdogzh7te/Fx795IVyfMyJT5sRbLjAtq6GvYLPt sfsAdvlVlSMXm8YcUSOIPcojePKauLsOBvHDeKJMQwicrit/D0iKmKSmpVDW9uZOUyTV JQRQ== X-Gm-Message-State: APjAAAUlXp+jP6ANWJoaED9KCXwfvasuSb8aoyt9SSPikpo3ADKXnl/t IeUWjjOR4iTXcIZeU82hd2Jm+w== X-Google-Smtp-Source: APXvYqyGeiGi1rdrfdXNO/icOwO5gEDSo2Gr7BxhF5G7xiGB1lEMbNYINxHWG76c4XmZgIber6/vfA== X-Received: by 2002:a63:ce4b:: with SMTP id r11mr4616880pgi.419.1576075164601; Wed, 11 Dec 2019 06:39:24 -0800 (PST) Received: from ?IPv6:2620:10d:c081:1130::1014? ([2620:10d:c090:180::50da]) by smtp.gmail.com with ESMTPSA id x197sm3578266pfc.1.2019.12.11.06.39.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Dec 2019 06:39:23 -0800 (PST) Subject: Re: [PATCH 3/5] mm: make buffered writes work with RWF_UNCACHED To: Dave Chinner Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org References: <20191210162454.8608-1-axboe@kernel.dk> <20191210162454.8608-4-axboe@kernel.dk> <20191211002349.GC19213@dread.disaster.area> From: Jens Axboe Message-ID: Date: Wed, 11 Dec 2019 07:39:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191211002349.GC19213@dread.disaster.area> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 12/10/19 5:23 PM, Dave Chinner wrote: > On Tue, Dec 10, 2019 at 09:24:52AM -0700, Jens Axboe wrote: >> If RWF_UNCACHED is set for io_uring (or pwritev2(2)), we'll drop the >> cache instantiated for buffered writes. If new pages aren't >> instantiated, we leave them alone. This provides similar semantics to >> reads with RWF_UNCACHED set. > > So what about filesystems that don't use generic_perform_write()? > i.e. Anything that uses the iomap infrastructure (i.e. > iomap_file_buffered_write()) instead of generic_file_write_iter()) > will currently ignore RWF_UNCACHED. That's XFS and gfs2 right now, > but there are likely to be more in the near future as more > filesystems are ported to the iomap infrastructure. I'll skip this one as you found it. > I'd also really like to see extensive fsx and fstress testing of > this new IO mode before it is committed - this is going to exercise page > cache coherency across different operations in new and unique > ways. that means we need patches to fstests to detect and use this > functionality when available, and new tests that explicitly exercise > combinations of buffered, mmap, dio and uncached for a range of > different IO size and alignments (e.g. mixing sector sized uncached > IO with page sized buffered/mmap/dio and vice versa). > > We are not going to have a repeat of the copy_file_range() data > corruption fuckups because no testing was done and no test > infrastructure was written before the new API was committed. Oh I totally agree, and there's no push from my end on this. I just think it's a cool feature and could be very useful, but it obviously needs a healthy dose of testing and test cases written. I'll be doing that as well. >> +void write_drop_cached_pages(struct page **pgs, struct address_space *mapping, >> + unsigned *nr) >> +{ >> + loff_t start, end; >> + int i; >> + >> + end = 0; >> + start = LLONG_MAX; >> + for (i = 0; i < *nr; i++) { >> + struct page *page = pgs[i]; >> + loff_t off; >> + >> + off = (loff_t) page_to_index(page) << PAGE_SHIFT; >> + if (off < start) >> + start = off; >> + if (off > end) >> + end = off; >> + get_page(page); >> + } >> + >> + __filemap_fdatawrite_range(mapping, start, end, WB_SYNC_NONE); >> + >> + for (i = 0; i < *nr; i++) { >> + struct page *page = pgs[i]; >> + >> + lock_page(page); >> + if (page->mapping == mapping) { >> + wait_on_page_writeback(page); >> + if (!page_has_private(page) || >> + try_to_release_page(page, 0)) >> + remove_mapping(mapping, page); >> + } >> + unlock_page(page); >> + } >> + *nr = 0; >> +} >> +EXPORT_SYMBOL_GPL(write_drop_cached_pages); >> + >> +#define GPW_PAGE_BATCH 16 > > In terms of performance, file fragmentation and premature filesystem > aging, this is also going to suck *really badly* for filesystems > that use delayed allocation because it is going to force conversion > of delayed allocation extents during the write() call. IOWs, > it adds all the overheads of doing delayed allocation, but it reaps > none of the benefits because it doesn't allow large contiguous > extents to build up in memory before physical allocation occurs. > i.e. there is no "delayed" in this allocation.... > > So it might work fine on a pristine, empty filesystem where it is > easy to find contiguous free space accross multiple allocations, but > it's going to suck after a few months of production usage has > fragmented all the free space into tiny pieces... I totally agree on this one, and I'm not a huge fan of it. But considering your suggestion in the other email, I think we just need to move this up a notch and do it per-write instead. If we can pass back information about the state of the page cache for the range we care about, then there's no reason to do it per-page for the write case. Reads are still best done that way, and we can avoid the LRU overhead by doing it that way. -- Jens Axboe