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=-14.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 2D7C0C433FF for ; Fri, 9 Aug 2019 23:03:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04C8D208C4 for ; Fri, 9 Aug 2019 23:03:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hgx4J6Xn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728057AbfHIXDx (ORCPT ); Fri, 9 Aug 2019 19:03:53 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37814 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbfHIXDx (ORCPT ); Fri, 9 Aug 2019 19:03:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id b3so7204520wro.4 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=GzmtzjCSb8g8QeKzl/nPYcyGcJePbPOeaw/CN4kiK3GIZElipJAGS227lWFyz316sp QRLu178YHK3dDmEwcbn3mdFsiJ6XxYhsH0l+swH0vovXLaygj/2DoxOW36zIy6EUjqll pSgESdSYzAsoD3Ej7+kI9DKpZbqfnq9uytT23WiXANoc3cqwyB9gkM4alyxYKjz0liQo +q1EJUcgFlkys4Jzk33Vhvib/0SvdFLtCuwqXAFmAH15thDmsXnqEgNcL4KNf8HHG6T3 OkFxGiusffbCPz81Ngd2ulz0rt2rTi58ZtXg8UOeiXZerW6iiPaTwD8uGS/DgFWPDJXj WyHg== X-Gm-Message-State: APjAAAVUnI9TaABu6f9JHAV9+s/FsTTMqA23kMbstgTLW4RgTHY/G896 frSuL54I3+7rPgGG+OHWqGq+EdGdCXNubmIU0O4iGg== X-Google-Smtp-Source: APXvYqxNIFUtq0mvXkjapWy5+xX1d0Xp8TP4K9kMBJ6lZAuc7uPuLpfox+P3pZ3dVwbona9mq6bzyo+H3lZPiB9qFJI= 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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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