From patchwork Tue Mar 24 15:26:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 6080671 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5A4A8BF90F for ; Tue, 24 Mar 2015 15:30:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EE95201EC for ; Tue, 24 Mar 2015 15:30:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63128201FE for ; Tue, 24 Mar 2015 15:30:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753380AbbCXP3l (ORCPT ); Tue, 24 Mar 2015 11:29:41 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:16911 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753006AbbCXP1L (ORCPT ); Tue, 24 Mar 2015 11:27:11 -0400 Received: from pps.filterd (m0004346 [127.0.0.1]) by mx0a-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t2OEtWXA020332; Tue, 24 Mar 2015 08:27:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=1KW4N+ucmuEM0CniF/u+5UHSCIgn/PTBQ+4R99ZorDY=; b=rcsVtJ42Pu17i9sPN1Z5aglVBfEotHqsAkuoKcTuj3xZjnQUt8Nq35Xd52AC7TMXRHlS +cAd3LhJoReL8reNGmn1p0R8Ibu0tioAIXuKvbGBZNDe9qsfN6D1pfFFif8dMplI45yb 2NpEIlQaK6fqIBjjYDeEqlE16xJzPfbpNJ4= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 1tb6qb8c8x-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 24 Mar 2015 08:27:09 -0700 Received: from localhost.localdomain (192.168.54.13) by mail.thefacebook.com (192.168.16.23) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 24 Mar 2015 08:27:07 -0700 From: Jens Axboe To: , , CC: , Jens Axboe Subject: [PATCH 2/6] Add support for per-file stream ID Date: Tue, 24 Mar 2015 09:26:59 -0600 Message-ID: <1427210823-5283-3-git-send-email-axboe@fb.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427210823-5283-1-git-send-email-axboe@fb.com> References: <1427210823-5283-1-git-send-email-axboe@fb.com> MIME-Version: 1.0 X-Originating-IP: [192.168.54.13] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.13.68, 1.0.33, 0.0.0000 definitions=2015-03-24_04:2015-03-24, 2015-03-24, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 kscore.is_bulkscore=0 kscore.compositescore=0 circleOfTrustscore=0 compositescore=0.925924926977281 suspectscore=0 recipient_domain_to_sender_totalscore=0 phishscore=0 bulkscore=0 kscore.is_spamscore=0 rbsscore=0.925924926977281 recipient_to_sender_totalscore=0 recipient_domain_to_sender_domain_totalscore=0 spamscore=0 recipient_to_sender_domain_totalscore=0 urlsuspectscore=0.925924926977281 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1503240151 X-FB-Internal: deliver Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,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 Writing on flash devices can be much more efficient, if we can inform the device what kind of data can be grouped together. If the device is able to group data together with similar lifetimes, then it can be more efficient in garbage collection. This, in turn, leads to lower write amplification, which is a win on both device wear and performance. Add a new fadvise hint, POSIX_FADV_STREAMID, which sets the file and inode streamid. The file streamid is used if we have the file available at the time of the write (O_DIRECT), we use the inode streamid if not (buffered writeback). The fadvise hint uses the 'offset' field to specify a stream ID. Signed-off-by: Jens Axboe --- fs/inode.c | 1 + fs/open.c | 1 + include/linux/fs.h | 11 +++++++++++ include/uapi/linux/fadvise.h | 2 ++ mm/fadvise.c | 17 +++++++++++++++++ 5 files changed, 32 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index f00b16f45507..41885322ba64 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -149,6 +149,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_blocks = 0; inode->i_bytes = 0; inode->i_generation = 0; + inode->i_streamid = 0; inode->i_pipe = NULL; inode->i_bdev = NULL; inode->i_cdev = NULL; diff --git a/fs/open.c b/fs/open.c index 33f9cbf2610b..4a9b2be1a674 100644 --- a/fs/open.c +++ b/fs/open.c @@ -743,6 +743,7 @@ static int do_dentry_open(struct file *f, f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); + f->f_streamid = 0; return 0; diff --git a/include/linux/fs.h b/include/linux/fs.h index b4d71b5e1ff2..6288d9680af6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -631,6 +631,7 @@ struct inode { }; __u32 i_generation; + unsigned int i_streamid; #ifdef CONFIG_FSNOTIFY __u32 i_fsnotify_mask; /* all events this inode cares about */ @@ -640,6 +641,14 @@ struct inode { void *i_private; /* fs or device private pointer */ }; +static inline unsigned int inode_streamid(struct inode *inode) +{ + if (inode) + return inode->i_streamid; + + return 0; +} + static inline int inode_unhashed(struct inode *inode) { return hlist_unhashed(&inode->i_hash); @@ -820,6 +829,8 @@ struct file { const struct cred *f_cred; struct file_ra_state f_ra; + unsigned int f_streamid; + u64 f_version; #ifdef CONFIG_SECURITY void *f_security; diff --git a/include/uapi/linux/fadvise.h b/include/uapi/linux/fadvise.h index e8e747139b9a..3dc8a1ff1422 100644 --- a/include/uapi/linux/fadvise.h +++ b/include/uapi/linux/fadvise.h @@ -18,4 +18,6 @@ #define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */ #endif +#define POSIX_FADV_STREAMID 8 /* associate stream ID with file */ + #endif /* FADVISE_H_INCLUDED */ diff --git a/mm/fadvise.c b/mm/fadvise.c index 4a3907cf79f8..b111a8899fb7 100644 --- a/mm/fadvise.c +++ b/mm/fadvise.c @@ -60,6 +60,7 @@ SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice) case POSIX_FADV_WILLNEED: case POSIX_FADV_NOREUSE: case POSIX_FADV_DONTNEED: + case POSIX_FADV_STREAMID: /* no bad return value, but ignore advice */ break; default: @@ -144,6 +145,22 @@ SYSCALL_DEFINE4(fadvise64_64, int, fd, loff_t, offset, loff_t, len, int, advice) } } break; + case POSIX_FADV_STREAMID: + /* + * streamid is stored in offset... we don't limit or check + * if the device supports streams, or if it does, if the + * stream nr is within the limits. 1 is the lowest valid + * stream id, 0 is "don't care/know". + */ + if (offset != (unsigned int) offset) + ret = EINVAL; + else { + f.file->f_streamid = offset; + spin_lock(&inode->i_lock); + inode->i_streamid = offset; + spin_unlock(&inode->i_lock); + } + break; default: ret = -EINVAL; }