Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4153722imu; Fri, 30 Nov 2018 12:00:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/VVuhRp7ZwPyFjBtvhz8E1ImhKVE/yN12MU74zQ1o3KNmGSs7Bf9zexH125Uq9j11pdBqSa X-Received: by 2002:a63:6445:: with SMTP id y66mr6099248pgb.250.1543608045710; Fri, 30 Nov 2018 12:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543608045; cv=none; d=google.com; s=arc-20160816; b=CS3Nq/mCU13byg8DNoo8i8NVeH7pe1dwnJcLIR4pJxiVNtYXFXySD6xMCQ+1bo+ei5 taVWcZ+G1K4fh+NipWPsP/fEqlYIMMk7hOvQzVfvEb/xFAEE8kL84RQ4CicSKvc+aWEp JY2EU+DZOelQ9t08I1IywR/O+pJY5n0vmiS7FhBMctLU5M3bhLEQaoOafNaMJbR2LHh4 4Lt1pDYxQcRXkIJSKxYXq3+ULoMsSoR4JlWWwPKspEiCltr1eTBeReT64uy2sj9K4KtW gltl/VTT0jOqlMGoezFwX4e7PuNwMvVsMlpE8rN3LdwPYELURjyzR0l5sC7by94rWUJm JTyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature; bh=tfQKrc5MaRoWXLgCC8cvo0W1La7ADJ1hTk4hFrcxJ2w=; b=u9Gfoqig6ySN031yjeQsTXaTGBSl8ebiIt0F8WXOVYQKvElXa8B7ZysoDWUaX817gZ InMzuNU7m8WUmOh7XumcXd/R6Yl/1SaiyRrYg9IQxqynJhsgW1tLiyy33pzo4LezyAou lhidDB8lQvMkMweB0z/AtfooglP8lfIjDhVa0eQaISTvnBI5CG/pkViuxNquXZhErS3J RfLdkliyO6Vvo0iV9FADKM80hL2VUeM/iWkhT5NiOTBhtc4KhdIWyOjulrfqcsSyjbTg 66kgelFSfBXinjj9UmDdtYlXl4z0e5GBmXbGlSb+B9SD73a0vROwPJo2HzpvQvSivtVS zt+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=RDqpS5N7; 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 t13si5748659pga.102.2018.11.30.12.00.31; Fri, 30 Nov 2018 12:00:45 -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; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=RDqpS5N7; 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 S1727029AbeLAHIm (ORCPT + 99 others); Sat, 1 Dec 2018 02:08:42 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:38487 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726994AbeLAHIl (ORCPT ); Sat, 1 Dec 2018 02:08:41 -0500 Received: by mail-yb1-f195.google.com with SMTP id u103-v6so2707137ybi.5 for ; Fri, 30 Nov 2018 11:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=tfQKrc5MaRoWXLgCC8cvo0W1La7ADJ1hTk4hFrcxJ2w=; b=RDqpS5N7sRdUqzfJbuUQ3cP6FZpSxwXrU7nIdtgeLwAMDypJ/AuyKBAVURaYyIpF+W TUH2qDG4sSw5CnfzSAptkUg9lt+KdZAK+fgbTlSAWUmnsUi4y6VWMS5jZtZQKr39Njv/ F8ZwAG81ZhZYKh7m/tVeTdOki3HtqStKzcvGDk0owKjUXs3fTpd2tJ9Rs0BrFOp8rDTv IpC12b7mnQMbZP4XGeqQMEzrvS3ty0nrYovoxKqVkHGcEbLTCAAlHOUg1vvZMXmuLnA3 0ld3tOkRZh1iEo4DOXmJFJ2K3rCYGyhbIjrDMvgb3ZrdwLjwfYfU25tiozmcObmmIpqM ezSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=tfQKrc5MaRoWXLgCC8cvo0W1La7ADJ1hTk4hFrcxJ2w=; b=jlIXnEK2ijy7j6fvcdnvjtwLSrtf6spi+SeInkvil4AWNi0CzbzWlQ/iv5XzDxYvON C44wVGJYoUJay7sgls3TeMgQ3DiZSlnrpqxJzcraGn+0LdlPCgz42A9QsvR1SF33GP73 wiX5YxrWmlU8VyVY8DjN9IosVi3dkK6J2L7aKOsd8ElOTJz08QwMr0Jt9AGGdftHOmi5 KNzY0EeVHXr6y+l+U76n1F9jWoxsKN8ZcWELwr/lm3exUMpeykyDWpqOYDa9UOtxuPc5 DhWc1bfpaWG+Yoi8RTJo1TnWt+5Y6aT6c0AjF5qn66csJUwDAdqMaeppBsdXJ4LNjmIb dGww== X-Gm-Message-State: AA+aEWa5EM+kb/frCMy0AICT5LFaAivvq0X9bXvOIMxxbKy2QGIppQUV 6Aff2AiOYwjrzBPWzSzyfoh4EQ== X-Received: by 2002:a25:bb4c:: with SMTP id b12-v6mr6648882ybk.45.1543607897615; Fri, 30 Nov 2018 11:58:17 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id e194sm2151940ywa.85.2018.11.30.11.58.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Nov 2018 11:58:16 -0800 (PST) From: Josef Bacik To: 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: [PATCH 2/4] filemap: kill page_cache_read usage in filemap_fault Date: Fri, 30 Nov 2018 14:58:10 -0500 Message-Id: <20181130195812.19536-3-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181130195812.19536-1-josef@toxicpanda.com> References: <20181130195812.19536-1-josef@toxicpanda.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/linux/pagemap.h | 1 + mm/filemap.c | 73 ++++++++++--------------------------------------- 2 files changed, 16 insertions(+), 58 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 226f96f0dee0..b13c2442281f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -252,6 +252,7 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping, #define FGP_WRITE 0x00000008 #define FGP_NOFS 0x00000010 #define FGP_NOWAIT 0x00000020 +#define FGP_FOR_MMAP 0x00000040 struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, int fgp_flags, gfp_t cache_gfp_mask); diff --git a/mm/filemap.c b/mm/filemap.c index 81adec8ee02c..f068712c2525 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1503,6 +1503,9 @@ EXPORT_SYMBOL(find_lock_entry); * @gfp_mask and added to the page cache and the VM's LRU * list. The page is returned locked and with an increased * refcount. Otherwise, NULL is returned. + * - FGP_FOR_MMAP: Similar to FGP_CREAT, only it unlocks the page after it has + * added it to pagecache, as the mmap code expects to do it's own special + * locking dance. * * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even * if the GFP flags specified for FGP_CREAT are atomic. @@ -1555,7 +1558,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, if (!page) return NULL; - if (WARN_ON_ONCE(!(fgp_flags & FGP_LOCK))) + if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) fgp_flags |= FGP_LOCK; /* Init accessed so avoid atomic mark_page_accessed later */ @@ -1569,6 +1572,13 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, if (err == -EEXIST) goto repeat; } + + /* + * add_to_page_cache_lru lock's the page, and for mmap we expect + * a unlocked page. + */ + if (fgp_flags & FGP_FOR_MMAP) + unlock_page(page); } return page; @@ -2293,39 +2303,6 @@ generic_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) EXPORT_SYMBOL(generic_file_read_iter); #ifdef CONFIG_MMU -/** - * page_cache_read - adds requested page to the page cache if not already there - * @file: file to read - * @offset: page index - * @gfp_mask: memory allocation flags - * - * This adds the requested page to the page cache if it isn't already there, - * and schedules an I/O to read in its contents from disk. - */ -static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) -{ - struct address_space *mapping = file->f_mapping; - struct page *page; - int ret; - - do { - page = __page_cache_alloc(gfp_mask); - if (!page) - return -ENOMEM; - - ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask); - if (ret == 0) - ret = mapping->a_ops->readpage(file, page); - else if (ret == -EEXIST) - ret = 0; /* losing race to add is OK */ - - put_page(page); - - } while (ret == AOP_TRUNCATED_PAGE); - - return ret; -} - #define MMAP_LOTSAMISS (100) /* @@ -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); } if (!lock_page_or_retry(page, vmf->vma->vm_mm, vmf->flags)) { @@ -2488,28 +2467,6 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) vmf->page = page; return ret | VM_FAULT_LOCKED; -no_cached_page: - /* - * We're only likely to ever get here if MADV_RANDOM is in - * effect. - */ - error = page_cache_read(file, offset, vmf->gfp_mask); - - /* - * The page we want has now been added to the page cache. - * In the unlikely event that someone removed it in the - * meantime, we'll just come back here and read it again. - */ - if (error >= 0) - goto retry_find; - - /* - * An error return from page_cache_read can result if the - * system is low on memory, or a problem occurs while trying - * to schedule I/O. - */ - return vmf_error(error); - page_not_uptodate: /* * Umm, take care of errors if the page isn't up-to-date. -- 2.14.3