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 */