From patchwork Mon Sep 25 19:44:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Wareing X-Patchwork-Id: 9970409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 589B860365 for ; Mon, 25 Sep 2017 19:44:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AFC328D5A for ; Mon, 25 Sep 2017 19:44:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F8B028D60; Mon, 25 Sep 2017 19:44:24 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC74C28D59 for ; Mon, 25 Sep 2017 19:44:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934790AbdIYToW (ORCPT ); Mon, 25 Sep 2017 15:44:22 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:34295 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934464AbdIYToV (ORCPT ); Mon, 25 Sep 2017 15:44:21 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.21/8.16.0.21) with SMTP id v8PJfdbY018546 for ; Mon, 25 Sep 2017 12:44:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=HRdgGj1o5FQ1Q4h+jc0/zlIeRXAAM0ZtHTjhwANWmmo=; b=L6V22Nm8H6nQIYEwg1i0lcxqkHB9pH0b6+rb7DjK1/T9EpCtNIRD/yrMd7C2WJZAWlTh oBqSmNX08PFyYNROs9HXOromgR3+NhADZSsz0Gggf6Bul7mLgvsLUzNEnWfpLpb99xnq GX1hAvpz2nriqQGiFXGGATIjU/IZMU0VFx8= Received: from mail.thefacebook.com ([199.201.64.23]) by m0001303.ppops.net with ESMTP id 2d77gd85qa-2 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 25 Sep 2017 12:44:20 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB09.TheFacebook.com (192.168.16.19) with Microsoft SMTP Server id 14.3.319.2; Mon, 25 Sep 2017 12:44:20 -0700 Received: from devbig279.prn1.facebook.com (localhost [127.0.0.1]) by devbig279.prn1.facebook.com (Postfix) with ESMTP id AF7EE3620DDF; Mon, 25 Sep 2017 12:44:19 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Richard Wareing Smtp-Origin-Hostname: devbig279.prn1.facebook.com To: CC: , , Smtp-Origin-Cluster: prn1c29 Subject: [PATCH v5 3/3] xfs: Add realtime fallback if data device full Date: Mon, 25 Sep 2017 12:44:18 -0700 Message-ID: <20170925194418.720146-4-rwareing@fb.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170925194418.720146-1-rwareing@fb.com> References: <20170925194418.720146-1-rwareing@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-09-25_07:, , signatures=0 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - For FSes which have a realtime device configured, rt_fallback_pct forces allocations to the realtime device after data device usage reaches rt_fallback_pct. - Useful for realtime device users to help prevent ENOSPC errors when selectively storing some files (e.g. small files) on data device, while others are stored on realtime block device. - Set via the "rt_fallback_pct" sysfs value which is available if the kernel is compiled with CONFIG_XFS_RT. Signed-off-by: Richard Wareing --- Changes since v4: * Refactored to align with xfs_inode_select_target change * Fallback percentage reworked to trigger on % space used on data device. I find this a bit more intuitive as it aligns well with "df" output. * mp->m_rt_min_fdblocks now assigned via function call * Better consistency on sysfs options Changes since v3: * None, new patch to patch set fs/xfs/xfs_fsops.c | 2 ++ fs/xfs/xfs_mount.c | 24 ++++++++++++++++++++++++ fs/xfs/xfs_mount.h | 8 ++++++++ fs/xfs/xfs_rtalloc.c | 32 ++++++++++++++++++++++++++++++++ fs/xfs/xfs_sysfs.c | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 6ccaae9..80ccb14 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -610,6 +610,8 @@ xfs_growfs_data_private( xfs_set_low_space_thresholds(mp); mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); + mp->m_rt_min_free_dblocks = xfs_rt_calc_min_free_dblocks(mp); + /* * If we expanded the last AG, free the per-AG reservation * so we can reinitialize it with the new size. diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 2eaf818..e8bae5e 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1396,3 +1396,27 @@ xfs_dev_is_read_only( } return 0; } + +/* + * precalculate minimum of data blocks required, if we fall + * below this value, we will fallback to the real-time device. + * + * m_rt_fallback_pct can only be non-zero if a real-time device + * is configured. + */ +uint64_t +xfs_rt_calc_min_free_dblocks( + struct xfs_mount *mp) +{ + uint64_t min_free_dblocks = 0; + + if (!XFS_IS_REALTIME_MOUNT(mp)) + return 0; + + /* Pre-compute minimum data blocks required before + * falling back to RT device for allocations + */ + min_free_dblocks = mp->m_sb.sb_dblocks * (100 - mp->m_rt_fallback_pct); + do_div(min_free_dblocks, 100); + return min_free_dblocks; +} diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 2adc701..74dcdc3 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -198,6 +198,13 @@ typedef struct xfs_mount { bool m_fail_unmount; uint m_rt_alloc_min; /* Min RT allocation */ + uint32_t m_rt_fallback_pct; /* Fallback to realtime device if data + * device usage above rt_fallback_pct + */ + uint64_t m_rt_min_free_dblocks; /* Use realtime device if free data + * device blocks falls below this; + * computed from m_rt_fallback_pct. + */ #ifdef DEBUG /* * DEBUG mode instrumentation to test and/or trigger delayed allocation @@ -463,4 +470,5 @@ int xfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb, struct xfs_error_cfg * xfs_error_get_cfg(struct xfs_mount *mp, int error_class, int error); +uint64_t xfs_rt_calc_min_free_dblocks(struct xfs_mount *mp); #endif /* __XFS_MOUNT_H__ */ diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 421f860..c197b95 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1305,6 +1305,35 @@ void xfs_rt_alloc_min( } /* + * m_rt_min_free_dblocks is a pre-computed threshold, which controls target + * selection based on how many free blocks are available on the data device. + * + * If the number of free data device blocks falls below + * mp->m_rt_min_free_dblocks, the realtime device is selected as the target + * device. If this value is not set, this target policy is in-active. + * + */ +void xfs_rt_min_free_dblocks( + struct xfs_mount *mp, + struct xfs_inode *ip, + xfs_off_t len) +{ + /* Disabled */ + if (!mp->m_rt_fallback_pct) + return; + + /* If inode target is already realtime device, nothing to do here */ + if(!XFS_IS_REALTIME_INODE(ip)) { + uint64_t free_dblocks; + free_dblocks = percpu_counter_sum(&mp->m_fdblocks) - + mp->m_alloc_set_aside; + if (free_dblocks < mp->m_rt_min_free_dblocks) { + ip->i_d.di_flags |= XFS_DIFLAG_REALTIME; + } + } +} + +/* * Select the target device for the inode based on either the size of the * initial allocation, or the amount of space available on the data device. * @@ -1333,4 +1362,7 @@ void xfs_inode_select_target( * not valid if not set. */ xfs_rt_alloc_min(mp, ip, len); + + /* Select target based on remaining free blocks on data device */ + xfs_rt_min_free_dblocks(mp, ip, len); } diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c index 1e202a1..889b006 100644 --- a/fs/xfs/xfs_sysfs.c +++ b/fs/xfs/xfs_sysfs.c @@ -166,11 +166,49 @@ rt_alloc_min_show( } XFS_SYSFS_ATTR_RW(rt_alloc_min); +STATIC ssize_t +rt_fallback_pct_store( + struct kobject *kobject, + const char *buf, + size_t count) +{ + struct xfs_mount *mp = to_mp(kobject); + int ret; + int val; + + ret = kstrtoint(buf, 0, &val); + if (ret) + return ret; + + if (!XFS_IS_REALTIME_MOUNT(mp)) + return -EINVAL; + + if (val < 0) + return -EINVAL; + + /* Only valid if using a real-time device */ + mp->m_rt_fallback_pct = val; + mp->m_rt_min_free_dblocks = xfs_rt_calc_min_free_dblocks(mp); + return count; +} + +STATIC ssize_t +rt_fallback_pct_show( + struct kobject *kobject, + char *buf) +{ + struct xfs_mount *mp = to_mp(kobject); + + return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_rt_fallback_pct); +} +XFS_SYSFS_ATTR_RW(rt_fallback_pct); + static struct attribute *xfs_mp_attrs[] = { #ifdef DEBUG ATTR_LIST(drop_writes), #endif ATTR_LIST(rt_alloc_min), + ATTR_LIST(rt_fallback_pct), NULL, };