From patchwork Wed Jan 25 13:34:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13115636 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 766FDC54E94 for ; Wed, 25 Jan 2023 13:34:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37FBF6B0078; Wed, 25 Jan 2023 08:34:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 30C2B6B007D; Wed, 25 Jan 2023 08:34:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECC196B0078; Wed, 25 Jan 2023 08:34:57 -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 C40A46B0073 for ; Wed, 25 Jan 2023 08:34:57 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8DF991201D8 for ; Wed, 25 Jan 2023 13:34:57 +0000 (UTC) X-FDA: 80393417034.09.7E2FAE1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf22.hostedemail.com (Postfix) with ESMTP id DD7E5C0004 for ; Wed, 25 Jan 2023 13:34:55 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d2zsfJpD; spf=none (imf22.hostedemail.com: domain of BATV+926f35216cf1e93e6ac9+7094+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+926f35216cf1e93e6ac9+7094+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674653695; 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=ROS65tCompeGK2agNW/ZuvBq/QEcxYeTNpBB9DoF018=; b=w8E1K0caVOb4gcsMjCjawaplw3gJQ9Hf7+UZ8aPhx4Na+r72UY8g0iJbfDHwgryp6bGfTb JEpBcW07SeUozcp+2tUMEbmkj1/qhwJwYmZ40fKIY68yKtKFjeEgyMVqCqrcG2JM7dEaxQ uc97dWPbwgq6EIw20Z8KyQdLyaCG8g8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=d2zsfJpD; spf=none (imf22.hostedemail.com: domain of BATV+926f35216cf1e93e6ac9+7094+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+926f35216cf1e93e6ac9+7094+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674653695; a=rsa-sha256; cv=none; b=DAehqyQJpyuSmc+xpoph4s87MaefrqvNOiz4Yzmt8SOQwZu0Os/iuyHmI40OrsCXHZIFTe phqFnGP4DKk5txEZGsd12d/GKClD+Y+Hw7QZjpMWj/emNO/SqtEP1APdff9EXu6JnewEJ9 TRuYuF4KCsc8ux/KFflf+hHjiMmFO4s= 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=ROS65tCompeGK2agNW/ZuvBq/QEcxYeTNpBB9DoF018=; b=d2zsfJpDRFFrzt10Ijye3rXQc2 Gjn+l3XF0voJlrGvZJbRaoDc0JsfwL53ZGXWNBzJ6miUPcn0kp8xAKeRout6JP7hGUgUeBnU8SnCL ZwXxcM7tOQPx16uvKwZ1a7QYhmAyFXfhWMcHRZLzuQtiHmQQ2dJ1SFoxLWl1VG9hqGtiqbKNwbZ13 az/1JlLHspaGSvs/82k74pRav2m9Z0bMZHevtFB7Ke82yYJE5KNarfHvapG+FrtjCXWOQUJII3U+0 mhXAdCeOuBAczTry7ksQCAQEQQBQKsezhy8QB3hprWYOCwBFc+wH4SeUtfu/DXDkl/f2QTnVwuwAK psNJQ/uQ==; Received: from [2001:4bb8:19a:27af:c78f:9b0d:b95c:d248] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKfvO-007P2P-RA; Wed, 25 Jan 2023 13:34:51 +0000 From: Christoph Hellwig To: Jens Axboe , Minchan Kim , Sergey Senozhatsky , Dan Williams , Vishal Verma , Dave Jiang , Ira Weiny Cc: Andrew Morton , linux-block@vger.kernel.org, nvdimm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/7] mm: factor out a swap_readpage_bdev helper Date: Wed, 25 Jan 2023 14:34:32 +0100 Message-Id: <20230125133436.447864-4-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230125133436.447864-1-hch@lst.de> References: <20230125133436.447864-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 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DD7E5C0004 X-Rspam-User: X-Stat-Signature: kr8fjgcgdb5cktd3ad9857fsarrugqsf X-HE-Tag: 1674653695-785563 X-HE-Meta: U2FsdGVkX1+CjMtQjhWW64TtUat1ZkBEABPmi0I4cH6dA6nczHV1qjgCRFiX0gvV7FLUZB6UIully6PbO92gQVwSXHhGNeyLiqA3koS+3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zKT3LMAfN2EzhAbYBEzfNuYGsOhfwlhWDe6Vd/9QVx0D9lgqF26No7YpuiS0HfQe/SuylG/1XrDn4ywVXnUGQLFEfMYamCWMuumtnIQMLWqSoGLjPoHzxBe+5Z6YFzQQqkuzxRMIABHfeJYQbfHzHNJVPj8lFoFuXd/GXSLIzKzUt6fsgU4i2jhdtK14T+TOr73PJeMrxVcfzyn8c3Csp37kU/nCKqx/88juwO2M5wWBoAM6VS1DRxbA4Qz74DD7Pmd3KsakQ16un9HVicU4P+7ymEC/jZRGzPN+n1R 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: Split the block device case from swap_readpage into a separate helper, following the abstraction for file based swap and frontswap. Signed-off-by: Christoph Hellwig Reviewed-by: Dan Williams --- mm/page_io.c | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 6f7166fdc4b2bb..ce0b3638094f85 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -445,44 +445,15 @@ static void swap_readpage_fs(struct page *page, *plug = sio; } -void swap_readpage(struct page *page, bool synchronous, struct swap_iocb **plug) +static void swap_readpage_bdev(struct page *page, bool synchronous, + struct swap_info_struct *sis) { struct bio *bio; - struct swap_info_struct *sis = page_swap_info(page); - bool workingset = PageWorkingset(page); - unsigned long pflags; - bool in_thrashing; - - VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page); - VM_BUG_ON_PAGE(!PageLocked(page), page); - VM_BUG_ON_PAGE(PageUptodate(page), page); - - /* - * Count submission time as memory stall and delay. When the device - * is congested, or the submitting cgroup IO-throttled, submission - * can be a significant part of overall IO time. - */ - if (workingset) { - delayacct_thrashing_start(&in_thrashing); - psi_memstall_enter(&pflags); - } - delayacct_swapin_start(); - - if (frontswap_load(page) == 0) { - SetPageUptodate(page); - unlock_page(page); - goto out; - } - - if (data_race(sis->flags & SWP_FS_OPS)) { - swap_readpage_fs(page, plug); - goto out; - } if ((sis->flags & SWP_SYNCHRONOUS_IO) && !bdev_read_page(sis->bdev, swap_page_sector(page), page)) { count_vm_event(PSWPIN); - goto out; + return; } bio = bio_alloc(sis->bdev, 1, REQ_OP_READ, GFP_KERNEL); @@ -509,8 +480,39 @@ void swap_readpage(struct page *page, bool synchronous, struct swap_iocb **plug) } __set_current_state(TASK_RUNNING); bio_put(bio); +} + +void swap_readpage(struct page *page, bool synchronous, struct swap_iocb **plug) +{ + struct swap_info_struct *sis = page_swap_info(page); + bool workingset = PageWorkingset(page); + unsigned long pflags; + bool in_thrashing; + + VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page); + VM_BUG_ON_PAGE(!PageLocked(page), page); + VM_BUG_ON_PAGE(PageUptodate(page), page); + + /* + * Count submission time as memory stall and delay. When the device + * is congested, or the submitting cgroup IO-throttled, submission + * can be a significant part of overall IO time. + */ + if (workingset) { + delayacct_thrashing_start(&in_thrashing); + psi_memstall_enter(&pflags); + } + delayacct_swapin_start(); + + if (frontswap_load(page) == 0) { + SetPageUptodate(page); + unlock_page(page); + } else if (data_race(sis->flags & SWP_FS_OPS)) { + swap_readpage_fs(page, plug); + } else { + swap_readpage_bdev(page, synchronous, sis); + } -out: if (workingset) { delayacct_thrashing_end(&in_thrashing); psi_memstall_leave(&pflags);