Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp380633imu; Fri, 7 Dec 2018 02:38:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/XxFK2ZXniAAmPD45K7LFY3qU0rLBFzpAgSXDI3xY+ySO6kxNkqkYfZU6RC0ge90u19oLix X-Received: by 2002:a62:d448:: with SMTP id u8mr1693326pfl.105.1544179107063; Fri, 07 Dec 2018 02:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544179107; cv=none; d=google.com; s=arc-20160816; b=oQ/ZD1F192YcYmkPndSQbCPyPrNPaweoTmLuoR2m3J24wCpaN7y7hJLbvNyPyRRMsA dEdqD+D34aJee3q6nQ35JmfSUkBcTJBRbiBFh59wJVW8K6SVxPHp/P3/rTSyWPy+ehEZ FQNqbQOyQhCLNchLGA6GrXH0uIFz3d/yl+/IAt2ASl0SHv8JX/6Qm2VoduXhqPUO7jGm X4dwPBSXfU4rVzXeJgZCFP0EYJEQlgTH70NZ2GCdF7Q4gr+sDWzb6x408Swz/m8l2UEE TjD+q35gtIzIKgmwwpdN2uzKCHVN1oJxAA2V+nKD4aztznPnZC1VMEqHniPrKboVoCtp 0r8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eKNcg1KqzR+HLcjxmitsD4HwRDhmd0F/6Q1s6DjXMNA=; b=cCv3Nojcgs6mhagDahkhXuPMWJYAXsH/cxxzSjVl/cYkrKjU28oBjjFbsH/8BtUPLT fWbmQ8OGAiX0xYGmMcSXVUUHrPgjs3dtGlAlVAmRH7DqSMAb1hGKKG4t3M2BJY/HNOv8 LaBHv9Oeztu3SdkettwOO+4cTbB95P/wqhAMGNM34Hh9aJp3U3Wz772j2iohLzwPNvMP F3IFS3V57V0lPm0vvhN6HHRJVvtfRCT2kjA9XLePdSZ4ztyfTBB6SNyNuIQ7GnQ6qTtg MVECGmIyZe+c4F0Kuu3etN1Oqmaj3otYu09qIaEftqG5p+6QL/7u0LajF4Tz8lcIKguu vK5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si2572344pgp.161.2018.12.07.02.38.09; Fri, 07 Dec 2018 02:38:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726008AbeLGKhc (ORCPT + 99 others); Fri, 7 Dec 2018 05:37:32 -0500 Received: from mx2.suse.de ([195.135.220.15]:35542 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725986AbeLGKhc (ORCPT ); Fri, 7 Dec 2018 05:37:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0FDA3ADD4; Fri, 7 Dec 2018 10:37:30 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id A96BC1E0D9D; Fri, 7 Dec 2018 11:37:28 +0100 (CET) Date: Fri, 7 Dec 2018 11:37:28 +0100 From: Jan Kara To: Josef Bacik Cc: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, david@fromorbit.com, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, riel@redhat.com, jack@suse.cz Subject: Re: [PATCH 2/4] filemap: kill page_cache_read usage in filemap_fault Message-ID: <20181207103728.GD13008@quack2.suse.cz> References: <20181130195812.19536-1-josef@toxicpanda.com> <20181130195812.19536-3-josef@toxicpanda.com> <20181207095750.GC13008@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181207095750.GC13008@quack2.suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 07-12-18 10:57:50, Jan Kara wrote: > On Fri 30-11-18 14:58:10, Josef Bacik wrote: > > If we do not have a page at filemap_fault time we'll do this weird > > forced page_cache_read thing to populate the page, and then drop it > > again and loop around and find it. This makes for 2 ways we can read a > > page in filemap_fault, and it's not really needed. Instead add a > > FGP_FOR_MMAP flag so that pagecache_get_page() will return a unlocked > > page that's in pagecache. Then use the normal page locking and readpage > > logic already in filemap_fault. This simplifies the no page in page > > cache case significantly. > > > > Signed-off-by: Josef Bacik > > Thanks for the patch. I like the simplification but I think it could be > even improved... see below. > > > @@ -2449,9 +2426,11 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > > count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT); > > ret = VM_FAULT_MAJOR; > > retry_find: > > - page = find_get_page(mapping, offset); > > + page = pagecache_get_page(mapping, offset, > > + FGP_CREAT|FGP_FOR_MMAP, > > + vmf->gfp_mask); > > if (!page) > > - goto no_cached_page; > > + return vmf_error(-ENOMEM); > > So why don't you just do: > > page = pagecache_get_page(mapping, offset, > FGP_CREAT | FGP_LOCK, vmf->gfp_mask); > if (!page) > return vmf_error(-ENOMEM); > goto check_uptodate; > > where check_uptodate would be a label before 'PageUptodate' check? > > Then you don't have to introduce new flag for pagecache_get_page() and you > also don't have to unlock and then lock again the page... And you can still > delete all the code you've deleted. Ah, you don't want lock_page() to block in case someone raced with you and instantiated the page so that you can drop mmap_sem. OK, the patch looks good to me then. You can add: Reviewed-by: Jan Kara Honza -- Jan Kara SUSE Labs, CR