From patchwork Tue Sep 22 02:01:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 11791339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85B8B112C for ; Tue, 22 Sep 2020 02:11:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4491523A7A for ; Tue, 22 Sep 2020 02:11:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4491523A7A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3650790001A; Mon, 21 Sep 2020 22:11:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 315AA900012; Mon, 21 Sep 2020 22:11:45 -0400 (EDT) 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 2058590001A; Mon, 21 Sep 2020 22:11:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 08051900012 for ; Mon, 21 Sep 2020 22:11:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C35DF181AEF09 for ; Tue, 22 Sep 2020 02:11:44 +0000 (UTC) X-FDA: 77289071328.14.wire94_3f03ca22714a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id A323918229818 for ; Tue, 22 Sep 2020 02:11:44 +0000 (UTC) X-Spam-Summary: 1,0,0,010f9a75b5168dae,d41d8cd98f00b204,riel@shelob.surriel.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:2898:3138:3139:3140:3141:3142:3354:3865:3866:3867:3870:4321:4605:5007:6261:7875:8957:10004:11026:11232:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12683:12895:13161:13229:13894:14096:14110:14181:14394:14721:21080:21627:21990:30003:30054:30070,0,RBL:96.67.55.147:@shelob.surriel.com:.lbl8.mailshell.net-64.201.201.201 62.8.0.100;04y8ykiajmf5da7wna4geqt861gh1opsh9rb4xr6hcffgw61xf6k6kaqnrzaszt.8hx5pbtxjhajskq1tmxfe3t5jsrybbztuuu5ej4ff5gpp9kw689crbr79hztzzk.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: wire94_3f03ca22714a X-Filterd-Recvd-Size: 3675 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 02:11:44 +0000 (UTC) Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kKXcv-0003Cm-DM; Mon, 21 Sep 2020 22:01:53 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kernel-team@fb.com, niketa@fb.com, akpm@linux-foundation.org, sjenning@redhat.com, ddstreet@ieee.org, konrad.wilk@oracle.com, hannes@cmpxchg.org, Rik van Riel Subject: [PATCH 1/2] mm,swap: extract swap single page readahead into its own function Date: Mon, 21 Sep 2020 22:01:47 -0400 Message-Id: <20200922020148.3261797-2-riel@surriel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200922020148.3261797-1-riel@surriel.com> References: <20200922020148.3261797-1-riel@surriel.com> MIME-Version: 1.0 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 swap single page readahead into its own function, to make the next patch easier to read. No functional changes. Signed-off-by: Rik van Riel --- mm/swap_state.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index c16eebb81d8b..aacb9ba53f63 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -594,6 +594,28 @@ static unsigned long swapin_nr_pages(unsigned long offset) return pages; } +static struct page *swap_cluster_read_one(swp_entry_t entry, + unsigned long offset, gfp_t gfp_mask, + struct vm_area_struct *vma, unsigned long addr, bool readahead) +{ + bool page_allocated; + struct page *page; + + page =__read_swap_cache_async(swp_entry(swp_type(entry), offset), + gfp_mask, vma, addr, &page_allocated); + if (!page) + return NULL; + if (page_allocated) { + swap_readpage(page, false); + if (readahead) { + SetPageReadahead(page); + count_vm_event(SWAP_RA); + } + } + put_page(page); + return page; +} + /** * swap_cluster_readahead - swap in pages in hope we need them soon * @entry: swap entry of this memory @@ -615,14 +637,13 @@ static unsigned long swapin_nr_pages(unsigned long offset) struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, struct vm_fault *vmf) { - struct page *page; unsigned long entry_offset = swp_offset(entry); unsigned long offset = entry_offset; unsigned long start_offset, end_offset; unsigned long mask; struct swap_info_struct *si = swp_swap_info(entry); struct blk_plug plug; - bool do_poll = true, page_allocated; + bool do_poll = true; struct vm_area_struct *vma = vmf->vma; unsigned long addr = vmf->address; @@ -649,19 +670,8 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, blk_start_plug(&plug); for (offset = start_offset; offset <= end_offset ; offset++) { /* Ok, do the async read-ahead now */ - page = __read_swap_cache_async( - swp_entry(swp_type(entry), offset), - gfp_mask, vma, addr, &page_allocated); - if (!page) - continue; - if (page_allocated) { - swap_readpage(page, false); - if (offset != entry_offset) { - SetPageReadahead(page); - count_vm_event(SWAP_RA); - } - } - put_page(page); + swap_cluster_read_one(entry, offset, gfp_mask, vma, addr, + offset != entry_offset); } blk_finish_plug(&plug); From patchwork Tue Sep 22 02:01:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 11791337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3A86C59D for ; Tue, 22 Sep 2020 02:02:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F3CDA23A7A for ; Tue, 22 Sep 2020 02:02:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3CDA23A7A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 331EB900019; Mon, 21 Sep 2020 22:02:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2B9FD900012; Mon, 21 Sep 2020 22:02:08 -0400 (EDT) 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 15B55900019; Mon, 21 Sep 2020 22:02:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id F10F6900012 for ; Mon, 21 Sep 2020 22:02:07 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id AD04C180AD804 for ; Tue, 22 Sep 2020 02:02:07 +0000 (UTC) X-FDA: 77289047094.17.beast25_4b03d682714a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 8F6D7180D0181 for ; Tue, 22 Sep 2020 02:02:07 +0000 (UTC) X-Spam-Summary: 1,0,0,317f72e62b9b532a,d41d8cd98f00b204,riel@shelob.surriel.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:2898:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:4250:4321:4605:5007:6261:8957:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13069:13311:13357:13894:14096:14181:14384:14394:14721:21080:21324:21627:30054:30070,0,RBL:96.67.55.147:@shelob.surriel.com:.lbl8.mailshell.net-64.201.201.201 62.14.0.100;04yrs33fcuapb5mmb49xitf86dpsfop3wkmhn19wpzgcu4hk4iot48hd1nutxbm.qynz4mimaofmcnhz8as85iwfkrc7jziatin17z33zozsn5qsbq55xenstobhkyu.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: beast25_4b03d682714a X-Filterd-Recvd-Size: 3149 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 22 Sep 2020 02:02:07 +0000 (UTC) Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kKXcv-0003Cm-EZ; Mon, 21 Sep 2020 22:01:53 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, kernel-team@fb.com, niketa@fb.com, akpm@linux-foundation.org, sjenning@redhat.com, ddstreet@ieee.org, konrad.wilk@oracle.com, hannes@cmpxchg.org, Rik van Riel Subject: [PATCH 2/2] mm,swap: skip swap readahead if page was obtained instantaneously Date: Mon, 21 Sep 2020 22:01:48 -0400 Message-Id: <20200922020148.3261797-3-riel@surriel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200922020148.3261797-1-riel@surriel.com> References: <20200922020148.3261797-1-riel@surriel.com> MIME-Version: 1.0 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: Check whether a swap page was obtained instantaneously, for example because it is in zswap, or on a very fast IO device which uses busy waiting, and we did not wait on IO to swap in this page. If no IO was needed to get the swap page we want, kicking off readahead on surrounding swap pages is likely to be counterproductive, because the extra loads will cause additional latency, use up extra memory, and chances are the surrounding pages in swap are just as fast to load as this one, making readahead pointless. Signed-off-by: Rik van Riel --- mm/swap_state.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index aacb9ba53f63..6919f9d5fe88 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -637,6 +637,7 @@ static struct page *swap_cluster_read_one(swp_entry_t entry, struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, struct vm_fault *vmf) { + struct page *page; unsigned long entry_offset = swp_offset(entry); unsigned long offset = entry_offset; unsigned long start_offset, end_offset; @@ -668,11 +669,18 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, end_offset = si->max - 1; blk_start_plug(&plug); + /* If we read the page without waiting on IO, skip readahead. */ + page = swap_cluster_read_one(entry, offset, gfp_mask, vma, addr, false); + if (page && PageUptodate(page)) + goto skip_unplug; + + /* Ok, do the async read-ahead now. */ for (offset = start_offset; offset <= end_offset ; offset++) { - /* Ok, do the async read-ahead now */ - swap_cluster_read_one(entry, offset, gfp_mask, vma, addr, - offset != entry_offset); + if (offset == entry_offset) + continue; + swap_cluster_read_one(entry, offset, gfp_mask, vma, addr, true); } +skip_unplug: blk_finish_plug(&plug); lru_add_drain(); /* Push any new pages onto the LRU now */