From patchwork Thu Sep 19 11:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qun-Wei Lin X-Patchwork-Id: 13807649 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 CD5AACE8D7A for ; Thu, 19 Sep 2024 11:30:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6800E6B00A0; Thu, 19 Sep 2024 07:30:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62F716B00A1; Thu, 19 Sep 2024 07:30:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CFFF6B00A2; Thu, 19 Sep 2024 07:30:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 31C4F6B00A0 for ; Thu, 19 Sep 2024 07:30:25 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C65F3160C0A for ; Thu, 19 Sep 2024 11:30:24 +0000 (UTC) X-FDA: 82581269568.16.B7ABA7A Received: from mailgw01.mediatek.com (mailgw01.mediatek.com [216.200.240.184]) by imf26.hostedemail.com (Postfix) with ESMTP id 76172140007 for ; Thu, 19 Sep 2024 11:30:22 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b="H+UYOB/j"; dmarc=pass (policy=quarantine) header.from=mediatek.com; spf=pass (imf26.hostedemail.com: domain of qun-wei.lin@mediatek.com designates 216.200.240.184 as permitted sender) smtp.mailfrom=qun-wei.lin@mediatek.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726745339; a=rsa-sha256; cv=none; b=zjOv4XG8T/BWlQgtVnct7DR57I+lBF/n7mSob2BujcymXzBpyZfgk2mqlWfK5FvXxyS7cg ggWw6waFHh9buGL9bbFxkkggD3LAVjrwcaGf22EkXM6h0ogxyd9ED7DK3TIMzBMGMVgbkl jlW9tB9SPoMMhCW9maCseaBZSoDM/cM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=mediatek.com header.s=dk header.b="H+UYOB/j"; dmarc=pass (policy=quarantine) header.from=mediatek.com; spf=pass (imf26.hostedemail.com: domain of qun-wei.lin@mediatek.com designates 216.200.240.184 as permitted sender) smtp.mailfrom=qun-wei.lin@mediatek.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726745339; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z1SfHddMinVKqBnBm88AjNHZXXoOonLGMKU9hBryUwg=; b=DbdPpkmJMTfUYqo+2CxD5MybM4zKnpbwmOaNUCPSuIzRvLBVHWfCUR2uPh2S33f00vskpI s+lTI/KMI4Z0+FYof45yO4YzmpIW22ha/i/FOysmH+uswEeJlD5lvb+RtjfzJJPUwSU1WN OmEEcZB4lHwF9I1WGRwhPtHZJQGJFGY= X-UUID: 89c65f96767a11efb3adad29d29602c1-20240919 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Z1SfHddMinVKqBnBm88AjNHZXXoOonLGMKU9hBryUwg=; b=H+UYOB/jxS26nMcyuJNX2vQjHqqwM6HxZ5BlhzQRcFpBxpne/WVLeOzAqB170VtJyLlanVhtUyyqOgZHg/xJu5+9PD4F8Zv6VmCpWAAhHXOe/6I5x7uLDIr+HgbSEqQx9SWSgLGe/vQwfex726o+bnECzCrwiUeEFDDQTmPucCk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.41,REQID:491685d5-aba9-4721-8f4d-70a97f01e1d7,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6dc6a47,CLOUDID:e6f03d9e-8e9a-4ac1-b510-390a86b53c0a,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 89c65f96767a11efb3adad29d29602c1-20240919 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1539984087; Thu, 19 Sep 2024 04:30:14 -0700 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 19 Sep 2024 19:30:10 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 19 Sep 2024 19:30:10 +0800 From: Qun-Wei Lin To: Andrew Morton , Matthias Brugger , AngeloGioacchino Del Regno , Ryan Roberts , "Huang, Ying" , David Hildenbrand , Chris Li , "Matthew Wilcox (Oracle)" , Al Viro , Dan Schatzberg , Kairui Song , Barry Song , Jens Axboe CC: , , , , , Casper Li , Chinwen Chang , Andrew Yang , John Hsu , , Qun-Wei Lin Subject: [PATCH 2/2] mm, swap: introduce SWP_READ_SYNCHRONOUS_IO Date: Thu, 19 Sep 2024 19:29:52 +0800 Message-ID: <20240919112952.981-3-qun-wei.lin@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240919112952.981-1-qun-wei.lin@mediatek.com> References: <20240919112952.981-1-qun-wei.lin@mediatek.com> MIME-Version: 1.0 X-MTK: N X-Rspamd-Queue-Id: 76172140007 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ganoyoefp8zb7odx64yuusx9a6ibc9tt X-HE-Tag: 1726745422-233898 X-HE-Meta: U2FsdGVkX1+Kd+AKqlhzDRQcyAOWy2xYAo6m0yHrPz5ff0ZW2fG93KklfF0Zsu2ww0vMfp4L+PB2MKDPBBTSs8d4Xnk0lnkNN42FBgMiXdii8GXGkxJCoaY4DRnAlEzo6ohrl8IUVw9fd6VO6Yr/FC92qxNWFkiMZOrlPUyI0c8brv7UG0sxJmQJW4XHLZe9ryaLpRIPRsh4zmCCIPsQaTV/syv2ZQ9gRy9quLkyymOKJ7IiLZjLvZ6VveAKi8pR0i7HK9Oc/EEXg0bsczTLZqWidh1X9RFPjtcKuE/WbyNWNA6FSPBmMx613NjXs4ICLz33AzNU9GD3VGRE88xoq9aWR0Qw9JK0bgnhmk+YCArd6f5yLfW2PgV9uvxJJlBJ2U9DJdD1J2KKRqQyu2PZBCLmK+R80FVHz7iceJrdzMfwAX/SastqFtBZ6WX3qD3oKtP7B/vtTR3N6vsL/BpTfLTtrzuxbF7be8cqHUG2O/2/5pCjBqAzFvLUa+dVNeSe6a9K0FqQhxXqNy7+7mv5H+Dwn8dbDcPGAwmq7Snb6U/fQBNILnby0m7oCsDfl+9L7vCsKJVFeXECdXO2IarWs76iiNJKccCi7t6TwdDWS5xgx0vHDWcYS5vxHTwfY4CWaG1IgSqfkRjbSbV9PqWula75LVc+mxCKAf4svQgaxFrxtt0dwyBM3wViObjZE6jp8iZVu2xH9GlJ3xUzHoeqf3926lM9T5B6wxTlXu1re1e4KOOunCrr5/vLmipvw2CAXXbjOuAFmEyrYL6WflTAUVhniSLcqRScPqqDCXiu2dwlMKSVSm7RgOAkU4+Ns9iZKmV/x40Rz8T121fu8ZH0wn8G3dn3suJ1qiVcONRzsnGaWCJCT8Nv8ky8mPTuWB9x9t9mmKC8czzjsavNs/mOAGe2WNydwaWXBaKigGSZafnBcApHA6Ldz+JE7pkdiVfOyHukN/ku98P+RjbVQ65 YWrMH+nP zHytAiWpHpbqHlO0SA1jLf/WN/FCOJtQAFyXI6sRjLS9j+MjJHg3jQH9Z0CMgeFDg5oRF1Ecrpszi68tSUdr1S0aHDikXXejX4Djr2fiWrO7CuXe4uvFIs+uetXYMSq/9LO4Csr3okEI1zIRwS7QcoJ0O0ePOhwno5asy16HmK/1UY2lS6TCOKlTVsIFnFPTIgQkuF8JUAL5IjvRslYyBRry48e1f4ThCwZKFCWkZyWDQpEXwLr4dhLZyG1S2f+nKQadYFfXKFJdwQbQ3gDGXgrMkzw== 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: The existing SWP_SYNCHRONOUS_IO flag is not enough for certain swap devices that support synchronous read operations but asynchronous write operations, so we need to introduce a new flag SWP_READ_SYNCHRONOUS_IO. Signed-off-by: Qun-Wei Lin --- include/linux/swap.h | 31 ++++++++++++++++--------------- mm/memory.c | 3 ++- mm/page_io.c | 2 +- mm/swapfile.c | 3 +++ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index ba7ea95d1c57..f595050f431b 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -205,21 +205,22 @@ struct swap_extent { offsetof(union swap_header, info.badpages)) / sizeof(int)) enum { - SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ - SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ - SWP_DISCARDABLE = (1 << 2), /* blkdev support discard */ - SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */ - SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */ - SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */ - SWP_BLKDEV = (1 << 6), /* its a block device */ - SWP_ACTIVATED = (1 << 7), /* set after swap_activate success */ - SWP_FS_OPS = (1 << 8), /* swapfile operations go through fs */ - SWP_AREA_DISCARD = (1 << 9), /* single-time swap area discards */ - SWP_PAGE_DISCARD = (1 << 10), /* freed swap page-cluster discards */ - SWP_STABLE_WRITES = (1 << 11), /* no overwrite PG_writeback pages */ - SWP_SYNCHRONOUS_IO = (1 << 12), /* synchronous IO is efficient */ - /* add others here before... */ - SWP_SCANNING = (1 << 14), /* refcount in scan_swap_map */ + SWP_USED = (1 << 0), /* is slot in swap_info[] used? */ + SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */ + SWP_DISCARDABLE = (1 << 2), /* blkdev support discard */ + SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */ + SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */ + SWP_CONTINUED = (1 << 5), /* swap_map has count continuation */ + SWP_BLKDEV = (1 << 6), /* its a block device */ + SWP_ACTIVATED = (1 << 7), /* set after swap_activate success */ + SWP_FS_OPS = (1 << 8), /* swapfile operations go through fs */ + SWP_AREA_DISCARD = (1 << 9), /* single-time swap area discards */ + SWP_PAGE_DISCARD = (1 << 10), /* freed swap page-cluster discards */ + SWP_STABLE_WRITES = (1 << 11), /* no overwrite PG_writeback pages */ + SWP_SYNCHRONOUS_IO = (1 << 12), /* synchronous IO is efficient */ + SWP_READ_SYNCHRONOUS_IO = (1 << 13), /* synchronous IO is efficient */ + /* add others here before... */ + SWP_SCANNING = (1 << 14), /* refcount in scan_swap_map */ }; #define SWAP_CLUSTER_MAX 32UL diff --git a/mm/memory.c b/mm/memory.c index ebfc9768f801..f531a6bfea5b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4089,7 +4089,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) swapcache = folio; if (!folio) { - if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && + if ((data_race(si->flags & (SWP_SYNCHRONOUS_IO | + SWP_READ_SYNCHRONOUS_IO))) && __swap_count(entry) == 1) { /* * Prevent parallel swapin from proceeding with diff --git a/mm/page_io.c b/mm/page_io.c index ff8c99ee3af7..98a00709e98c 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -499,7 +499,7 @@ static void swap_read_folio_bdev_async(struct folio *folio, void swap_read_folio(struct folio *folio, struct swap_iocb **plug) { struct swap_info_struct *sis = swp_swap_info(folio->swap); - bool synchronous = sis->flags & SWP_SYNCHRONOUS_IO; + bool synchronous = sis->flags & (SWP_SYNCHRONOUS_IO | SWP_READ_SYNCHRONOUS_IO); bool workingset = folio_test_workingset(folio); unsigned long pflags; bool in_thrashing; diff --git a/mm/swapfile.c b/mm/swapfile.c index 38bdc439651a..7b8feb235aab 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3177,6 +3177,9 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (p->bdev && bdev_synchronous(p->bdev)) p->flags |= SWP_SYNCHRONOUS_IO; + if (p->bdev && bdev_read_synchronous(p->bdev)) + p->flags |= SWP_READ_SYNCHRONOUS_IO; + if (p->bdev && bdev_nonrot(p->bdev)) { int cpu, i; unsigned long ci, nr_cluster;