From patchwork Sat Dec 20 03:18:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5521911 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BB163BEEA8 for ; Sat, 20 Dec 2014 03:19:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D36A320154 for ; Sat, 20 Dec 2014 03:19:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6E4532014A for ; Sat, 20 Dec 2014 03:19:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752817AbaLTDS5 (ORCPT ); Fri, 19 Dec 2014 22:18:57 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:37140 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752757AbaLTDSt (ORCPT ); Fri, 19 Dec 2014 22:18:49 -0500 Received: by mail-pa0-f46.google.com with SMTP id lf10so2364942pab.19 for ; Fri, 19 Dec 2014 19:18:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=neePDmLY2ndAo31K3yWzNJLSSuAL7oO9OSLqoxGzslI=; b=TAGCXFd0Eg5wyv77SbKB5SG4FjKY7OXff/CY7J6FXBdthsLQVd442tlyrnOLW5b5ih a5he+dBAAhOHJoVs7ACOejmUJLizmd7PcjkmJCUMqknYi6ndjb/ZM7aPEG2pcehaCu68 BcEKnVDCNXNnivlc3FBsHbepHnykUIbRaeTc0Y7e45rXHYr+aU9Ek2j+7XCB84NRlC/A Kzue6y9y1vEIJ1i+O26qgDX3LV5X+e79BGTVBfG3lY6RZ6fMTp14cPCC9ycBvl9lh7T1 gf9OnpkWClylGaISed2fkIYj0L0mKYmgcWR/PMaWTDaZc5J2UEZbn6CFuJuEF1gOyEyf 8Lnw== X-Gm-Message-State: ALoCoQkmjSeX+VHX//qqe9aPH7p8Xy4HicyxKcBo7MIGLHmqzUQK3kz4QHCiFdi98KS9B47B5A16 X-Received: by 10.70.90.209 with SMTP id by17mr17525376pdb.162.1419045529236; Fri, 19 Dec 2014 19:18:49 -0800 (PST) Received: from mew.localdomain ([72.192.100.38]) by mx.google.com with ESMTPSA id uq15sm10972638pab.8.2014.12.19.19.18.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Dec 2014 19:18:48 -0800 (PST) From: Omar Sandoval To: Alexander Viro , Andrew Morton , Trond Myklebust , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Omar Sandoval , Mel Gorman Subject: [PATCH v2 4/5] swapfile: use ->read_iter and ->write_iter Date: Fri, 19 Dec 2014 19:18:28 -0800 Message-Id: X-Mailer: git-send-email 2.2.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Using ->direct_IO and ->readpage for the generic swap file infrastructure requires all sorts of nasty workarounds. ->readpage implementations don't play nicely with swap cache pages, and ->direct_IO implementations have different locking conventions for every filesystem. Instead, use ->read_iter/->write_iter with an ITER_BVEC and let the filesystem take care of it. This will also allow us to easily transition to kernel AIO if that gets merged in the future. Cc: Mel Gorman Signed-off-by: Omar Sandoval --- mm/page_io.c | 30 +++++++++++++++++++++++------- mm/swapfile.c | 11 ++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/mm/page_io.c b/mm/page_io.c index 532a39b..61165b0 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -263,7 +263,6 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, if (sis->flags & SWP_FILE) { struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; struct iov_iter from; struct bio_vec bv = { .bv_page = page, @@ -279,9 +278,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc, set_page_writeback(page); unlock_page(page); - ret = mapping->a_ops->direct_IO(ITER_BVEC | WRITE, - &kiocb, &from, - kiocb.ki_pos); + ret = swap_file->f_op->write_iter(&kiocb, &from); if (ret == PAGE_SIZE) { count_vm_event(PSWPOUT); ret = 0; @@ -344,12 +341,31 @@ int swap_readpage(struct page *page) } if (sis->flags & SWP_FILE) { + struct kiocb kiocb; struct file *swap_file = sis->swap_file; - struct address_space *mapping = swap_file->f_mapping; + struct iov_iter to; + struct bio_vec bv = { + .bv_page = page, + .bv_len = PAGE_SIZE, + .bv_offset = 0, + }; + + iov_iter_bvec(&to, ITER_BVEC | READ, &bv, 1, PAGE_SIZE); + + init_sync_kiocb(&kiocb, swap_file); + kiocb.ki_pos = page_file_offset(page); + kiocb.ki_nbytes = PAGE_SIZE; - ret = mapping->a_ops->readpage(swap_file, page); - if (!ret) + ret = swap_file->f_op->read_iter(&kiocb, &to); + if (ret == PAGE_SIZE) { + SetPageUptodate(page); count_vm_event(PSWPIN); + ret = 0; + } else { + ClearPageUptodate(page); + SetPageError(page); + } + unlock_page(page); return ret; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 63f55cc..4e14122 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2379,7 +2379,16 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) name = NULL; goto bad_swap; } - swap_file = file_open_name(name, O_RDWR|O_LARGEFILE, 0); + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE | O_DIRECT, 0); + if (swap_file == ERR_PTR(-EINVAL)) { + /* + * XXX: there are several filesystems that implement ->bmap but + * not ->direct_IO. It's unlikely that anyone is using a + * swapfile on, e.g., the MINIX fs, but this kludge will keep us + * from getting a complaint from the one person who does. + */ + swap_file = file_open_name(name, O_RDWR | O_LARGEFILE, 0); + } if (IS_ERR(swap_file)) { error = PTR_ERR(swap_file); swap_file = NULL;