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; From patchwork Sun Dec 30 04:49:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10745051 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 0BA611874 for ; Sun, 30 Dec 2018 04:50:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E016228715 for ; Sun, 30 Dec 2018 04:50:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCF2F2873A; Sun, 30 Dec 2018 04:50:04 +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 0121E28715 for ; Sun, 30 Dec 2018 04:50:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76A888E006D; Sat, 29 Dec 2018 23:50:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 717238E005B; Sat, 29 Dec 2018 23:50:00 -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 6056C8E006D; Sat, 29 Dec 2018 23:50:00 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 1D3618E005B for ; Sat, 29 Dec 2018 23:50:00 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id ay11so20558960plb.20 for ; Sat, 29 Dec 2018 20:50:00 -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:in-reply-to:references; bh=lcjD1zBeERRxJjf2F3hugdxuZivyMNd/i0PSrUp1gXo=; b=T2s7Cn/85+bwzHkBoMEC+At7ZwnxRyp8+Ela8/quB94Dwr8hLMFPXm8BBY9Cq47Wnh 7dE7aZygCRjkMbf68MF+goLUnHGAAluK619iTXqFT1KsSi7JhejT5Q4z73DJUVTQS5nB F9jzfnJi+SnOh7b9kcmr5sEvPsFzVmnW2GOydwkd5dIFKVnNTZ8899jQRvnVzd4PsyXc glVzhmrr0AImrR7tTEk1eKpa12020GwRfEQHs0KqPCJ+gWUp6hW5w0zYSBt84Wl+8RMq efCdkEH9NMv0hdp9hZpvs4IL7yYDOLL/oQNoJSTLPFN/brVzswor9w0xpVGkX4Beoppw 83jQ== 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: AJcUukcYSFEegHbJ0f1CaDbrsJPQ9jZ40ProZ5hnh1iyl1vqCh/1rHxK rkiP3QxfxE0/j+gNErpblPF5+t396ufeiTL2D6CzFFNE/QB5LA/RDhXHzTnWMV9kkigLmt6L+FM hda1HI3BZSpz6dKx+1mvG2fVWNPnMVCRBX8RPFuUhcjFUfHAV/brdrpBxGC86nSkcQA== X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr33544671plb.254.1546145399661; Sat, 29 Dec 2018 20:49:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN6GkiayxC2pHIoQ8ivrwscsJ/MktvPHCum7X6a+imEP2QZqGduTzsKWJWRJZ7yoWNp+TN7r X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr33544649plb.254.1546145398893; Sat, 29 Dec 2018 20:49:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546145398; cv=none; d=google.com; s=arc-20160816; b=kywy6xZsgQtPLPJRbsdNZEdlDXcujxa3DNhucx4q18tZJDAgGJfIw1lzSRp8Or17Ex QInNOzX4eCE+JcgAIUgnenNlJA7zTJgQjbPINK6KVOcY5Tj5Bgd/U7hiV2yKP7WAZlYg T4p9CeynK+47mYOeE+ny01hWS7WnYsrSTQ1QtetgQfyPBFdjX/sXh7SxXWJzDb9Fs1Nx WCAx/g5p40i73yVYDJ1+EF7ZsZaXV7dS959m2u63ABFrrkzebAoqosHz4R50LU00/3iS J2HNsgfjAHDYqo2cRTsXdZxOc7HdkfAof8MZu2FkzfHReE2k7A2jL75hXZ8qqaKeH2qf BR8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=lcjD1zBeERRxJjf2F3hugdxuZivyMNd/i0PSrUp1gXo=; b=iCsX11ECgxfljnaiedczvYx3mnvomQr+qc/lSyY7Pe85qO/zkR+mAF1C1wNClokX0L TYB4K1ha0ak8cJ9owtfh7r3li4ophW/dcvWbrGHxE9wFERKs+4QZqLoVn97Cu1IC+i+D 9Ux5mlQFe5it57+PSaWxT3A3lpCHw7D3hnhj50Oe/l6A4z/TMK7f/fZ2JYRZFskq74bw 34kREFEV9oMBHGiCyyrIq0svuR95x/0aDkIAd1K6y6mW8lMxNVpY9TOxz4sqPz6jTKiW v16XN//VJIJPEK7sITSPuuPZEWqO9iP84ui3Elz5jnPaSv2UHnnxqvnJFNlPdlKSa6M6 v/gw== 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 i20si42118143pgh.187.2018.12.29.20.49.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Dec 2018 20:49:58 -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=01201311R121e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07449;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 2/2] mm: swap: add comment for swap_vma_readahead Date: Sun, 30 Dec 2018 12:49:35 +0800 Message-Id: <1546145375-793-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1546145375-793-1-git-send-email-yang.shi@linux.alibaba.com> References: <1546145375-793-1-git-send-email-yang.shi@linux.alibaba.com> 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_vma_readahead()'s comment is missed, just add it. Cc: Huang Ying Cc: Tim Chen Cc: Minchan Kim Signed-off-by: Yang Shi --- mm/swap_state.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mm/swap_state.c b/mm/swap_state.c index 78d500e..dd8f698 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -698,6 +698,23 @@ static void swap_ra_info(struct vm_fault *vmf, pte_unmap(orig_pte); } +/** + * swap_vm_readahead - swap in pages in hope we need them soon + * @entry: swap entry of this memory + * @gfp_mask: memory allocation flags + * @vmf: fault information + * + * Returns the struct page for entry and addr, after queueing swapin. + * + * Primitive swap readahead code. We simply read in a few pages whoes + * virtual addresses are around the fault address in the same vma. + * + * This has been extended to use the NUMA policies from the mm triggering + * the readahead. + * + * Caller must hold down_read on the vma->vm_mm if vmf->vma is not NULL. + * + */ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask, struct vm_fault *vmf) {