From patchwork Tue Dec 16 08:56:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 5499951 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E75AA9F1CD for ; Tue, 16 Dec 2014 08:56:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A95520A20 for ; Tue, 16 Dec 2014 08:56:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44C3020A1F for ; Tue, 16 Dec 2014 08:56:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750882AbaLPI4a (ORCPT ); Tue, 16 Dec 2014 03:56:30 -0500 Received: from mail-pd0-f171.google.com ([209.85.192.171]:51481 "EHLO mail-pd0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750809AbaLPI42 (ORCPT ); Tue, 16 Dec 2014 03:56:28 -0500 Received: by mail-pd0-f171.google.com with SMTP id y13so13554498pdi.30 for ; Tue, 16 Dec 2014 00:56:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=HKUVhfk87PoP+xbxBoxyH0sS/h1PZMCxiZ443TkPhQc=; b=d7V8+Y3Ywod8G2Oo5kOTyGlZI+DwE6J9DXhOJFVLZ80CzvOJhmmEjDnT/NSUsyP0iu KnL5EZEHjdligdPSKLZCLp8Z83zI1F3k8p5TszfdSUBDd7Bm/kCk8ydylxGGZCGFLMrk kPCjQfaKQDDNAm77LUgGYPvpTmrKsPacqKSGrijRSr+gHhzlFzOc2PtpG5M5WWUQtfwY HDGeMfYbuwT1jbdTa/o2JvY6Oyxc+9Z5YJPkh11tts2otEVZ7+Yh2zh/1mLpXqdkenuv 3I/L9uD8D4MNneAFj5A+uVonOu981XwhjOPLQS49e/ajp9xJfn5jey3LIqE6FtGReGns tkig== X-Gm-Message-State: ALoCoQlsZ0jcidRWx80Jw/YjoSkP5x1wvkP9X21A7TbgyZ622rIXWRsKmGkIKfOrqX3QJZ8Y3uj+ X-Received: by 10.68.225.193 with SMTP id rm1mr59258312pbc.77.1418720188330; Tue, 16 Dec 2014 00:56:28 -0800 (PST) Received: from mew ([72.192.100.38]) by mx.google.com with ESMTPSA id y7sm313435pdm.12.2014.12.16.00.56.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Dec 2014 00:56:27 -0800 (PST) Date: Tue, 16 Dec 2014 00:56:24 -0800 From: Omar Sandoval To: Christoph Hellwig Cc: Jan Kara , Alexander Viro , Andrew Morton , Trond Myklebust , David Sterba , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/8] swap: lock i_mutex for swap_writepage direct_IO Message-ID: <20141216085624.GA25256@mew> References: <20141215162705.GA23887@quack.suse.cz> <20141215165615.GA19041@infradead.org> <20141215221100.GA4637@mew> <20141216083543.GA32425@infradead.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141216083543.GA32425@infradead.org> User-Agent: Mutt/1.5.23 (2014-03-12) 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=ham 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 On Tue, Dec 16, 2014 at 12:35:43AM -0800, Christoph Hellwig wrote: > On Mon, Dec 15, 2014 at 02:11:00PM -0800, Omar Sandoval wrote: > > Ok, I got the swap code working with ->read_iter/->write_iter without > > too much trouble. I wanted to double check before I submit if there's > > any gotchas involved with adding the O_DIRECT flag to a file pointer > > after it has been opened -- swapon opens the swapfile before we know if > > we're using the SWP_FILE infrastructure, and we need to add O_DIRECT so > > ->{read,write}_iter use direct I/O, but we can't add O_DIRECT to the > > original open without excluding filesystems that support the old bmap > > path but not direct I/O. > > In general just adding O_DIRECT is a problem. However given that the > swap file is locked against any other access while in use it seems ok > in this particular case. Just make sure to clear it on swapoff, and > write a detailed comment explaining the situation. I'll admit that I'm a bit confused. I want to do this: This seems to be more or less equivalent to doing a fcntl(F_SETFL) to add the O_DIRECT flag to swap_file (which is a struct file *). Swapoff calls filp_close on swap_file, so I don't see why it's necessary to clear the flag. diff --git a/mm/swapfile.c b/mm/swapfile.c index 8798b2e..5145c09 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1728,6 +1728,9 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span) } if (mapping->a_ops->swap_activate) { + if (!mapping->a_ops->direct_IO) + return -EINVAL; + swap_file->f_flags |= O_DIRECT; ret = mapping->a_ops->swap_activate(sis, swap_file, span); if (!ret) { sis->flags |= SWP_FILE;