Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4350335ybl; Mon, 26 Aug 2019 09:08:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqziW57jz+JYBngldJYuebj5WdPYDqa4AHwue2rPGDUxj8SNDo5TKVnehNtub8cwjJwpINEX X-Received: by 2002:a17:90a:c20f:: with SMTP id e15mr20386180pjt.123.1566835707817; Mon, 26 Aug 2019 09:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566835707; cv=none; d=google.com; s=arc-20160816; b=F+89lx5gpYRv+ctQtEj/upsZNIWn0/Z0Ef2JR+TegULMABGzYEjGpuiWs/MZnTl1x6 Qey8k14TQu9NAAKW6QHcXywrfDiWxcRY6GnYXlDkyuhI9fv56cLgLzW2QePrlYGbt9/P a+otE6MZSK/IIc27Y2uMszpGf4TdB3yYdNo8T1ymmS7qx+BT8ZhwAN+wIdBtEqyjFNmU WAUOdfXwReSPf7cSZ7S7EJMHXG7ByEzYUc6W/D/b9GhWtVttw7cqm+MlncMYgetVrr+R fZqLlk5mWNi9ZL7osLZEI+4ralRZaID3QdYe6LomrR+DVV4tPzT2ifmorCXaCM1MlwUA C3sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=sbi9AtPpKs90xX0XCzYWXMGLwoRRPZP34bqUM0NUXLs=; b=xIe55rhcvssQm15bLXjLzjiO3NZLcUthHRxflIMrORDBkuEicEDXF1cShWeMqNDIj5 cID0PpG+GElRiC3eiKxuvogtInAABOs2M4LKgw1qbALOEah72acTbIuDBYhx8wQKza63 4Od7B0L12MXOH1pW5xfVhmRiH0tILp200w2iVNRLv86bgCppOWfKFWmg6O2RIcoQ0Qwy racKtvgKc/ixuHTXhoqt/Urq/JfVu68Lm7Klnm4JJ8gQf/ftpD5muAhkONOyKs4Who6Q 4129rEpTDPx02MCo1cP2/QyR3K+hn6wijuazkKUteTAiFAxQKT1+NJdMCn6C19sZvP62 LKgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gX5n0n0I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v27si9589777pgn.14.2019.08.26.09.08.12; Mon, 26 Aug 2019 09:08:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gX5n0n0I; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732688AbfHZQHP (ORCPT + 99 others); Mon, 26 Aug 2019 12:07:15 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38970 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732612AbfHZQHL (ORCPT ); Mon, 26 Aug 2019 12:07:11 -0400 Received: by mail-qt1-f193.google.com with SMTP id l9so18371244qtu.6; Mon, 26 Aug 2019 09:07:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=sbi9AtPpKs90xX0XCzYWXMGLwoRRPZP34bqUM0NUXLs=; b=gX5n0n0Iya2r+6HfxSBgduwjqnM9PRtJlmoEm5ghngBsve/UtQYFYtPDwNviTIYOMH yLHoMeNJ+DWQ0bdNx4cvSVgcN681dV36+OkH/g1jKJgRguOi7VsP0NlyTZAz7cNUZOE6 zqnuyTGB/QvBuFExLTGnei+AosOZ6sQ0y8LkGtkVWGqoLaIqdMokGxmf43BnVYTMWOsm TfgrfDI+kUfbZopDzIk1PUoIxNGEh7GWOOExZRBb6f7AdZPpR69VNoZkY4jlUDeGLJQo pcOBl6W9Exf/K3YN+IZmyKLnwa/O+zqQugMqiuDEyPBkAwPlHoZuAITEWOR87u2+0DCW ok0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=sbi9AtPpKs90xX0XCzYWXMGLwoRRPZP34bqUM0NUXLs=; b=lAu9S9iex0vX+b+i6BGbhCh4rCDjb43qIoeBVZA0tbOjfj9vr7MNd+YwOwUVM+3D41 a+zUZF1tLNpg9fHAP4GFK5BhpDv9XOQlzIBq7p48d3Wpf+PFOjU6/3+w8r3Kv2vMq+JG blol3er/fN5nVDAtoCLtcSbQDrbPcv4LuOHHpZ5cfDL299hxyOZpg9s+BeBNyEM0Zl60 aj0SN8Ve3bnRDLy0VipTz1b0OgcIHH7yTQEmMGt9iQDX0J4t0FXNWTvF1cee4rUEdud7 Yd1Pp99OZnjfU7JBoSoxf0iSkeniqtgwPI82tFPH0mieM3PKz5WX8ZsLSYXpCXzwLqP9 WtHQ== X-Gm-Message-State: APjAAAWoMp9YiSRWdG7FmtrDlswnL6gZa+W1wRtHZUDG+2Ms+Nf8WIxN 9O1K00hRYQ1w8Wq97WVAuQ0= X-Received: by 2002:ac8:4789:: with SMTP id k9mr18184801qtq.41.1566835630468; Mon, 26 Aug 2019 09:07:10 -0700 (PDT) Received: from localhost ([2620:10d:c091:500::d081]) by smtp.gmail.com with ESMTPSA id 131sm6410446qkn.7.2019.08.26.09.07.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Aug 2019 09:07:09 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk, jack@suse.cz, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, guro@fb.com, akpm@linux-foundation.org, Tejun Heo Subject: [PATCH 3/5] writeback: Separate out wb_get_lookup() from wb_get_create() Date: Mon, 26 Aug 2019 09:06:54 -0700 Message-Id: <20190826160656.870307-4-tj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190826160656.870307-1-tj@kernel.org> References: <20190826160656.870307-1-tj@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Separate out wb_get_lookup() which doesn't try to create one if there isn't already one from wb_get_create(). This will be used by later patches. Signed-off-by: Tejun Heo Reviewed-by: Jan Kara --- include/linux/backing-dev.h | 2 ++ mm/backing-dev.c | 55 +++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 84cdcfbc763f..97967ce06de3 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -230,6 +230,8 @@ static inline int bdi_sched_wait(void *word) struct bdi_writeback_congested * wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp); void wb_congested_put(struct bdi_writeback_congested *congested); +struct bdi_writeback *wb_get_lookup(struct backing_dev_info *bdi, + struct cgroup_subsys_state *memcg_css); struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi, struct cgroup_subsys_state *memcg_css, gfp_t gfp); diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 612aa7c5ddbd..d9daa3e422d0 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -618,13 +618,12 @@ static int cgwb_create(struct backing_dev_info *bdi, } /** - * wb_get_create - get wb for a given memcg, create if necessary + * wb_get_lookup - get wb for a given memcg * @bdi: target bdi * @memcg_css: cgroup_subsys_state of the target memcg (must have positive ref) - * @gfp: allocation mask to use * - * Try to get the wb for @memcg_css on @bdi. If it doesn't exist, try to - * create one. The returned wb has its refcount incremented. + * Try to get the wb for @memcg_css on @bdi. The returned wb has its + * refcount incremented. * * This function uses css_get() on @memcg_css and thus expects its refcnt * to be positive on invocation. IOW, rcu_read_lock() protection on @@ -641,6 +640,39 @@ static int cgwb_create(struct backing_dev_info *bdi, * each lookup. On mismatch, the existing wb is discarded and a new one is * created. */ +struct bdi_writeback *wb_get_lookup(struct backing_dev_info *bdi, + struct cgroup_subsys_state *memcg_css) +{ + struct bdi_writeback *wb; + + if (!memcg_css->parent) + return &bdi->wb; + + rcu_read_lock(); + wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id); + if (wb) { + struct cgroup_subsys_state *blkcg_css; + + /* see whether the blkcg association has changed */ + blkcg_css = cgroup_get_e_css(memcg_css->cgroup, &io_cgrp_subsys); + if (unlikely(wb->blkcg_css != blkcg_css || !wb_tryget(wb))) + wb = NULL; + css_put(blkcg_css); + } + rcu_read_unlock(); + + return wb; +} + +/** + * wb_get_create - get wb for a given memcg, create if necessary + * @bdi: target bdi + * @memcg_css: cgroup_subsys_state of the target memcg (must have positive ref) + * @gfp: allocation mask to use + * + * Try to get the wb for @memcg_css on @bdi. If it doesn't exist, try to + * create one. See wb_get_lookup() for more details. + */ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi, struct cgroup_subsys_state *memcg_css, gfp_t gfp) @@ -653,20 +685,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi, return &bdi->wb; do { - rcu_read_lock(); - wb = radix_tree_lookup(&bdi->cgwb_tree, memcg_css->id); - if (wb) { - struct cgroup_subsys_state *blkcg_css; - - /* see whether the blkcg association has changed */ - blkcg_css = cgroup_get_e_css(memcg_css->cgroup, - &io_cgrp_subsys); - if (unlikely(wb->blkcg_css != blkcg_css || - !wb_tryget(wb))) - wb = NULL; - css_put(blkcg_css); - } - rcu_read_unlock(); + wb = wb_get_lookup(bdi, memcg_css); } while (!wb && !cgwb_create(bdi, memcg_css, gfp)); return wb; -- 2.17.1