Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3616319pxk; Mon, 21 Sep 2020 20:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+EDnOmYta+ySl9eJTNYs5RTrrNhUkLKaJq7lDA5qkoeSbHsm41P9/4B9oWJ8oYnFVptJT X-Received: by 2002:a17:906:719a:: with SMTP id h26mr2729237ejk.336.1600744208325; Mon, 21 Sep 2020 20:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600744208; cv=none; d=google.com; s=arc-20160816; b=fmyi91txeO1ZqRsSKvetO7b9CLlIQWHh3zOw9jjDVJnhS4M5sfrGE34GnwYSGOIMEQ brAdxLgwTNV7o29O62pssnS6Z3MvnOqDsRLUKxh7wByys+EYxXdDtRzkXJyUp8hg08YT 2gEQc+zi55v7GS2kCGha0jCrK9cpceVpI+SVEGlfwbBvGavzuskppEdm2xOieBbaxMiT 64wuEhLLHGuxpNDMeziOwmy1l5Q+cuUXV6N8vx+5l+3x9tsE3VTT+76eX5xlpqDIsVOe hVc5rmjYHtGQ1yj5cu8NG2bgwNCYoEQi/sbtR2pZufuL5FnCwjdTYRVF1eoLwi251P10 Ftgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Xdj4DBPgclgqQg6pAVEx61PjZrc/rEiAV6SWUtvdpEg=; b=AB9zplyJQFdqTckNXm5Xpps60P/kuXj1sZ3EudqjG1rAUB8t2qSnYL5nMVJHT6ock0 BmABsLYqyw+CadsWnDJMHgPk70AvZA6kc1wzNPQrcUt105pUumVYMk/BEuBmiB4p/4UI 2ZqrPZvxSyWOyXv4bYVc8Y2uj+li22802mgFyOFqaPFXohmpQrTyX66MJHEp67IiV1Kr s892gziorQwwpmjG1MaTAb5PWWeh5oCZYmJ+D8esCgm/0u0xtUj+o8Kf3mfC/25jwaYU i4JOlyu12QKv+9xQ7uMrJq9H0I2UNgQtxXtgMONEzMPoJZsnhG5dfWzZQSx7K2tAlg3y N7rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b26si4698078edu.250.2020.09.21.20.09.45; Mon, 21 Sep 2020 20:10:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729407AbgIVCCH (ORCPT + 99 others); Mon, 21 Sep 2020 22:02:07 -0400 Received: from shelob.surriel.com ([96.67.55.147]:45670 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729366AbgIVCCE (ORCPT ); Mon, 21 Sep 2020 22:02:04 -0400 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 Content-Transfer-Encoding: 8bit Sender: riel@shelob.surriel.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.25.4