From patchwork Sun Dec 30 04:49:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10745053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4F7413AD for ; Sun, 30 Dec 2018 04:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C48222880B for ; Sun, 30 Dec 2018 04:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B869328B01; Sun, 30 Dec 2018 04:50:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 407342880B for ; Sun, 30 Dec 2018 04:50:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78F198E006E; Sat, 29 Dec 2018 23:50:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 73FC28E005B; Sat, 29 Dec 2018 23:50:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62C6E8E006E; Sat, 29 Dec 2018 23:50:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 2022F8E005B for ; Sat, 29 Dec 2018 23:50:29 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id v11so20602901ply.4 for ; Sat, 29 Dec 2018 20:50:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=sS5kvMTElfOWvunL1XHhe0WP3EXyhE57LqPU2jaQ+nY=; b=Hb3/QtONw2R0AKeaMErg7SIjgbMCR76pTrdw9A5Q8cTXffQdTke9ZiPuqL/l6kRJdU fWF/0t5OS6P7SOgv6+WBfJrky3UyNjI/Djvy8/FCMWP0FW8Su6sq/17wZttiswqEUHVw 1GBhDnpaP3cU9Emn63T9sPn3eLKecQUupEfd2wkhRtgmm43ywY9jiv4pRIIpWg1h1yOA PShBbeWmmT73fYIoVH23/ZjJbDdhrC4i5vzaatjFidZhBQT9KwI092zUIpve6ldijI0O pEYxQjXJBRQeNNgxdrTz3662rZJWqw1LtrGqViLqLOdcf0ON38M1UAjTI1VoO326Xmo3 wrxQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AJcUukfQZ8uaqb6SV8yykg9iAedIxyRinGMVPx6sZUnTClWSLYwy+twP 3Zaxd724pvgWeVWn0n4GtwpiAXyBaQ6IjHIyNfjJt12KRXR6NTIlIIjb8/MkeMH6uv59RMeFc/F ecGp5Ns20Ivaq1lDe18mtsEdnsZ2l4H0dUQK7SlU0mKx+6EsuwWCgFuwmC4ZpnHWRDw== X-Received: by 2002:a17:902:9045:: with SMTP id w5mr31792417plz.32.1546145428760; Sat, 29 Dec 2018 20:50:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ejZF5OIg/6AWzYfylWTPpKBC8Vh1Y+UuC95KNArPvz9Nt0ticRiG7kyTK6EhbQ40R8Foh X-Received: by 2002:a17:902:9045:: with SMTP id w5mr31792392plz.32.1546145427460; Sat, 29 Dec 2018 20:50:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546145427; cv=none; d=google.com; s=arc-20160816; b=SgptPkhfjyUdxQIv6YLxZTOpT4URQev2JU8qr6rDC8NNCPefl6Vtsl5Y4PzFN0lNrX MdNVYJ+BICJp0EVEMMF3s2B0jsZggeqMQ0CpXXtT87bfV7lmLu6y+UeogEF67sY3y6eV L8T2xLC1KUHr5dqfGWC2J+C5xSmD5Kc51UX375A6QFL6D4SvG6IQEE/qSU1FAMoDeHB1 iHwh8hY9RZrq9ULvmbzDS0ZPzA3aOuj3sC//i7FT3mmdLDhhm4/Ryk8r3P7hXGRn4DtS 0KF34Zk54TDWYxSqGkszsnYMQ+KT2mP2Tkc0rGyp+0zoA7O/06Y4kHvkl8nguP99LAKq 8lVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=sS5kvMTElfOWvunL1XHhe0WP3EXyhE57LqPU2jaQ+nY=; b=Ovu6gWiNAmkSJALwRJRf4B1Q4TvBhbaIOkWTjUatdE3Q6dkStNU4cF473KmQpULDtD DAe+xvPIwLqMbSiSFmQbcD2+Z9TsedJ+iNYXx6XNH33YzRnYa3hAUvkfqHjokgSN7h65 2UaGFbWYjxSTdHCPm4Ky0SK7fyFHnUxa1qlASsN7XX6eOyHQO7ea5VLaXJ+7JNnyeL39 jwDcqHh9PSCawLVLJTbntdhuGEKSdKEGtJJZoRswhqc+ffoBB2ysScd3WfzDmCnvlTMG cXBanFCpQ7RKLwRZBAW/xYw6uKVAjYL8qgTdC/DyritKAPwV12EvOd31zSXhNy0JpxCp HURw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com. [115.124.30.130]) by mx.google.com with ESMTPS id c19si38768515pls.242.2018.12.29.20.50.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Dec 2018 20:50:27 -0800 (PST) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) client-ip=115.124.30.130; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TH6r6Yk_1546145375; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TH6r6Yk_1546145375) by smtp.aliyun-inc.com(127.0.0.1); Sun, 30 Dec 2018 12:49:44 +0800 From: Yang Shi To: ying.huang@intel.com, tim.c.chen@intel.com, minchan@kernel.org, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v4 PATCH 1/2] mm: swap: check if swap backing device is congested or not Date: Sun, 30 Dec 2018 12:49:34 +0800 Message-Id: <1546145375-793-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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: X-Virus-Scanned: ClamAV using ClamSMTP Swap readahead would read in a few pages regardless if the underlying device is busy or not. It may incur long waiting time if the device is congested, and it may also exacerbate the congestion. Use inode_read_congested() to check if the underlying device is busy or not like what file page readahead does. Get inode from swap_info_struct. Although we can add inode information in swap_address_space (address_space->host), it may lead some unexpected side effect, i.e. it may break mapping_cap_account_dirty(). Using inode from swap_info_struct seems simple and good enough. Just does the check in vma_cluster_readahead() since swap_vma_readahead() is just used for non-rotational device which much less likely has congestion than traditional HDD. Although swap slots may be consecutive on swap partition, it still may be fragmented on swap file. This check would help to reduce excessive stall for such case. The test on my virtual machine with congested HDD shows long tail latency is reduced significantly. Without the patch page_fault1_thr-1490 [023] 129.311706: funcgraph_entry: #57377.796 us | do_swap_page(); page_fault1_thr-1490 [023] 129.369103: funcgraph_entry: 5.642us | do_swap_page(); page_fault1_thr-1490 [023] 129.369119: funcgraph_entry: #1289.592 us | do_swap_page(); page_fault1_thr-1490 [023] 129.370411: funcgraph_entry: 4.957us | do_swap_page(); page_fault1_thr-1490 [023] 129.370419: funcgraph_entry: 1.940us | do_swap_page(); page_fault1_thr-1490 [023] 129.378847: funcgraph_entry: #1411.385 us | do_swap_page(); page_fault1_thr-1490 [023] 129.380262: funcgraph_entry: 3.916us | do_swap_page(); page_fault1_thr-1490 [023] 129.380275: funcgraph_entry: #4287.751 us | do_swap_page(); With the patch runtest.py-1417 [020] 301.925911: funcgraph_entry: #9870.146 us | do_swap_page(); runtest.py-1417 [020] 301.935785: funcgraph_entry: 9.802us | do_swap_page(); runtest.py-1417 [020] 301.935799: funcgraph_entry: 3.551us | do_swap_page(); runtest.py-1417 [020] 301.935806: funcgraph_entry: 2.142us | do_swap_page(); runtest.py-1417 [020] 301.935853: funcgraph_entry: 6.938us | do_swap_page(); runtest.py-1417 [020] 301.935864: funcgraph_entry: 3.765us | do_swap_page(); runtest.py-1417 [020] 301.935871: funcgraph_entry: 3.600us | do_swap_page(); runtest.py-1417 [020] 301.935878: funcgraph_entry: 7.202us | do_swap_page(); Acked-by: Tim Chen Cc: Huang Ying Cc: Minchan Kim Signed-off-by: Yang Shi --- v4: Added observed effects in the commit log per Andrew v3: Move inode deference under swap device type check per Tim Chen v2: Check the swap device type per Tim Chen mm/swap_state.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/swap_state.c b/mm/swap_state.c index fd2f21e..78d500e 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -538,11 +538,18 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, bool do_poll = true, page_allocated; struct vm_area_struct *vma = vmf->vma; unsigned long addr = vmf->address; + struct inode *inode = NULL; mask = swapin_nr_pages(offset) - 1; if (!mask) goto skip; + if (si->flags & (SWP_BLKDEV | SWP_FS)) { + inode = si->swap_file->f_mapping->host; + if (inode_read_congested(inode)) + goto skip; + } + do_poll = false; /* Read a page_cluster sized and aligned cluster around offset. */ start_offset = offset & ~mask;