From patchwork Thu Feb 25 07:29:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12103563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29172C433DB for ; Thu, 25 Feb 2021 07:34:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B0DB164E85 for ; Thu, 25 Feb 2021 07:34:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0DB164E85 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 378618D0003; Thu, 25 Feb 2021 02:33:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 357286B0074; Thu, 25 Feb 2021 02:33:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 216638D0003; Thu, 25 Feb 2021 02:33:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id 0AA9D6B0073 for ; Thu, 25 Feb 2021 02:33:56 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id CF969181AEF3F for ; Thu, 25 Feb 2021 07:33:55 +0000 (UTC) X-FDA: 77855976030.17.7600B04 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 0387FC0001EE for ; Thu, 25 Feb 2021 07:33:56 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id z5so3056679pfe.3 for ; Wed, 24 Feb 2021 23:33:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/5/6+cfz5gtBsby2ty8cXFbwclvAT3dDAZAxr63sxVg=; b=ibGos30OWkGhK94St7H4ygsjcHlkjiHBe5OfiXsHHCMi8KokCyS8CUUj6+jho55QZL vockORGC/YpJq4oaHSlTs5c6p1B9UfpQVf+26G/WLd1nZ974LY3hgX2NJmUkMYjVn4yQ Ujdew4CI+s0gBBq1esyGow3zdyEO1HNPG4Nu+VblemfLozhl6TfV9heeBW1Y6yda+KCG ZwNpD0fxcntbR75Z5IkbtixArbBQzph7R7+XZvt2GD9uvzBGIY8TRKfX/tfCEbRIHSV3 CC0zzYWVRQNpMJMgbcTSGTSeXhV2+TIptv1V3XkTbY/+YOAgUaVZRP9s17XEPl+cZ5HS dvEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/5/6+cfz5gtBsby2ty8cXFbwclvAT3dDAZAxr63sxVg=; b=SUZPCprWIk/0DdElSByKgi6DwziOhVDhxM1bM+/3eU01rMwk/wG8YNn4u0ezbkUOXX vQv+SmxN60+WA/yWACKiDz9iGwX9nGab3RTcy8QeYN9sHk0TRYfWAb766LNtwL3sF/v8 U51HbkPq82DWNy7OJj32CQzZrVcrahtAjb45NL9el8WcPLxoZdXT3S42wuGT8w+8Gzhh X5MblSMXGJd+823TZjLtVb3sX4Gr0cp5w470SZZnhkwNOEJLRlMSnsuD51c9mvGcP1Ed NXE3E6lViGZf5IyK1FNdqfzCAuRyuLIHrjDufZxrGRamCIqGljCrS4cyRpWvyG7Eswnv C0aw== X-Gm-Message-State: AOAM530CjQmryMXaqkFenhDiKb56HQurYsFXUNgsXqX1+Vct0+lCuDOK B9NqUBugv9nHHFOrg/GOu1PqbvMBrUygcQ== X-Google-Smtp-Source: ABdhPJzlg70x3wr3Y1hic7wjGCwzmQfHI7U2X3bfeBjzjSYddIgrS14TA6tUsoKVfGhF8hS6lxHCYw== X-Received: by 2002:a62:1412:0:b029:1ec:bc11:31fd with SMTP id 18-20020a6214120000b02901ecbc1131fdmr1997292pfu.76.1614238434086; Wed, 24 Feb 2021 23:33:54 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id w3sm4917561pjt.24.2021.02.24.23.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 23:33:53 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Andy Lutomirski , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Nadav Amit , Sean Christopherson , Andrew Morton , x86@kernel.org Subject: [RFC 4/6] mm/swap_state: respect FAULT_FLAG_RETRY_NOWAIT Date: Wed, 24 Feb 2021 23:29:08 -0800 Message-Id: <20210225072910.2811795-5-namit@vmware.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225072910.2811795-1-namit@vmware.com> References: <20210225072910.2811795-1-namit@vmware.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0387FC0001EE X-Stat-Signature: 58t6w946et3yr65ztnqpxb9xacje5dgi Received-SPF: none (<>: No applicable sender policy available) receiver=imf06; identity=mailfrom; envelope-from="<>"; helo=mail-pf1-f172.google.com; client-ip=209.85.210.172 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614238436-574326 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: From: Nadav Amit Certain use-cases (e.g., prefetch_page()) may want to avoid polling while a page is brought from the swap. Yet, swap_cluster_readahead() and swap_vma_readahead() do not respect FAULT_FLAG_RETRY_NOWAIT. Add support to respect FAULT_FLAG_RETRY_NOWAIT by not polling in these cases. Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Sean Christopherson Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Andrew Morton Cc: x86@kernel.org Signed-off-by: Nadav Amit --- mm/memory.c | 15 +++++++++++++-- mm/shmem.c | 1 + mm/swap_state.c | 12 +++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index feff48e1465a..13b9cf36268f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3326,12 +3326,23 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } if (!page) { + /* + * Back out if we failed to bring the page while we + * tried to avoid I/O. + */ + if (fault_flag_allow_retry_first(vmf->flags) && + (vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) { + ret = VM_FAULT_RETRY; + delayacct_clear_flag(DELAYACCT_PF_SWAPIN); + goto out; + } + /* * Back out if somebody else faulted in this pte * while we released the pte lock. */ - vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + vmf->pte = pte_offset_map_lock(vma->vm_mm, + vmf->pmd, vmf->address, &vmf->ptl); if (likely(pte_same(*vmf->pte, vmf->orig_pte))) ret = VM_FAULT_OOM; delayacct_clear_flag(DELAYACCT_PF_SWAPIN); diff --git a/mm/shmem.c b/mm/shmem.c index 7c6b6d8f6c39..b108e9ba9e89 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1525,6 +1525,7 @@ static struct page *shmem_swapin(swp_entry_t swap, gfp_t gfp, shmem_pseudo_vma_init(&pvma, info, index); vmf.vma = &pvma; vmf.address = 0; + vmf.flags = 0; page = swap_cluster_readahead(swap, gfp, &vmf); shmem_pseudo_vma_destroy(&pvma); diff --git a/mm/swap_state.c b/mm/swap_state.c index 751c1ef2fe0e..1e930f7ff8b3 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -656,10 +656,13 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, unsigned long mask; struct swap_info_struct *si = swp_swap_info(entry); struct blk_plug plug; - bool do_poll = true, page_allocated; + bool page_allocated, do_poll; struct vm_area_struct *vma = vmf->vma; unsigned long addr = vmf->address; + do_poll = !fault_flag_allow_retry_first(vmf->flags) || + !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT); + mask = swapin_nr_pages(offset) - 1; if (!mask) goto skip; @@ -838,7 +841,7 @@ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask, pte_t *pte, pentry; swp_entry_t entry; unsigned int i; - bool page_allocated; + bool page_allocated, do_poll; struct vma_swap_readahead ra_info = { .win = 1, }; @@ -873,9 +876,12 @@ static struct page *swap_vma_readahead(swp_entry_t fentry, gfp_t gfp_mask, } blk_finish_plug(&plug); lru_add_drain(); + skip: + do_poll = (!fault_flag_allow_retry_first(vmf->flags) || + !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) && ra_info.win == 1; return read_swap_cache_async(fentry, gfp_mask, vma, vmf->address, - ra_info.win == 1); + do_poll); } /**