Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2677897imm; Thu, 18 Oct 2018 20:15:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Sfd0zAIH+Y+oyCgFK7LVBHb0bCYrxFWYX0RPj2qsN4E8p328O8nCHcGhVI1aDeeMLlqHu X-Received: by 2002:a17:902:5a43:: with SMTP id f3-v6mr648794plm.114.1539918957935; Thu, 18 Oct 2018 20:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539918957; cv=none; d=google.com; s=arc-20160816; b=I529KfP1cPclCciOWMC0vx557+L9Ga8gPdIuiuJoar2pUpIwuDx2xZq2Om4k9ASRME hR91B9zwikkdJpJnm10vItpo5YIX9gYwOVs64YzxNLYPZ4lM4XCE24QyswnX6ql+4s7k 9n4HkiXxZVyHV2u9JQ+kJ34Ik3JB6p3wcSQeTvoBGB66JIWnJ8Q3f4n7oRcEUdA8h50M EsHVe51JRqvuYcUCHPdadAPvccNinHkRwpr/Ht6HdPJlMPTZ/Qf0ZIWu09F+Du7/yrUD QXhTuF7wr8F+zsmOZoge+/hYZYiUtGPHni35vQuDMr/SyZEewmYJAECwtNb4VVFTgRmw Yryw== 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=YI8JyV3wnUsEmUDlakpJ03/Yjzwqui9fObtn43AVdxY=; b=vOZ6G4HNL3oBRnz81PNr5S14tbw4wcApps0KYuAu71ZRImso+zSZXQ06ZOen7yYcMt YBPYuO1/Z0fykfxwUtSKD4215OGUqPYVXcCjO7S3RApRhcoL6nD2hamMq/7eP/dCkM9l J0Y2TM2pIJ6ga7HjuOhl+0S+WBoEVDAQesMmJgFbTmFSa1s5LFyrNKBjbbYQPYKRC9cP mHmBdllewRHUAVfjJM21mS5AdmLXy73LGL1y4zfjJ+10DkHL09G/CED2wwvCDZ4il5s0 zC2nKL2wFtjqPX5fA/h4j3aanPuKCSYHytpHjn4ycfJDOYbhnI9efKF2JzL0ePM0Qw0L z8ug== 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 v1-v6si23192824plb.396.2018.10.18.20.15.27; Thu, 18 Oct 2018 20:15:57 -0700 (PDT) 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 S1726702AbeJSLTB (ORCPT + 99 others); Fri, 19 Oct 2018 07:19:01 -0400 Received: from ipmail02.adl2.internode.on.net ([150.101.137.139]:56973 "EHLO ipmail02.adl2.internode.on.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726245AbeJSLTB (ORCPT ); Fri, 19 Oct 2018 07:19:01 -0400 Received: from ppp59-167-129-252.static.internode.on.net (HELO dastard) ([59.167.129.252]) by ipmail02.adl2.internode.on.net with ESMTP; 19 Oct 2018 13:44:46 +1030 Received: from dave by dastard with local (Exim 4.80) (envelope-from ) id 1gDLFO-0006ZQ-3K; Fri, 19 Oct 2018 14:14:46 +1100 Date: Fri, 19 Oct 2018 14:14:46 +1100 From: Dave Chinner To: Josef Bacik Cc: kernel-team@fb.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, tj@kernel.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, riel@fb.com, linux-mm@kvack.org Subject: Re: [PATCH 2/7] mm: drop mmap_sem for page cache read IO submission Message-ID: <20181019031446.GH18822@dastard> References: <20181018202318.9131-1-josef@toxicpanda.com> <20181018202318.9131-3-josef@toxicpanda.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181018202318.9131-3-josef@toxicpanda.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 18, 2018 at 04:23:13PM -0400, Josef Bacik wrote: > From: Johannes Weiner > > Reads can take a long time, and if anybody needs to take a write lock on > the mmap_sem it'll block any subsequent readers to the mmap_sem while > the read is outstanding, which could cause long delays. Instead drop > the mmap_sem if we do any reads at all. > > Signed-off-by: Johannes Weiner > Signed-off-by: Josef Bacik > --- ..... > vm_fault_t filemap_fault(struct vm_fault *vmf) > { > int error; > + struct mm_struct *mm = vmf->vma->vm_mm; > struct file *file = vmf->vma->vm_file; > struct address_space *mapping = file->f_mapping; > struct file_ra_state *ra = &file->f_ra; > struct inode *inode = mapping->host; > pgoff_t offset = vmf->pgoff; > + int flags = vmf->flags; local copy of flags. > pgoff_t max_off; > struct page *page; > vm_fault_t ret = 0; > @@ -2509,27 +2540,44 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > * Do we have something in the page cache already? > */ > page = find_get_page(mapping, offset); > - if (likely(page) && !(vmf->flags & FAULT_FLAG_TRIED)) { > + if (likely(page) && !(flags & FAULT_FLAG_TRIED)) { Used here. > /* > * We found the page, so try async readahead before > * waiting for the lock. > */ > - do_async_mmap_readahead(vmf->vma, ra, file, page, offset); > + error = do_async_mmap_readahead(vmf->vma, ra, file, page, offset, vmf->flags); Not here. > + if (error == -EAGAIN) > + goto out_retry_wait; > } else if (!page) { > /* No page in the page cache at all */ > - do_sync_mmap_readahead(vmf->vma, ra, file, offset); > - count_vm_event(PGMAJFAULT); > - count_memcg_event_mm(vmf->vma->vm_mm, PGMAJFAULT); > ret = VM_FAULT_MAJOR; > + count_vm_event(PGMAJFAULT); > + count_memcg_event_mm(mm, PGMAJFAULT); > + error = do_sync_mmap_readahead(vmf->vma, ra, file, offset, vmf->flags); or here. (Also, the vmf is passed through to where these flags are used, so why is it passed as a separate flag parameter?) > + if (error == -EAGAIN) > + goto out_retry_wait; > retry_find: > page = find_get_page(mapping, offset); > if (!page) > goto no_cached_page; > } > > - if (!lock_page_or_retry(page, vmf->vma->vm_mm, vmf->flags)) { > - put_page(page); > - return ret | VM_FAULT_RETRY; > + if (!trylock_page(page)) { > + if (flags & FAULT_FLAG_ALLOW_RETRY) { > + if (flags & FAULT_FLAG_RETRY_NOWAIT) > + goto out_retry; > + up_read(&mm->mmap_sem); > + goto out_retry_wait; > + } > + if (flags & FAULT_FLAG_KILLABLE) { but is used here... > + int ret = __lock_page_killable(page); > + > + if (ret) { > + up_read(&mm->mmap_sem); > + goto out_retry; > + } > + } else > + __lock_page(page); > } > > /* Did it get truncated? */ > @@ -2607,6 +2655,19 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > /* Things didn't work out. Return zero to tell the mm layer so. */ > shrink_readahead_size_eio(file, ra); > return VM_FAULT_SIGBUS; > + > +out_retry_wait: > + if (page) { > + if (flags & FAULT_FLAG_KILLABLE) and here. Any reason for this discrepancy? -Dave. -- Dave Chinner david@fromorbit.com