From patchwork Fri Nov 30 19:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10707083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7D1314BD for ; Fri, 30 Nov 2018 19:58:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAEB6304C9 for ; Fri, 30 Nov 2018 19:58:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EC1F304F5; Fri, 30 Nov 2018 19:58:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CCA4304C9 for ; Fri, 30 Nov 2018 19:58:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71CE96B59F0; Fri, 30 Nov 2018 14:58:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A7646B59F1; Fri, 30 Nov 2018 14:58:19 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FBF26B59F2; Fri, 30 Nov 2018 14:58:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) by kanga.kvack.org (Postfix) with ESMTP id 1DD686B59F0 for ; Fri, 30 Nov 2018 14:58:19 -0500 (EST) Received: by mail-yb1-f198.google.com with SMTP id f17-v6so4147569yba.15 for ; Fri, 30 Nov 2018 11:58:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:subject:date:message-id :in-reply-to:references; bh=tfQKrc5MaRoWXLgCC8cvo0W1La7ADJ1hTk4hFrcxJ2w=; b=NpSIT+Mq69zEu8G271zwbN04ehAnYEdrbsdoF/mwoSYTaaAWGhjS8OaI6nduQd3651 cGePlUhaLEfDqL0xsQzPeSpI3JCwrpG7zsvKVlFQh3rbcONTIBiv3hecYWhSpZ98A7id 1GKQiiDf3gG0eMhyJwiqknW+b8pccARnZNn1bGQ14ebjEPuEuZ2IvcC675Vhz94jYvNu S3VIoQeZ6XHxfLNBJM+dOPbm4HKc2EYxQAcM3OPk9+ZbB5ewBR23/CasSrFxtvw+v/qM 8JgBLk6Ya9eChI0XGCsIrk22nHnaxHswNTj8OAL3Tp4fms4xhAOGfEeY5X2l3zYSibQl K6sg== X-Gm-Message-State: AA+aEWbY7eHbyZQ+VuRIsRUUVmd18ySbP1qYbt/rJD6781J7vZVuMlDn aqSQ67isb2LzgBUVMxbfatPqxOJ0DTp2m5Z/Wm9Ny1EIfFRQVZ8ojiXn7QI0q5be2MY6qpIMhcS Fg3XMlNFOSx9mvfhQPwB9n6BXf6hTs/VAPMVf+wgI/o0jTJfxh5Fr6tVwAzFz8W2g537xSgQs/G wnUvd/FvH2MEw3B2EtJNMbsAYhK63GQ0L2QF5Xa2tdI85oMa64o6UeJCv2yg13X4M1XWivbkBLX kOYv7oAE1pUuXeo6CJPPHIVkL25bulkkZmc4c7okkk/pK51+tQKkO3h2Z9ETGujPNrBwYSc4gtj rFQl1xpa9a1nVoDyBJk4a0mbbV2W21k9eBwnV2YCd4Zd5Qg03OAfy3N/4xWCArHp8rc6A2iOlsY n X-Received: by 2002:a25:4457:: with SMTP id r84-v6mr6576203yba.192.1543607898855; Fri, 30 Nov 2018 11:58:18 -0800 (PST) X-Received: by 2002:a25:4457:: with SMTP id r84-v6mr6576173yba.192.1543607898042; Fri, 30 Nov 2018 11:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543607897; cv=none; d=google.com; s=arc-20160816; b=g/dJ+H3yCk26jAK76hagoPYcncqv6+9OgN5mIa0UEWRN0rKznk/n0l+nELC7SAa1Ma 5nlSYwUdL9N7QxMynvzH9Ch1pYBvdsRSfuzZN/dyDxdbWsloBSxylMg5LeGSRsJxKCzT DdZyy59XtszMICDZfXNEQn1HOEf2ubCQFnJb9VuJp6pJZidJIeN2WulnPH6r7EhfQd7L mWzjJ6B90MnfIHkGl/BZsdtAcO831Mz8m1iEyAjiBDyID/6xHLzVCe3v7wwtwErflRB0 SDugWtEF8FupjCvGfNMZXCadGjRLJqjn+L+8ni+R5Uh2amFU+YC4POdjCbLLY/U9qxhP aL/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=tfQKrc5MaRoWXLgCC8cvo0W1La7ADJ1hTk4hFrcxJ2w=; b=Kp8AtxfHqhPnxyCnNVb+26D6OcVNz3C6+uawVRVXQ79o2E+6EENS7n4qw41gVHI3bT 30IlKTFPyj+CiaMeRks44u/JmndvuzHyM7MJc5UaBCGKjs/E6gJWS5D9Ww+v6JM1Y70N dD3JYMljkzZXQxBu6kOt9Xb6ZmOwKObGmzRqwP5Vk7fek6++0IcWKWTUIplSEUVWEMB+ 7ho5iZFTm7wYA9NftoC8AauaQL13Curx+zj5cbLjRGPM/OWyllKqYv8x9dlyuSw9nFWS AnD1bZCWOMRix0g+eObbvlsqh+jRuOnR7dVf98QnvlxFtb15qYhiIviRBpEVwHUSI29u s6Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=RDqpS5N7; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) smtp.mailfrom=josef@toxicpanda.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m206-v6sor2621714ybb.36.2018.11.30.11.58.17 for (Google Transport Security); Fri, 30 Nov 2018 11:58:17 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=RDqpS5N7; spf=neutral (google.com: 209.85.220.65 is neither permitted nor denied by best guess record for domain of josef@toxicpanda.com) smtp.mailfrom=josef@toxicpanda.com 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-Smtp-Source: AFSGD/XWgCRVHDSF9Pe7/FTfBQjuZIj2paksVvKyVRtCwfnLtusXiVGu/hAx627t9t+3WpViWhH6Xw== 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> 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Johannes Weiner Reviewed-by: Jan Kara --- 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.