From patchwork Sun Nov 19 19:47:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13460664 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 58B41C54FB9 for ; Sun, 19 Nov 2023 19:48:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE3C76B0380; Sun, 19 Nov 2023 14:48:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6A806B038A; Sun, 19 Nov 2023 14:48:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE5096B038E; Sun, 19 Nov 2023 14:48:31 -0500 (EST) 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 A82B46B0380 for ; Sun, 19 Nov 2023 14:48:31 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 72CB38052C for ; Sun, 19 Nov 2023 19:48:31 +0000 (UTC) X-FDA: 81475740822.26.3B7050F Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf01.hostedemail.com (Postfix) with ESMTP id 9E15A40004 for ; Sun, 19 Nov 2023 19:48:29 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TQvnhzoo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700423309; h=from:from:sender:reply-to: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=/Iv3a0RkKO4tJSHfzH299Wh8nqjqW5sZox/cVI//TM8=; b=TpPTJHKDwN3DW42sIuTwyvW6MFhrTlawuUlyudaf1ZMzPpmVRayCL8dQKhKtI2D0cEg2Of RAO2FgtLZVQGCR60pxkOm7eBriQW3mKHElTR0ujHPHXh4ug1zvg64jPMekZz0nJObkRCpk Nr50WRTo1FWcj9+qr67HrkKtuSmvuWg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TQvnhzoo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700423309; a=rsa-sha256; cv=none; b=Y6eYYgiXvbs12gfni2n2N3PwQpwD5SF9pbXNGpY+BtbnP4tIUyttDHrWsyYlwkKxgGn3i2 aNFQ5fDMuhpYstP9n0q9undQH5kpKYV1nCNaonLm2e9R56fPnqLGY+YANDEDxQiE4XvDXp rk1AJnSTR3BRCGIz8/a57sSMfmRN9SQ= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6be1bc5aa1cso3858625b3a.3 for ; Sun, 19 Nov 2023 11:48:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423308; x=1701028108; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=/Iv3a0RkKO4tJSHfzH299Wh8nqjqW5sZox/cVI//TM8=; b=TQvnhzooU4ppGZmsrjtJS0ZqYRsY7GBpX+4VgrIqMscO6be9NsibhvchSnMKesDNkK HhnoXwUW08u+rtVSiyNsRYnxDxTdaV+xMhdhR/zxodGe1l5tRJeg4g1TDOLHSAXyb5hW BZ9Q3lbzwF8ZCUZuJS5d3laaW/nizDbQDHi986p2s84XEJ6bY2mE5JXS8OtMSf2NhAPb oxOVjUZPSbchWV1D07gxJKv2rw/oHsM+6U89zfr1Epc8oDLdnHMRQks/cfTlFH+4wm5g JOkS7I7b+XSzo/Z09UtNTC2vKeK9C9dpf0nPZLBWrJ6S2n2Xeki/G1EPb3x3uElkstK5 a6QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423308; x=1701028108; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=/Iv3a0RkKO4tJSHfzH299Wh8nqjqW5sZox/cVI//TM8=; b=UqZz0csrAaWioAPPlZYM8MhqFOOncnghG+CDRWAcWREjbpn+Jm+TvFveLTwCqFVQ9T B7TgVDusPZ7rlncQErnX/DuyC1Z2tZ1qE54t2fRJx4q1muTDNMPF+9OFrm5DQGmakfzE mT2klvH8olhuJdG49FxYZ6FoSkwWu9lIcIj/FFXb674iMnNhRlB92TReEfgGgXgpMR5V NQcgbNiZUElkp5QmtGOBJ/WXcIYccOjY4Lpcd9zo1Xp7BYN4r0D/7ZW8xkzCBvTkCnNa Ara3+UwTYHy29kdQoYz+qEpG5QjNjxJ44Qjfv50uEBLjrlIg2UsjkpvXbWVAm7leTJoG zYRA== X-Gm-Message-State: AOJu0YweS2H0HX7ZFCJtU90SP+IweS0uq8RG0O8/QiZ+trpmI3+0F2/r ldZUfzvjLJgL8HA+2/ow5ADbRCOgHwyPw57V X-Google-Smtp-Source: AGHT+IHOC/pH4egukb5+EX3DwlCGnZ4HWVCMhNwTp5WbUoyceBak2FygNQZocPIPIHn77Rx48Jh+bw== X-Received: by 2002:a05:6a20:3d84:b0:17b:426f:829 with SMTP id s4-20020a056a203d8400b0017b426f0829mr7488318pzi.37.1700423307883; Sun, 19 Nov 2023 11:48:27 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.48.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:27 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , "Huang, Ying" , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH 08/24] mm/swap: check readahead policy per entry Date: Mon, 20 Nov 2023 03:47:24 +0800 Message-ID: <20231119194740.94101-9-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: p3i5rrfh9yx8e1547g1w5i6tdi5jdn1b X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9E15A40004 X-HE-Tag: 1700423309-723619 X-HE-Meta: U2FsdGVkX194b9xf2vq/Pfwtdl48OFCgdrzkokkkSscS6ykOo3EVJzTWxcjuYkqeaxotm6ee09f0X1JTGwqqUfWKKNXyoC4+qWHoks9dkIBx40KQ+YLgtr/bh1b8VKu0JrvceosbrVlE7ZVpNLtlwhzw1s36XsThffUAEMZiGoIzrT7WHpqQE6gOxuvaUYnmLjjlOiQ6xzVB+xZRERwnGO7REV4IcCAbMarvxfTCNdupCfJNF6l43ivhrIo0TzeKZYKd7LX89bVHwzI+9in8MLJxqU8BObPGg01zrpDvqqTHoxuDsKHIf4oe9n9wRlaaC5FOhoAwXBNeqsRW4P9RE+kuS9sAiYyrZLXnq+Vv6PZXl0RuaOVr31iL1w9GGQ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fXyB2i2rlbhIDdUGMFw0172WAOPS5vWqh1rWb4mJ12Xfb3uHliO6huNFrxcgkIj8qv8CVvDVPBd0oQmsOm42WNpbbHZTEX+oLioYe/gii8axWIZXcrA1oEIckaYe5R7iMD4CH5gMXcSkYRgYYMmmr+Forh5Tt4+ 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: From: Kairui Song Currently VMA readahead is globally disabled when any rotate disk is used as swap backend. So multiple swap devices are enabled, if a slower hard disk is set as a low priority fallback, and a high performance SSD is used and high priority swap device, vma readahead is disabled globally. The SSD swap device performance will drop by a lot. Check readahead policy per entry to avoid such problem. Signed-off-by: Kairui Song --- mm/swap_state.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index ff6756f2e8e4..fb78f7f18ed7 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -321,9 +321,9 @@ static inline bool swap_use_no_readahead(struct swap_info_struct *si, swp_entry_ return data_race(si->flags & SWP_SYNCHRONOUS_IO) && __swap_count(entry) == 1; } -static inline bool swap_use_vma_readahead(void) +static inline bool swap_use_vma_readahead(struct swap_info_struct *si) { - return READ_ONCE(enable_vma_readahead) && !atomic_read(&nr_rotate_swap); + return data_race(si->flags & SWP_SOLIDSTATE) && READ_ONCE(enable_vma_readahead); } /* @@ -341,7 +341,7 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); if (!IS_ERR(folio)) { - bool vma_ra = swap_use_vma_readahead(); + bool vma_ra = swap_use_vma_readahead(swp_swap_info(entry)); bool readahead; /* @@ -920,16 +920,18 @@ static struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, struct page *swapin_readahead(swp_entry_t entry, gfp_t gfp_mask, struct vm_fault *vmf, bool *swapcached) { + struct swap_info_struct *si; struct mempolicy *mpol; struct page *page; pgoff_t ilx; bool cached; + si = swp_swap_info(entry); mpol = get_vma_policy(vmf->vma, vmf->address, 0, &ilx); - if (swap_use_no_readahead(swp_swap_info(entry), entry)) { + if (swap_use_no_readahead(si, entry)) { page = swapin_no_readahead(entry, gfp_mask, mpol, ilx, vmf->vma->vm_mm); cached = false; - } else if (swap_use_vma_readahead()) { + } else if (swap_use_vma_readahead(si)) { page = swap_vma_readahead(entry, gfp_mask, mpol, ilx, vmf); cached = true; } else {