From patchwork Mon Dec 12 22:32:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Patlasov X-Patchwork-Id: 9471609 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 DBC32607EE for ; Tue, 13 Dec 2016 00:06:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C059A2852F for ; Tue, 13 Dec 2016 00:06:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B258328535; Tue, 13 Dec 2016 00:06:12 +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 A69532852F for ; Tue, 13 Dec 2016 00:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752801AbcLMAGH (ORCPT ); Mon, 12 Dec 2016 19:06:07 -0500 Received: from mail-ve1eur01on0110.outbound.protection.outlook.com ([104.47.1.110]:2560 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751465AbcLMAGG (ORCPT ); Mon, 12 Dec 2016 19:06:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SSCjn0caBFCTPOGXaoLSD2KV7tnipjZkl168N6ZlFyM=; b=QVjArGJY8d/L6vyTgbOX3JiCMMKwGCul2bkfKLwJohcHp3AHRGgS8bj0LRlXSYCqbBjhieymRyg/fC/kIPi9KACTiwcdjdjyHujyxT3xXlGn5p3M9OBYS4QoaX8+bhUxF9dn8SVLhA1AVliIE/rgsONZWztt7pqDOvCg1NSG134= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=MPatlasov@virtuozzo.com; Received: from [192.168.0.106] (73.53.48.178) by DB6PR0801MB1848.eurprd08.prod.outlook.com (10.169.227.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Mon, 12 Dec 2016 22:32:57 +0000 Subject: [PATCH v2] btrfs: limit async_work allocation and worker func duration From: Maxim Patlasov To: CC: , , , , Date: Mon, 12 Dec 2016 14:32:44 -0800 Message-ID: <148158188817.14549.6890368240319389582.stgit@maxim-thinkpad> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [73.53.48.178] X-ClientProxiedBy: BY1PR18CA0024.namprd18.prod.outlook.com (10.162.126.34) To DB6PR0801MB1848.eurprd08.prod.outlook.com (10.169.227.146) X-MS-Office365-Filtering-Correlation-Id: eb13b156-6d2c-42be-e1a3-08d422ded3a5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB6PR0801MB1848; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1848; 3:lttlYs59dBFzYDOCh7+z5skccKmFoar4hQk702z0LF8DyXz7AKQbpZkBCd7INfCQYLqf+QhT6AIkYGrOh8H243eEE06cy01Q7Gosk3LQjrIspKhhMBhtWO1/YRc7Yqlh12Jpr1mFwtL5tufZa1JY7cW2zZBVnhIe8HrlVPzO1c52BlDChu/Biqcv1SBpEb3JC6EGE0lrCUHBUesCeQmXOSjXyIoKNrMBQvilpAmTIilpA/gIeKsm+MK9EFWzVxlQJvAIuKsuB5WODJ1ekAl/pg== X-Microsoft-Exchange-Diagnostics: 1; D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q0egShKWavLQGL6e4jj; 20:IPrVcWdrfXo+e6ndbhsAc7CcBJx+zZ5Tbq4WzjrUjLXtqJGxtk6TAjD4XnZG7ji5pq2mePAArjrUU4JU1U2R/y6uCawx91QLUy/l36ssKU675sqLvQUlvhTLnkdm/HlhIZrzuO2Bpr2o0OIXjpA3ECTKD13gUp1B/PY4oqRS3UIpXbHkXJn4JcCNNcMcziVznF7K5484exz55zlJoIUEdIWvmltAHt0p/GbT+jbpYYtoUhQsSYTbFOYRB/1jXGkD X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(6072148); SRVR:DB6PR0801MB1848; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1848; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1848; 4:JUQIygBjaGj2tX3S3GMYA/6uTpOoW24zSAPvR8/+SLWC13z3dFuE4Inz1/ochym/pjk8RMJYkngXGPsl+idniWcZ3OFBtH7GW6xd4PLGZYso4e2bPEWeFBttbcUvJk5TuaTLqR0orFTfpH74ARMzRgeKWG3SAvix9z5SDrEI78Acp955ljgvObbzTVhUAMZwShDTUKIGSoQLC7iYglBnCDnOAZOGXfmxffmj3dHKqi0MVECZC64uiGinsiZgmquIQ7dBZ1fhO4h9CkFIcf7WG9jT3hYCgcMF0j7k2Q+1KhrHW0oX5VDYwLt3lUpjBziH3BA4x98m3UOcjUYg23kb9wAj6CA+SfG3lPIwSauTnt3sgzk5iggv0Aeh6vCIM+5lx276BkzMQtSiXWLuwbIKQIoPF54FYkzXWzYKSfb8gYvZXOfF5VG9/Hg+NdGA88kz4MCBIVKvadnqqhw3rhqc3tE11FQ4epmwgtv2/UJtT6zBUUUiZ98z3QYwGqrpsrYwJQkVylN4pMJcmxrYlDhwDv3kCxfeDPTkFDR5v7I6yspi+VZA8PSTbjeCmI01c1uX/gs0WEbxjRuZlNa0striEg== X-Forefront-PRVS: 0154C61618 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6049001)(7916002)(39450400003)(199003)(189002)(7736002)(6486002)(50466002)(23676002)(107886002)(305945005)(4001350100001)(4326007)(4001430100002)(103116003)(68736007)(66066001)(81166006)(81156014)(189998001)(47776003)(3846002)(8676002)(86362001)(83506001)(575784001)(90366009)(33646002)(38730400001)(117156001)(2351001)(42186005)(230700001)(33716001)(9686002)(110136003)(101416001)(54356999)(5660300001)(106356001)(50986999)(92566002)(6116002)(77096006)(105586002)(6666003)(6916009)(2906002)(97736004)(80792005); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1848; H:[192.168.0.106]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDFNQjE4NDg7MjM6RTlnSW11WlRTZERKdklINWFueXFJaWdp?= =?utf-8?B?VGRvYlZIR3BOQ0VEeTc4cmhJV0pkRkxHNmp2eGxaYXVIL1BUVHlXVWJCQ0lB?= =?utf-8?B?MXo0SytyeXFUZ2YyWlQ0RENOSnoxVW4xUDRnOXF4c0Y1Y0dqdmR4c3VPK3Rw?= =?utf-8?B?bnJ0MDBZWWU4eG5MVm42ZDJubkk1SlBFM08xWjJyZEJOOFkxVldYVG14THdK?= =?utf-8?B?cW1IR0VYL2RCNjhoOUdRcnJuUjQ2WGszcTduNjR3YzNtVWMwRnJiTVhocGto?= =?utf-8?B?ZG5oNkZ2MjNmZkxRV2NrMFR5VHB6ZHQ2SDlpbUwwQk14R0ZRV0t3blBvWUEy?= =?utf-8?B?Zy8yYmJTdDgvUGdQVCtseEZJbmlyZ0p4cGpYam8wR015QWN2N1BkOXZCV2lv?= =?utf-8?B?cXdXb1lxd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7VE+o59cf7Yig==; 24:dFAHCaFG+srKQXdNL/MOdTga+cdEL7pxWTxa8kj/jwJ9H37oQyDbqpKUamITT1X5t1P8juQtc9aa2xNZw8sDSuBs7vfQ7QO3NOp068mM2sk= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1848; 7:Mw66cR9YvKWo8R9z+Bcmekfm1gdHYtpJKAXOvdi7kVks1ZSXvYtRqvpwU8/SkI1rdzbGqM7PedHi+F2hRinBBDBAgXuS288umrtLk48L9J3Nooan+CXXqHDo0YutZ+MsJFIPcFh44YJ3HwZsNS1thR5vEW3VVN9jyhVxlKW8SbauJ6qy6WgfpZGlJtAbUwG1SqY7GhrvHxRM3jFn+Ae0pWXR2LzW7GFGA6Y+0SsvTDqhmqrs8VayoAs00eVh+z64IcnniMCwdpX627wE/e1e81enGMPQnQVahN+46nGnh2W9epWXHPqjYwdCo3otnbhe++IambO4DkZGCBC2Je+lwW+hNceiLCCwl3hHS/CTmR/M9o0aX/zz7D6cRMoOtUTT/eWloCziukTEjE5964xCAMXYLVGeCZphNqsU6LAxEWUHoFxaEQm0pPM8aVI4bTgU2uCPiDxXGFO6OpIrVnxeBg==; 20:qucLtFYJAO5QPe5TQ5JVuc0L0qt1MiOOhYyafKHnc59dZeO4tgcqEFmyKVCFcJUaltVkG0Ps1gEBomJW74fHHzOfAr1+mKHWIoAwkanmV0+CaNyBCR8XEPbiW2RgZ7nC+YPK6cioptB89m3wkrlTsP78WdoTd3XcgCLzsO/PwGw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2016 22:32:57.3262 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1848 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Problem statement: unprivileged user who has read-write access to more than one btrfs subvolume may easily consume all kernel memory (eventually triggering oom-killer). Reproducer (./mkrmdir below essentially loops over mkdir/rmdir): [root@kteam1 ~]# cat prep.sh DEV=/dev/sdb mkfs.btrfs -f $DEV mount $DEV /mnt for i in `seq 1 16` do mkdir /mnt/$i btrfs subvolume create /mnt/SV_$i ID=`btrfs subvolume list /mnt |grep "SV_$i$" |cut -d ' ' -f 2` mount -t btrfs -o subvolid=$ID $DEV /mnt/$i chmod a+rwx /mnt/$i done [root@kteam1 ~]# sh prep.sh [maxim@kteam1 ~]$ for i in `seq 1 16`; do ./mkrmdir /mnt/$i 2000 2000 & done [root@kteam1 ~]# for i in `seq 1 4`; do grep "kmalloc-128" /proc/slabinfo | grep -v dma; sleep 60; done kmalloc-128 10144 10144 128 32 1 : tunables 0 0 0 : slabdata 317 317 0 kmalloc-128 9992352 9992352 128 32 1 : tunables 0 0 0 : slabdata 312261 312261 0 kmalloc-128 24226752 24226752 128 32 1 : tunables 0 0 0 : slabdata 757086 757086 0 kmalloc-128 42754240 42754240 128 32 1 : tunables 0 0 0 : slabdata 1336070 1336070 0 The huge numbers above come from insane number of async_work-s allocated and queued by btrfs_wq_run_delayed_node. The problem is caused by btrfs_wq_run_delayed_node() queuing more and more works if the number of delayed items is above BTRFS_DELAYED_BACKGROUND. The worker func (btrfs_async_run_delayed_root) processes at least BTRFS_DELAYED_BATCH items (if they are present in the list). So, the machinery works as expected while the list is almost empty. As soon as it is getting bigger, worker func starts to process more than one item at a time, it takes longer, and the chances to have async_works queued more than needed is getting higher. The problem above is worsened by another flaw of delayed-inode implementation: if async_work was queued in a throttling branch (number of items >= BTRFS_DELAYED_WRITEBACK), corresponding worker func won't quit until the number of items < BTRFS_DELAYED_BACKGROUND / 2. So, it is possible that the func occupies CPU infinitely (up to 30sec in my experiments): while the func is trying to drain the list, the user activity may add more and more items to the list. The patch fixes both problems in straightforward way: refuse queuing too many works in btrfs_wq_run_delayed_node and bail out of worker func if at least BTRFS_DELAYED_WRITEBACK items are processed. Changed in v2: remove support of thresh == NO_THRESHOLD. Signed-off-by: Maxim Patlasov --- fs/btrfs/async-thread.c | 14 ++++++++++++++ fs/btrfs/async-thread.h | 1 + fs/btrfs/delayed-inode.c | 6 ++++-- 3 files changed, 19 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c index e0f071f..63d1977 100644 --- a/fs/btrfs/async-thread.c +++ b/fs/btrfs/async-thread.c @@ -86,6 +86,20 @@ btrfs_work_owner(struct btrfs_work *work) return work->wq->fs_info; } +bool btrfs_workqueue_normal_congested(struct btrfs_workqueue *wq) +{ + /* + * We could compare wq->normal->pending with num_online_cpus() + * to support "thresh == NO_THRESHOLD" case, but it requires + * moving up atomic_inc/dec in thresh_queue/exec_hook. Let's + * postpone it until someone needs the support of that case. + */ + if (wq->normal->thresh == NO_THRESHOLD) + return false; + + return atomic_read(&wq->normal->pending) > wq->normal->thresh * 2; +} + BTRFS_WORK_HELPER(worker_helper); BTRFS_WORK_HELPER(delalloc_helper); BTRFS_WORK_HELPER(flush_delalloc_helper); diff --git a/fs/btrfs/async-thread.h b/fs/btrfs/async-thread.h index 8e52484..1f95973 100644 --- a/fs/btrfs/async-thread.h +++ b/fs/btrfs/async-thread.h @@ -84,4 +84,5 @@ void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max); void btrfs_set_work_high_priority(struct btrfs_work *work); struct btrfs_fs_info *btrfs_work_owner(struct btrfs_work *work); struct btrfs_fs_info *btrfs_workqueue_owner(struct __btrfs_workqueue *wq); +bool btrfs_workqueue_normal_congested(struct btrfs_workqueue *wq); #endif diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 3eeb9cd..de946dd 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c @@ -1356,7 +1356,8 @@ release_path: total_done++; btrfs_release_prepared_delayed_node(delayed_node); - if (async_work->nr == 0 || total_done < async_work->nr) + if ((async_work->nr == 0 && total_done < BTRFS_DELAYED_WRITEBACK) || + total_done < async_work->nr) goto again; free_path: @@ -1372,7 +1373,8 @@ static int btrfs_wq_run_delayed_node(struct btrfs_delayed_root *delayed_root, { struct btrfs_async_delayed_work *async_work; - if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND) + if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND || + btrfs_workqueue_normal_congested(fs_info->delayed_workers)) return 0; async_work = kmalloc(sizeof(*async_work), GFP_NOFS);