From patchwork Thu Feb 25 07:29:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12103565 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=-13.5 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,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 94C30C433E0 for ; Thu, 25 Feb 2021 07:34:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F20F64E85 for ; Thu, 25 Feb 2021 07:34:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F20F64E85 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 8D80A6B0073; Thu, 25 Feb 2021 02:33:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 832FF8D0005; Thu, 25 Feb 2021 02:33:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F8C06B0075; Thu, 25 Feb 2021 02:33:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 5B1AD6B0073 for ; Thu, 25 Feb 2021 02:33:57 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2C374180AC498 for ; Thu, 25 Feb 2021 07:33:57 +0000 (UTC) X-FDA: 77855976114.07.B13C944 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf11.hostedemail.com (Postfix) with ESMTP id E09D12000381 for ; Thu, 25 Feb 2021 07:33:46 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id o6so3012287pjf.5 for ; Wed, 24 Feb 2021 23:33:56 -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=JZI/Cbjn5yPQpxTbGPsLZp1NA7npdB4OJJowknZTVUs=; b=KjOOgxtrhZlH8VdO3dMyYpui8dLLX2TbOkHXP4hItYpluXhWbReLIAH0zLujUrAQYz S++VpRkVYfNGYMBON/Dw1siXsLXFn4MI1tQemzVZk+AyG0gxQUPCF4runK17YMZSDOst eMyTv7Se9QIfpWVUZSC2e4TW9RwMQswLSUob3trfEHFrCu/pujybAS+bt8jx8D5JSRko 7j4ksmuDorNaeM77FX36QzIyIh536zFzd0euF5EenlcEt3J92kCkxmxBz03xfM+jDFJ8 H682Owwk4peOC4ffUSJHOD5832Lwf7Jun5us4rT8vDmv2reNWUUbF5R+IzmPq3HTNCz+ tB4Q== 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=JZI/Cbjn5yPQpxTbGPsLZp1NA7npdB4OJJowknZTVUs=; b=A80zd5093aQ7OSZUt7YvhVEWJsDxfxbHlhTxXOrsZ80fQZWX1xTX4T6V1SfL7xjaPW vYNsvNbQxV3r+coWT+ItxXZdNthIShmzAwWFoeleJMrNNHKZBx/8L18diAAGuRzAqGKW GE7dCsj5OktEG4CQGSQtTspx2t2aNVCw7wwR34V3dO9Axs16qwS6uXs12EMjbzlRkRT9 cIMige+26W3BZu5O1Nd5LK/OGIyoa23ZvCXbBhJkmYnSqpE8+5IvbxrdMkrNAumlL8c/ ur5/HHM5KGbu4tH1oi6pNvAQYJvkJYQTiVKfYKxlNd1K3YwgTRkQtC3gSR5d4/VFEdUw b1LQ== X-Gm-Message-State: AOAM533ltjRZYkAcwyLs+/WAajox2oMmAFvKKYLtfOEJSr5nfB0cj1zu Q67hJGC/8oQWIctyc4fPyhNOW5u2SCFhLg== X-Google-Smtp-Source: ABdhPJyr/UlzcZf2ldqJ+gitmpfnxmmzEHvMiLhJ+XDQ8mDA7ozvSlKj+GAJbrvNdJPIN+HxPqRCGg== X-Received: by 2002:a17:90a:9c7:: with SMTP id 65mr2033257pjo.24.1614238435483; Wed, 24 Feb 2021 23:33:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 23:33:55 -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 5/6] mm: use lightweight reclaim on FAULT_FLAG_RETRY_NOWAIT Date: Wed, 24 Feb 2021 23:29:09 -0800 Message-Id: <20210225072910.2811795-6-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: rspam04 X-Rspamd-Queue-Id: E09D12000381 X-Stat-Signature: ad48j51puih7uqap4i94s6oqzc1eioqr Received-SPF: none (<>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from="<>"; helo=mail-pj1-f48.google.com; client-ip=209.85.216.48 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614238426-785298 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 When FAULT_FLAG_RETRY_NOWAIT is set, the caller arguably wants only a lightweight reclaim to avoid a long reclamation, which would not respect the "NOWAIT" semantic. Regard the request in swap and file-backed page-faults accordingly during the first try. 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 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 13b9cf36268f..70899c92a9e6 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2679,18 +2679,31 @@ static inline bool cow_user_page(struct page *dst, struct page *src, return ret; } -static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma) +static gfp_t massage_page_gfp_mask(gfp_t gfp_mask, unsigned long vmf_flags) { - struct file *vm_file = vma->vm_file; + if (fault_flag_allow_retry_first(vmf_flags) && + (vmf_flags & FAULT_FLAG_RETRY_NOWAIT)) + gfp_mask |= __GFP_NORETRY | __GFP_NOWARN; - if (vm_file) - return mapping_gfp_mask(vm_file->f_mapping) | __GFP_FS | __GFP_IO; + return gfp_mask; +} + +static gfp_t __get_fault_gfp_mask(struct vm_area_struct *vma, + unsigned long flags) +{ + struct file *vm_file = vma->vm_file; + gfp_t gfp_mask; /* * Special mappings (e.g. VDSO) do not have any file so fake * a default GFP_KERNEL for them. */ - return GFP_KERNEL; + if (!vm_file) + return GFP_KERNEL; + + gfp_mask = mapping_gfp_mask(vm_file->f_mapping) | __GFP_FS | __GFP_IO; + + return massage_page_gfp_mask(gfp_mask, flags); } /* @@ -3253,6 +3266,7 @@ EXPORT_SYMBOL(unmap_mapping_range); */ vm_fault_t do_swap_page(struct vm_fault *vmf) { + gfp_t gfp_mask = massage_page_gfp_mask(GFP_HIGHUSER_MOVABLE, vmf->flags); struct vm_area_struct *vma = vmf->vma; struct page *page = NULL, *swapcache; swp_entry_t entry; @@ -3293,8 +3307,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && __swap_count(entry) == 1) { /* skip swapcache */ - page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, - vmf->address); + page = alloc_page_vma(gfp_mask, vma, vmf->address); if (page) { int err; @@ -3320,8 +3333,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) swap_readpage(page, true); } } else { - page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, - vmf); + page = swapin_readahead(entry, gfp_mask, vmf); swapcache = page; } @@ -4452,7 +4464,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, .address = address & PAGE_MASK, .flags = flags, .pgoff = linear_page_index(vma, address), - .gfp_mask = __get_fault_gfp_mask(vma), + .gfp_mask = __get_fault_gfp_mask(vma, flags), }; unsigned int dirty = flags & FAULT_FLAG_WRITE; struct mm_struct *mm = vma->vm_mm;