From patchwork Thu Sep 15 09:41:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12977124 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 1E451ECAAD3 for ; Thu, 15 Sep 2022 09:42:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E9666B0074; Thu, 15 Sep 2022 05:42:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 471896B0075; Thu, 15 Sep 2022 05:42:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 277D48D0001; Thu, 15 Sep 2022 05:42:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 028726B0075 for ; Thu, 15 Sep 2022 05:42:22 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D0FA6404DA for ; Thu, 15 Sep 2022 09:42:21 +0000 (UTC) X-FDA: 79913829282.07.0BB5DD0 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 88EA51400CE for ; Thu, 15 Sep 2022 09:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Sn1STluEcmAEl2IDkRqQTtdfy5beUs4WRE2QQKAsD/8=; b=os6+qAq+Yh06rcP0f4OouU/22o oWMxav2lmp8ydZQlV6kYJHiVg8ZVYPX5Z5bUp7SoaxqFj/nUS4D885nff+ExvyS+/ZeTUGV4jsgEU ER77a8FARvGVxYQc08pU28vamvOLA93UJlOYB+wMD6hJYfaFlwU7gVGEBvA4QBbVOudz8qGi3zl6j PD4HWCk7kfMEuJEharZdxwNNq3YjLexhD9ZuJU9XTK/fP5VUj1cnMn1ePeBY44Kxrp22zlpCAneVa pYT72nSZOveSvkojw81g64FzZrU9pT28Z+dU81UCAkWPRoOJZqNkQwmhvF/DotA52n+uG+9hsXvG2 598sGqsQ==; Received: from [185.122.133.20] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oYlNq-005b3C-78; Thu, 15 Sep 2022 09:42:10 +0000 From: Christoph Hellwig To: Jens Axboe , Matthew Wilcox , Johannes Weiner , Suren Baghdasaryan , Andrew Morton Cc: Chris Mason , Josef Bacik , David Sterba , Gao Xiang , Chao Yu , linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-mm@kvack.org Subject: [PATCH 3/5] btrfs: add manual PSI accounting for compressed reads Date: Thu, 15 Sep 2022 10:41:58 +0100 Message-Id: <20220915094200.139713-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220915094200.139713-1-hch@lst.de> References: <20220915094200.139713-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663234941; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Sn1STluEcmAEl2IDkRqQTtdfy5beUs4WRE2QQKAsD/8=; b=jLYAFpWyXISkfBPIXeIpRZQ2IZ1VnOx40LAUDozJTBEb9jO1nWrJF1OzQaiNXDOLZktOp8 TYf/W1rz4pifVNK8CxRsY6ITvdSNKEP017peQ3642SdZjE5HGu0XG5p2erlYQ2+Zj3+6Nt R/Sr3pV94otLxCRNzoho2WHSXv3GDBY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=os6+qAq+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+aa90abf7a61f323a8d2f+6962+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aa90abf7a61f323a8d2f+6962+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663234941; a=rsa-sha256; cv=none; b=EYVRoYtfrgxBG10s1TBUwMWXgiTQTd0RfdemIoVVRRkKtM7jcySgc4U5KxMK5xobvsWMtV etJYIH8Z4wjAerXvFtf2hvcfkhpWUmEETAR0E3G2fFq1F2D28TIBMDIbeg9k+z9s1cKhYk SCqkIv1vdHmhWMYeyZGUnqsZaG3a6iQ= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 88EA51400CE X-Rspam-User: X-Stat-Signature: gnhokmf9u7kxpg5rqfm8e6xqbycxmmm3 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=os6+qAq+; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+aa90abf7a61f323a8d2f+6962+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+aa90abf7a61f323a8d2f+6962+infradead.org+hch@bombadil.srs.infradead.org X-HE-Tag: 1663234941-784155 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: btrfs compressed reads try to always read the entire compressed chunk, even if only a subset is requested. Currently this is covered by the magic PSI accounting underneath submit_bio, but that is about to go away. Instead add manual psi_memstall_{enter,leave} annotations. Note that for readahead this really should be using readahead_expand, but the additionals reads are also done for plain ->read_folio where readahead_expand can't work, so this overall logic is left as-is for now. Signed-off-by: Christoph Hellwig Acked-by: David Sterba Acked-by: Johannes Weiner Reported-by: Thorsten Leemhuis Signed-off-by: Johannes Weiner Tested-by: Thorsten Leemhuis Reported-by: Thorsten Leemhuis Signed-off-by: Johannes Weiner Tested-by: Thorsten Leemhuis --- fs/btrfs/compression.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index e84d22c5c6a83..370788b9b1249 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -519,7 +520,8 @@ static u64 bio_end_offset(struct bio *bio) */ static noinline int add_ra_bio_pages(struct inode *inode, u64 compressed_end, - struct compressed_bio *cb) + struct compressed_bio *cb, + unsigned long *pflags) { struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); unsigned long end_index; @@ -588,6 +590,9 @@ static noinline int add_ra_bio_pages(struct inode *inode, continue; } + if (PageWorkingset(page)) + psi_memstall_enter(pflags); + ret = set_page_extent_mapped(page); if (ret < 0) { unlock_page(page); @@ -674,6 +679,8 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, u64 em_len; u64 em_start; struct extent_map *em; + /* Initialize to 1 to make skip psi_memstall_leave unless needed */ + unsigned long pflags = 1; blk_status_t ret; int ret2; int i; @@ -729,7 +736,7 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, goto fail; } - add_ra_bio_pages(inode, em_start + em_len, cb); + add_ra_bio_pages(inode, em_start + em_len, cb, &pflags); /* include any pages we added in add_ra-bio_pages */ cb->len = bio->bi_iter.bi_size; @@ -810,6 +817,9 @@ void btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, } } + if (!pflags) + psi_memstall_leave(&pflags); + if (refcount_dec_and_test(&cb->pending_ios)) finish_compressed_bio_read(cb); return;