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 7B116D43FEE for ; Mon, 18 Nov 2024 08:42:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD0E08D0018; Mon, 18 Nov 2024 03:42:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D7FF08D000D; Mon, 18 Nov 2024 03:42:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFA748D0018; Mon, 18 Nov 2024 03:42:34 -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 9DD6D8D000D for ; Mon, 18 Nov 2024 03:42:34 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 575301A0109 for ; Mon, 18 Nov 2024 08:42:34 +0000 (UTC) X-FDA: 82798573200.22.D80176E Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf01.hostedemail.com (Postfix) with ESMTP id B497C4000A for ; Mon, 18 Nov 2024 08:41:52 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of libaokun1@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=libaokun1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731919262; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hETLAIy3Nr+Z65Gcpt1TtrcrGGFuHl97sEutUYi0fY4=; b=EZTIO6ohk4xg+uGJ7tiBomGl2WBb+1CHjs908wAHGNyZNapF8fH8qPxnHnQi2p4Bv75kfW jMzdY0iNJS6nQ2eCqnUb/4RbPKUktEGFtlgW8+dOf0AgobgYakYJ8S/fmIhqfi9ZllPO78 inInkKBe+fW7LaFt/+GsUB1B90wQdD4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of libaokun1@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=libaokun1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731919262; a=rsa-sha256; cv=none; b=ZUyppxo3grG4zbvioPFm4sYSgMFOuIT0Cdd7LYeFvf7Ikm5TegqKEHF/zPVyjOKtwni62i S9pCDcJf1fzRc8x8CfzGk+syfcqVbRLi4EKsTIUiMontsrzUYI+jfM2+O6kxGVn+NopN6r gf0J+BIDuJZpQj83MJL8V8ufLDgZpMw= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4XsLg00LDrz1T4sT; Mon, 18 Nov 2024 16:40:28 +0800 (CST) Received: from kwepemg500008.china.huawei.com (unknown [7.202.181.45]) by mail.maildlp.com (Postfix) with ESMTPS id E1E54140138; Mon, 18 Nov 2024 16:42:24 +0800 (CST) Received: from [127.0.0.1] (10.174.177.71) by kwepemg500008.china.huawei.com (7.202.181.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 18 Nov 2024 16:42:23 +0800 Message-ID: <01fadf73-6b0f-44ff-9325-515fae37d968@huawei.com> Date: Mon, 18 Nov 2024 16:42:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 10/17] mm/filemap: make buffered writes work with RWF_UNCACHED To: Jens Axboe CC: , , , , , , , , , , , Yang Erkun References: <20241114152743.2381672-2-axboe@kernel.dk> <20241114152743.2381672-12-axboe@kernel.dk> Content-Language: en-US From: Baokun Li In-Reply-To: <20241114152743.2381672-12-axboe@kernel.dk> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.71] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemg500008.china.huawei.com (7.202.181.45) X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B497C4000A X-Stat-Signature: 4dhxbuk5awfwaezg3s4mug4n17xknt89 X-HE-Tag: 1731919312-373727 X-HE-Meta: U2FsdGVkX1/EjbotiEZzXEJlhlW8xYUf+4k6IbvkXV3ekwa4CPhhHluYDguLnfmC4N4e+HYrfEc8QLWW4HyBOz4Ou7ZPMLGkTqrZFeOsu9iX10wJLC5HYWqLL+UVvfCPsr80raXloYNdPuzUi/uESrbrNKLf/uZ0Ir4O2skoIVcdBr5HHSpyj7Ut31pOEEbRHx1ia2lpTQNdy0dkcsF3HP3+euNundWktNt9r6iYn1/X51oDOxeQcMmz9EpCgZUru9Bl+HjfGTaBZ3taN/mgVUi0iwwlb083iONHS0BiouhPAM6RQNM7aU05Dn8K9lo0RvTOfBqS3m615Uwgf79am9YWwc6gFzw60xI9MBvunQeZe1edZO20I4YBkyIwZujlEIISdzePxHFLmOShoQ6yVyaA6x7o20ZQ5yp40sR3BjbbTUnKGVAtI8ka2CKgVBtwE/3lGRc43e7blKlRlLl2BmyDhigIUAHX7b0lVDuzHlb9sA1FEiMmbUTWOs/qCmiDnjFsLiQfI1L8v5lWQE0fac/DAqbqj0o1Ut9eUqJ/+VHd/e/hO8E0prqLSToad3a8b3TUaI2boSJzgVbUuK4Ty2p+RplZokZBfqgve7ogU5T06NYd8SWT5pDmfaZlQMDf9EDB6GwXZe7AksGJylCXMTP+lBNzK/RBMUyLDGeycwlSTVXAOeT6nFQqw3mp7TvLWsVc1fyc/FVGj/jMo7WFzoZnqJS+1mZJbno/NCAXCPuBAD85xlKkT+dQquHBrbpT6R55I83ezH2yFHebKRomVjJrRNN4q1YwsGhkwhddNYWp+vGEWqN0pFWlm1jydx4YlbcRPFJSGvxKK0IFgir3ye/mZpZYkUkiChx2HChwm6hkIA6FTRYDEUMksNF0UsJwmYUQ3EGxdYpETQU+U/is2IjIlbZe4VrbHPk0I2E9vjLXHx2+V15bERg1hZU1NYYK3Zxl2tJAH+YZgOhG2lz ZzDyBIrt vCvqzinlo+xFWL2TCNTJ8ITPevyQTSxKjiP4yRCye0G0AsywhHvJt/eFOzDDaJz2V0sftdanQET4NKeWR6cOj0lG8OmJpClqnsKtcqULmBIGeTiB4ZOWcB487xHs+khFQcuf7sUuz+Z7jgOMuLnd9UdF/vyuXE7oaw8t3/VtLFKxZHiE0UtW+D2crIhDzUqEMVijzhb3W/EvsSbg4M3wbnhv7Cg== 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 2024/11/14 23:25, Jens Axboe wrote: > If RWF_UNCACHED is set for a write, mark new folios being written with > uncached. This is done by passing in the fact that it's an uncached write > through the folio pointer. We can only get there when IOCB_UNCACHED was > allowed, which can only happen if the file system opts in. Opting in means > they need to check for the LSB in the folio pointer to know if it's an > uncached write or not. If it is, then FGP_UNCACHED should be used if > creating new folios is necessary. > > Uncached writes will drop any folios they create upon writeback > completion, but leave folios that may exist in that range alone. Since > ->write_begin() doesn't currently take any flags, and to avoid needing > to change the callback kernel wide, use the foliop being passed in to > ->write_begin() to signal if this is an uncached write or not. File > systems can then use that to mark newly created folios as uncached. > > This provides similar benefits to using RWF_UNCACHED with reads. Testing > buffered writes on 32 files: > > writing bs 65536, uncached 0 > 1s: 196035MB/sec > 2s: 132308MB/sec > 3s: 132438MB/sec > 4s: 116528MB/sec > 5s: 103898MB/sec > 6s: 108893MB/sec > 7s: 99678MB/sec > 8s: 106545MB/sec > 9s: 106826MB/sec > 10s: 101544MB/sec > 11s: 111044MB/sec > 12s: 124257MB/sec > 13s: 116031MB/sec > 14s: 114540MB/sec > 15s: 115011MB/sec > 16s: 115260MB/sec > 17s: 116068MB/sec > 18s: 116096MB/sec > > where it's quite obvious where the page cache filled, and performance > dropped from to about half of where it started, settling in at around > 115GB/sec. Meanwhile, 32 kswapds were running full steam trying to > reclaim pages. > > Running the same test with uncached buffered writes: > > writing bs 65536, uncached 1 > 1s: 198974MB/sec > 2s: 189618MB/sec > 3s: 193601MB/sec > 4s: 188582MB/sec > 5s: 193487MB/sec > 6s: 188341MB/sec > 7s: 194325MB/sec > 8s: 188114MB/sec > 9s: 192740MB/sec > 10s: 189206MB/sec > 11s: 193442MB/sec > 12s: 189659MB/sec > 13s: 191732MB/sec > 14s: 190701MB/sec > 15s: 191789MB/sec > 16s: 191259MB/sec > 17s: 190613MB/sec > 18s: 191951MB/sec > > and the behavior is fully predictable, performing the same throughout > even after the page cache would otherwise have fully filled with dirty > data. It's also about 65% faster, and using half the CPU of the system > compared to the normal buffered write. > > Signed-off-by: Jens Axboe > --- > include/linux/fs.h | 5 +++++ > include/linux/pagemap.h | 9 +++++++++ > mm/filemap.c | 12 +++++++++++- > 3 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 45510d0b8de0..122ae821989f 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2877,6 +2877,11 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count) > (iocb->ki_flags & IOCB_SYNC) ? 0 : 1); > if (ret) > return ret; > + } else if (iocb->ki_flags & IOCB_UNCACHED) { > + struct address_space *mapping = iocb->ki_filp->f_mapping; > + > + filemap_fdatawrite_range_kick(mapping, iocb->ki_pos, > + iocb->ki_pos + count); > } > Hi Jens, The filemap_fdatawrite_range_kick() helper function is not added until the next patch, so you should swap the order of patch 10 and patch 11. Regards, Baokun > return count; > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index d55bf995bd9e..cc02518d338d 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -14,6 +14,7 @@ > #include > #include > #include /* for in_interrupt() */ > +#include > #include > > struct folio_batch; > @@ -70,6 +71,14 @@ static inline int filemap_write_and_wait(struct address_space *mapping) > return filemap_write_and_wait_range(mapping, 0, LLONG_MAX); > } > > +/* > + * Value passed in to ->write_begin() if IOCB_UNCACHED is set for the write, > + * and the ->write_begin() handler on a file system supporting FOP_UNCACHED > + * must check for this and pass FGP_UNCACHED for folio creation. > + */ > +#define foliop_uncached ((struct folio *) 0xfee1c001) > +#define foliop_is_uncached(foliop) (*(foliop) == foliop_uncached) > + > /** > * filemap_set_wb_err - set a writeback error on an address_space > * @mapping: mapping in which to set writeback error > diff --git a/mm/filemap.c b/mm/filemap.c > index 13815194ed8a..297cb53332ff 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -4076,7 +4076,7 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) > ssize_t written = 0; > > do { > - struct folio *folio; > + struct folio *folio = NULL; > size_t offset; /* Offset into folio */ > size_t bytes; /* Bytes to write to folio */ > size_t copied; /* Bytes copied from user */ > @@ -4104,6 +4104,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) > break; > } > > + /* > + * If IOCB_UNCACHED is set here, we now the file system > + * supports it. And hence it'll know to check folip for being > + * set to this magic value. If so, it's an uncached write. > + * Whenever ->write_begin() changes prototypes again, this > + * can go away and just pass iocb or iocb flags. > + */ > + if (iocb->ki_flags & IOCB_UNCACHED) > + folio = foliop_uncached; > + > status = a_ops->write_begin(file, mapping, pos, bytes, > &folio, &fsdata); > if (unlikely(status < 0))