From patchwork Mon Mar 23 04:54:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 6070371 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 46020BF90F for ; Mon, 23 Mar 2015 05:19:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78CBE201FA for ; Mon, 23 Mar 2015 05:19:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D898200E7 for ; Mon, 23 Mar 2015 05:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752512AbbCWFTj (ORCPT ); Mon, 23 Mar 2015 01:19:39 -0400 Received: from mail-qg0-f52.google.com ([209.85.192.52]:35775 "EHLO mail-qg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752161AbbCWEzW (ORCPT ); Mon, 23 Mar 2015 00:55:22 -0400 Received: by qgf74 with SMTP id 74so11431952qgf.2; Sun, 22 Mar 2015 21:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=+DOS9EDFeydzccS3jbmDKoamxnq6YJmGgu6Upq3HCeo=; b=ZoZfGfUAaVGAfOrDY9z2TwjQdEI4b0LPrGAMpe+GhYSjEGoxLFCjipCOF5Cd1X3JW2 0Kj/1zVizlEi5aedWWytIvSBO+SFF0k3Z1WODBrMdZGXCMC2moBdheFZ10iWkPIHSd0n DlSzS344uGjC/M8GZcqPBIre5sP0qrwQ0zJhj0XRg6iZQ9Wtdg2cwKyjOixUoBOylZwC YY0iW2I1TjueX/5aF96Cq1UhMVnqB7XCkp1XQmIdjRwvebipbg7nV0l/94y8hqKpKk7i B8vDXQkvDBHEtalmy6QXf1ezTlWF4A0JUcabdkgXvb71aWC8UMFohjpBAqf1SbehltGj lK3w== X-Received: by 10.55.42.27 with SMTP id q27mr158874181qkh.64.1427086521819; Sun, 22 Mar 2015 21:55:21 -0700 (PDT) Received: from htj.duckdns.org.lan (207-38-238-8.c3-0.wsd-ubr1.qens-wsd.ny.cable.rcn.com. [207.38.238.8]) by mx.google.com with ESMTPSA id n20sm8504159qgd.48.2015.03.22.21.55.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2015 21:55:20 -0700 (PDT) From: Tejun Heo To: axboe@kernel.dk Cc: linux-kernel@vger.kernel.org, jack@suse.cz, hch@infradead.org, hannes@cmpxchg.org, linux-fsdevel@vger.kernel.org, vgoyal@redhat.com, lizefan@huawei.com, cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz, clm@fb.com, fengguang.wu@intel.com, david@fromorbit.com, gthelen@google.com, Tejun Heo Subject: [PATCH 08/48] blkcg: implement bio_associate_blkcg() Date: Mon, 23 Mar 2015 00:54:19 -0400 Message-Id: <1427086499-15657-9-git-send-email-tj@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1427086499-15657-1-git-send-email-tj@kernel.org> References: <1427086499-15657-1-git-send-email-tj@kernel.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, a bio can only be associated with the io_context and blkcg of %current using bio_associate_current(). This is too restrictive for cgroup writeback support. Implement bio_associate_blkcg() which associates a bio with the specified blkcg. bio_associate_blkcg() leaves the io_context unassociated. bio_associate_current() is updated so that it considers a bio as already associated if it has a blkcg_css, instead of an io_context, associated with it. Signed-off-by: Tejun Heo Cc: Jens Axboe Cc: Vivek Goyal --- block/bio.c | 24 +++++++++++++++++++++++- include/linux/bio.h | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index 968683e..ab7517d 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1971,6 +1971,28 @@ struct bio_set *bioset_create_nobvec(unsigned int pool_size, unsigned int front_ EXPORT_SYMBOL(bioset_create_nobvec); #ifdef CONFIG_BLK_CGROUP + +/** + * bio_associate_blkcg - associate a bio with the specified blkcg + * @bio: target bio + * @blkcg_css: css of the blkcg to associate + * + * Associate @bio with the blkcg specified by @blkcg_css. Block layer will + * treat @bio as if it were issued by a task which belongs to the blkcg. + * + * This function takes an extra reference of @blkcg_css which will be put + * when @bio is released. The caller must own @bio and is responsible for + * synchronizing calls to this function. + */ +int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css) +{ + if (unlikely(bio->bi_css)) + return -EBUSY; + css_get(blkcg_css); + bio->bi_css = blkcg_css; + return 0; +} + /** * bio_associate_current - associate a bio with %current * @bio: target bio @@ -1988,7 +2010,7 @@ int bio_associate_current(struct bio *bio) { struct io_context *ioc; - if (bio->bi_ioc) + if (bio->bi_css) return -EBUSY; ioc = current->io_context; diff --git a/include/linux/bio.h b/include/linux/bio.h index da3a127..cbc5d1d 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -469,9 +469,12 @@ extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int); extern unsigned int bvec_nr_vecs(unsigned short idx); #ifdef CONFIG_BLK_CGROUP +int bio_associate_blkcg(struct bio *bio, struct cgroup_subsys_state *blkcg_css); int bio_associate_current(struct bio *bio); void bio_disassociate_task(struct bio *bio); #else /* CONFIG_BLK_CGROUP */ +static inline int bio_associate_blkcg(struct bio *bio, + struct cgroup_subsys_state *blkcg_css) { return 0; } static inline int bio_associate_current(struct bio *bio) { return -ENOENT; } static inline void bio_disassociate_task(struct bio *bio) { } #endif /* CONFIG_BLK_CGROUP */