Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp903602ybl; Fri, 9 Aug 2019 16:04:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6g4MCl3walWSwOSyQNHNsQJcfM6BxJRqwcw1omRdMWUSliCD0g2Xa1axAjtHhMPA+xi7I X-Received: by 2002:a62:2f06:: with SMTP id v6mr24185860pfv.195.1565391872989; Fri, 09 Aug 2019 16:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565391872; cv=none; d=google.com; s=arc-20160816; b=AuADXTYSGJ3LI8sl//nmUXmhrLIrcPVnpoGhKjjHRh4U8ducFaFquFPrVsk9WnHfAb SO11720m3XY7Kz/8olj4GuKRKie8M6CiRH9s0GJxr8Pe9qttZSTqZy/ONtkY94W9lJOh aGpMRr16juWBh1OhBroJ9jPmxKOAAuZYebGBTcV5W6nvfaHdVOkeMRhCw6MxWWy/grHn T3VLGmZHoZAch1ZIP2k1shsQjG1RuEBfAcbE/0Q30btYvVSPyGG79xexfKOnpD//AwHD gCEjH0sfoFLsA+EbOyp4gWbU7MQzK/AnwWwzEJduhRw4tc8BVo6NCsnvY33nIGWwO0My 0Wcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=AA45q6IMPxeio0FSS0wDQ5w5I6FSh5bk8IxEXeZUP0E=; b=fl5yiD1RqpynWzAP5iDxYOfHT55PW/mcruo0ckhYuDbue3Koa8yXUG7hkn+zvCQPXo 5NfDqfawcf42Xr62OLj1RpTBCnLnPBMGix505N+hGm9Zzcqogv+SxaVES2gZ21eylXxW D9G6afw3xTSbzbTlBJk1YdhVDIbhJUINp3swdX+6173QJieL81Zsb+3T19BoxKJ5dEV6 3SLv2UtGcVy0hQPgZYRUAtghzLCDZ8LeYgZmOMO+ehHZOVirUDkbzBxFmecHshlMM0Ef UnY4hD2ll4GXjIaClkGps4+lfF8rLpMGellHaVLKf85zcGHcpbnvZ/5jInoW2i3mYacF jwPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Hgx4J6Xn; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si51166191plg.353.2019.08.09.16.04.18; Fri, 09 Aug 2019 16:04:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Hgx4J6Xn; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727484AbfHIXDx (ORCPT + 99 others); Fri, 9 Aug 2019 19:03:53 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44648 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbfHIXDx (ORCPT ); Fri, 9 Aug 2019 19:03:53 -0400 Received: by mail-wr1-f65.google.com with SMTP id p17so99578051wrf.11 for ; Fri, 09 Aug 2019 16:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AA45q6IMPxeio0FSS0wDQ5w5I6FSh5bk8IxEXeZUP0E=; b=Hgx4J6XnzbPi/G6IzDkRvXBDXp3Xw1iLGFI/8Hl4XZuiFH/pUvEk+HOHKKjP76/hQX mWBD6zQ+rQEL/nOuq0/6OmDbIxxGtFO6mY0LVFTTsqFrIlaZRSb6M8aKKowHzhH3DQTm 2V+ddlS0fA173GTaNiMA1v1CE+VrS8SelYzm2zJvLS4DQ8ADl33KFGIwXY+3yOoWJZOf 43vCBcpxoWOuxjX+XDan+MgqKv25HMcRzB9Sdy38s8MR02Rff0hzlNnG2pYSL2LO5aSF Ub94moH3Leka0deP3ghd/pfu+DURzPTrsZXYAaf5nPRADSxRxH4ONydFG4lxIGtrLsfa iSyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AA45q6IMPxeio0FSS0wDQ5w5I6FSh5bk8IxEXeZUP0E=; b=SDvC5dD7zPnh14BpNAOr0mGlEJEU9lhRUdJCGyvS0NF30eYkdtkdUFAzGLO48fk3qB Y5MicJe6KVNKYD2ZzgLUUebcHJYEBPU8EJ/7GpHmiWGSJBNHM2t10xv0tTTW1ll17Qkb DrTz0lrdFNgdo39D+2HcOWZHXRauOuTVkY+Avb3MeRaq2E7vWGDtNPV/+RLHMreHPQ93 8dOqJm223Gzwc2jf78iLvkat0kDI9j+EKROMZ+flYtycWvsi4+m85Og1UngjGD/Sk4LC O+cCCteSSrLYGOLcxYcExfF5i27uI49AxNJC29cNzVc45lVQLj3fwGjL58O/2FRxzZ0J ZAiw== X-Gm-Message-State: APjAAAXr0pyaJVBKmvSq6NOHhZJK0TI7pb9K6IIalhQFoX4/lZhYcQaj 2vHswcLUwtQI70U9IV4PT/PX2IYAvRJPHdLYNUQoXQ== X-Received: by 2002:adf:ce88:: with SMTP id r8mr28161681wrn.42.1565391830743; Fri, 09 Aug 2019 16:03:50 -0700 (PDT) MIME-Version: 1.0 References: <20190808190300.GA9067@cmpxchg.org> In-Reply-To: <20190808190300.GA9067@cmpxchg.org> From: Suren Baghdasaryan Date: Fri, 9 Aug 2019 16:03:39 -0700 Message-ID: Subject: Re: [PATCH RESEND] block: annotate refault stalls from IO submission To: Johannes Weiner Cc: Jens Axboe , Dave Chinner , Andrew Morton , linux-mm , linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Aug 8, 2019 at 12:03 PM Johannes Weiner wrote: > > psi tracks the time tasks wait for refaulting pages to become > uptodate, but it does not track the time spent submitting the IO. The > submission part can be significant if backing storage is contended or > when cgroup throttling (io.latency) is in effect - a lot of time is > spent in submit_bio(). In that case, we underreport memory pressure. > > Annotate submit_bio() to account submission time as memory stall when > the bio is reading userspace workingset pages. > > Signed-off-by: Johannes Weiner > --- > block/bio.c | 3 +++ > block/blk-core.c | 23 ++++++++++++++++++++++- > include/linux/blk_types.h | 1 + > 3 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/block/bio.c b/block/bio.c > index 299a0e7651ec..4196865dd300 100644 > --- a/block/bio.c > +++ b/block/bio.c > @@ -806,6 +806,9 @@ void __bio_add_page(struct bio *bio, struct page *page, > > bio->bi_iter.bi_size += len; > bio->bi_vcnt++; > + > + if (!bio_flagged(bio, BIO_WORKINGSET) && unlikely(PageWorkingset(page))) > + bio_set_flag(bio, BIO_WORKINGSET); > } > EXPORT_SYMBOL_GPL(__bio_add_page); > > diff --git a/block/blk-core.c b/block/blk-core.c > index d0cc6e14d2f0..1b1705b7dde7 100644 > --- a/block/blk-core.c > +++ b/block/blk-core.c > @@ -36,6 +36,7 @@ > #include > #include > #include > +#include > > #define CREATE_TRACE_POINTS > #include > @@ -1128,6 +1129,10 @@ EXPORT_SYMBOL_GPL(direct_make_request); > */ > blk_qc_t submit_bio(struct bio *bio) > { > + bool workingset_read = false; > + unsigned long pflags; > + blk_qc_t ret; > + > if (blkcg_punt_bio_submit(bio)) > return BLK_QC_T_NONE; > > @@ -1146,6 +1151,8 @@ blk_qc_t submit_bio(struct bio *bio) > if (op_is_write(bio_op(bio))) { > count_vm_events(PGPGOUT, count); > } else { > + if (bio_flagged(bio, BIO_WORKINGSET)) > + workingset_read = true; > task_io_account_read(bio->bi_iter.bi_size); > count_vm_events(PGPGIN, count); > } > @@ -1160,7 +1167,21 @@ blk_qc_t submit_bio(struct bio *bio) > } > } > > - return generic_make_request(bio); > + /* > + * If we're reading data that is part of the userspace > + * workingset, count submission time as memory stall. When the > + * device is congested, or the submitting cgroup IO-throttled, > + * submission can be a significant part of overall IO time. > + */ > + if (workingset_read) > + psi_memstall_enter(&pflags); > + > + ret = generic_make_request(bio); > + > + if (workingset_read) > + psi_memstall_leave(&pflags); > + > + return ret; > } > EXPORT_SYMBOL(submit_bio); > > diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h > index 1b1fa1557e68..a9dadfc16a92 100644 > --- a/include/linux/blk_types.h > +++ b/include/linux/blk_types.h > @@ -209,6 +209,7 @@ enum { > BIO_BOUNCED, /* bio is a bounce bio */ > BIO_USER_MAPPED, /* contains user pages */ > BIO_NULL_MAPPED, /* contains invalid user pages */ > + BIO_WORKINGSET, /* contains userspace workingset pages */ > BIO_QUIET, /* Make BIO Quiet */ > BIO_CHAIN, /* chained bio, ->bi_remaining in effect */ > BIO_REFFED, /* bio has elevated ->bi_cnt */ > -- > 2.22.0 > The change contributes to the amount of recorded stall while running memory stress test with and without the patch. Did not notice any performance regressions so far. Thanks! Tested-by: Suren Baghdasaryan