From patchwork Sat Sep 10 06:50:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12972430 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 F222EC6FA82 for ; Sat, 10 Sep 2022 06:51:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FAAD6B0074; Sat, 10 Sep 2022 02:51:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0AC7E6B0075; Sat, 10 Sep 2022 02:51:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E19AA8D0001; Sat, 10 Sep 2022 02:51:24 -0400 (EDT) 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 C65DE6B0074 for ; Sat, 10 Sep 2022 02:51:24 -0400 (EDT) Received: from smtpin31.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9607B1407AA for ; Sat, 10 Sep 2022 06:51:24 +0000 (UTC) X-FDA: 79895254488.31.FB95A0A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 482AF800AA for ; Sat, 10 Sep 2022 06:51:24 +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=FkPl9IvUjfBsIN7AIjdm08mTjlqewl1g1KHKU4sEYn8=; b=RMyNmneg26qCu35hD5+W/DxVr4 iVPficcPRLAokYM8ZwsoBLv8dW8VnZmJoK+GDv3k99nhtWxs6z+2MP6KXvBvQGDZX3E3IOlhYWYih 1wSKkmK6byR4m9gCQAvdCO4LFG0XyTL/Wg4/XQ/NxIibvPoIxqr+YNihM/P/pvyv3RLQssprSncca iEiwC1YXUzHQ2sBq+jikNtoTM9Asnl3xpUT3rE6pcjSKj787bsdsV1ETRfYPz/KIjQc2g5iacXJE3 +wyvgt21XtR4GFAfm29jnH92HvRDkK2397b1S1gSfn/wfDIHA8M7HhR6zgyZJzSMSIqFggodqjXIG lsWWrGew==; Received: from [2001:4bb8:198:38af:e8dc:dbbd:a9d:5c54] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWuKg-006paD-79; Sat, 10 Sep 2022 06:51:14 +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: Sat, 10 Sep 2022 08:50:56 +0200 Message-Id: <20220910065058.3303831-4-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220910065058.3303831-1-hch@lst.de> References: <20220910065058.3303831-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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662792684; a=rsa-sha256; cv=none; b=74dkKQB80RrkePAhDn6hs4aSk+qUe9Xn3Lnyk1pGcKm7pSGinHGxE9rRJFldNrBciXkPNt XzGDjFNMsYegV87MhEninebE/VhRIRna5CVbrDvlvYjyg5Kf54IV6evpQnS5kw7e0MSPod 7MrOY85AvUD5FBeoHdi0z920yNoWbsY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RMyNmneg; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+74593d5eb0e0b46c37a4+6957+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+74593d5eb0e0b46c37a4+6957+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662792684; 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=FkPl9IvUjfBsIN7AIjdm08mTjlqewl1g1KHKU4sEYn8=; b=52NNPBNx7JyYoBphJXkO/wmINUpNsEovsrtXRO9z/0MbgpTH3FcwAI3Ppc3b8c01smO3p7 0R3c+O8qYJXoRuCOs/53v6w/n5vdPSNw+jr18A7emloODUns7XucBRrIEv/33PoNwrDsQZ u5TPmZrTk6adPtkNZ8J45kjtDrAS5Qc= Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=RMyNmneg; dmarc=none; spf=none (imf30.hostedemail.com: domain of BATV+74593d5eb0e0b46c37a4+6957+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+74593d5eb0e0b46c37a4+6957+infradead.org+hch@bombadil.srs.infradead.org X-Rspam-User: X-Rspamd-Queue-Id: 482AF800AA X-Rspamd-Server: rspam11 X-Stat-Signature: u734j784ti9cc7jfcb1puamrz3q1im8d X-HE-Tag: 1662792684-819278 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 --- 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..f7889a00e0055 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 (unlikely(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;