From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2731CA9EB9 for ; Sat, 26 Oct 2019 10:47:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 41C0A20863 for ; Sat, 26 Oct 2019 10:47:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41C0A20863 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 957726B0003; Sat, 26 Oct 2019 06:47:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E1106B0005; Sat, 26 Oct 2019 06:47:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F67C6B0006; Sat, 26 Oct 2019 06:47:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 581706B0003 for ; Sat, 26 Oct 2019 06:47:11 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id DE0EA6D6E for ; Sat, 26 Oct 2019 10:47:10 +0000 (UTC) X-FDA: 76085608620.16.roof57_78ab98741aa4d X-HE-Tag: roof57_78ab98741aa4d X-Filterd-Recvd-Size: 5991 Received: from mail3-164.sinamail.sina.com.cn (mail3-164.sinamail.sina.com.cn [202.108.3.164]) by imf50.hostedemail.com (Postfix) with SMTP for ; Sat, 26 Oct 2019 10:47:08 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([222.131.69.34]) by sina.com with ESMTP id 5DB4242800007A18; Sat, 26 Oct 2019 18:47:06 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 46429715073849 From: Hillf Danton To: linux-mm Cc: fsdev , Andrew Morton , linux-kernel , Fengguang Wu , Tejun Heo , Jan Kara , Johannes Weiner , Shakeel Butt , Minchan Kim , Mel Gorman , Hillf Danton Subject: [RFC v2] writeback: add elastic bdi in cgwb bdp Date: Sat, 26 Oct 2019 18:46:56 +0800 Message-Id: <20191026104656.15176-1-hdanton@sina.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The elastic bdi is the mirror bdi of spinning disks, SSD, USB and other storage devices/instruments on market. The performance of ebdi goes up and down as the pattern of IO dispatched changes, as approximately estimated as below. P =3D j(..., IO pattern); In ebdi's view, the bandwidth currently measured in balancing dirty pages has close relation to its performance because the former is a part of the latter. B =3D y(P); The functions above suggest there may be a layer violation if it could be better measured somewhere below fs. It is measured however to the extent that makes every judge happy, and is playing a role in dispatching IO with the IO pattern entirely ignored that is volatile in nature. And it helps to throttle the dirty speed, with the figure ignored that DRAM in general is x10 faster than ebdi. If B is half of P for instance, then it is near 5% of dirty speed, just 2 points from the figure in the snippet below. /* * If ratelimit_pages is too high then we can get into dirty-data overloa= d * if a large number of processes all perform writes at the same time. * If it is too low then SMP machines will call the (expensive) * get_writeback_state too often. * * Here we set ratelimit_pages to a level which ensures that when all CPU= s are * dirtying in parallel, we cannot go more than 3% (1/32) over the dirty = memory * thresholds. */ To prevent dirty speed from running away from laundry speed, ebdi suggests the walk-dog method to put in bdp as a leash seems to churn less in IO pattern. V2 is based on next-20191025. Changes since v1 - drop CGWB_BDP_WITH_EBDI=20 Changes since v0 - add CGWB_BDP_WITH_EBDI in mm/Kconfig - drop wakeup in wbc_detach_inode() - add wakeup in wb_workfn() Cc: Fengguang Wu Cc: Tejun Heo Cc: Jan Kara Cc: Johannes Weiner Cc: Shakeel Butt Cc: Minchan Kim Cc: Mel Gorman Signed-off-by: Hillf Danton --- --- a/include/linux/backing-dev-defs.h +++ b/include/linux/backing-dev-defs.h @@ -170,6 +170,8 @@ struct bdi_writeback { =20 struct list_head bdi_node; /* anchored at bdi->wb_list */ =20 + struct wait_queue_head bdp_waitq; + #ifdef CONFIG_CGROUP_WRITEBACK struct percpu_ref refcnt; /* used only for !root wb's */ struct fprop_local_percpu memcg_completions; --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -324,6 +324,8 @@ static int wb_init(struct bdi_writeback goto out_destroy_stat; } =20 + init_waitqueue_head(&wb->bdp_waitq); + return 0; =20 out_destroy_stat: --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -1551,6 +1551,39 @@ static inline void wb_dirty_limits(struc } } =20 +static bool cgwb_bdp_should_throttle(struct bdi_writeback *wb) +{ + struct dirty_throttle_control gdtc =3D { GDTC_INIT_NO_WB }; + + if (fatal_signal_pending(current)) + return false; + + gdtc.avail =3D global_dirtyable_memory(); + + domain_dirty_limits(&gdtc); + + gdtc.dirty =3D global_node_page_state(NR_FILE_DIRTY) + + global_node_page_state(NR_UNSTABLE_NFS) + + global_node_page_state(NR_WRITEBACK); + + if (gdtc.dirty < gdtc.bg_thresh) + return false; + + if (!writeback_in_progress(wb)) + wb_start_background_writeback(wb); + + return gdtc.dirty > gdtc.thresh && + wb_stat(wb, WB_DIRTIED) > + wb_stat(wb, WB_WRITTEN) + + wb_stat_error(); +} + +static inline void cgwb_bdp(struct bdi_writeback *wb) +{ + wait_event_interruptible_timeout(wb->bdp_waitq, + !cgwb_bdp_should_throttle(wb), HZ); +} + /* * balance_dirty_pages() must be called by processes which are generatin= g dirty * data. It looks at the number of dirty pages in the machine and will = force @@ -1910,7 +1943,7 @@ void balance_dirty_pages_ratelimited(str preempt_enable(); =20 if (unlikely(current->nr_dirtied >=3D ratelimit)) - balance_dirty_pages(wb, current->nr_dirtied); + cgwb_bdp(wb); =20 wb_put(wb); } --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -811,6 +811,8 @@ static long wb_split_bdi_pages(struct bd if (nr_pages =3D=3D LONG_MAX) return LONG_MAX; =20 + return nr_pages; + /* * This may be called on clean wb's and proportional distribution * may not make sense, just use the original @nr_pages in those @@ -1604,6 +1606,7 @@ static long writeback_chunk_size(struct pages =3D min(pages, work->nr_pages); pages =3D round_down(pages + MIN_WRITEBACK_PAGES, MIN_WRITEBACK_PAGES); + pages =3D work->nr_pages; } =20 return pages; @@ -2092,6 +2095,9 @@ void wb_workfn(struct work_struct *work) wb_wakeup_delayed(wb); =20 current->flags &=3D ~PF_SWAPWRITE; + + if (waitqueue_active(&wb->bdp_waitq)) + wake_up_all(&wb->bdp_waitq); } =20 /* --