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=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 63FDAC2BA2B for ; Thu, 16 Apr 2020 06:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 423DE20857 for ; Thu, 16 Apr 2020 06:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587018340; bh=lzpRqPBUwIIGNxeK8ErMkJC4dKa1WefGXxSlP+PW1Z0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=Je5tHm9EMtTV4LcoUhNRwQO1an2I+JwmpIwUskqjdlqSaC9HcD3pBBslWLzy3gLGO ocQRCHlG/9ROzEQUNP2oyquuhC7eUPalq+CBE+Iqo8J5Gj9iFwUboP9WnOaxKSN83U EGw19+Yq6wVowTRPyAsihYoN2b6UOHFrHdvJpCts= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407823AbgDPGZh (ORCPT ); Thu, 16 Apr 2020 02:25:37 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46908 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407774AbgDPGZf (ORCPT ); Thu, 16 Apr 2020 02:25:35 -0400 Received: by mail-pl1-f194.google.com with SMTP id n24so981330plp.13; Wed, 15 Apr 2020 23:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yXGR4Bg7B4fWxnTesZDbA54bH8hV3HoWza1XGimfjCQ=; b=ij3A3+APdQJWzUcKzcLAF4WF18t5tsxqLbyZ5XxJndYYbfZYbEUsiyGj7xpUgN5n96 aXED9mfpvKLXBw9FN/INB366/gQpXYf72ilJ9Zz322aBGjbSAQfrFI6MHmHrefLp+/h+ THej5HCGfLWg9RBqdCjzOf8CR+2LwFvVSveg6T7UQNq1L1brDUkmJ6a+x4si1BGa4L+2 3pX/QJW3QPLxSLYnbvLJKwP0uajeb7XmPmKOHWFGzId+/OmzEdBicgCXTE6k01Znxkjs bAS67Af2WJw2bawcQAKkXJ+oXGZBkGwigdtjkci7NtZ/WjkGNwAEh9rfjdgW4Dxmh2BY qTaA== X-Gm-Message-State: AGi0PubxTvldvD8n3+75zyhNmYujNKXdlP5DzALZfJQuRbnZEEb6rLiD QeTyQNTRxKxUws/5RvSjvPo= X-Google-Smtp-Source: APiQypK6Q94irkE310ki9D9P7Ta4hUnFoh9tC5XFqGd/hIiWcNXJbF2na+YajnIaMneHsYoGJn1tfg== X-Received: by 2002:a17:902:7d89:: with SMTP id a9mr8415747plm.233.1587018334960; Wed, 15 Apr 2020 23:25:34 -0700 (PDT) Received: from 42.do-not-panic.com (42.do-not-panic.com. [157.230.128.187]) by smtp.gmail.com with ESMTPSA id a9sm14500113pgv.18.2020.04.15.23.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2020 23:25:33 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id EBF4140277; Thu, 16 Apr 2020 06:25:32 +0000 (UTC) Date: Thu, 16 Apr 2020 06:25:32 +0000 From: Luis Chamberlain To: Ming Lei Cc: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, nstange@suse.de, akpm@linux-foundation.org, mhocko@suse.com, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Omar Sandoval , Hannes Reinecke , Michal Hocko Subject: Re: [PATCH 4/5] mm/swapfile: refcount block and queue before using blkcg_schedule_throttle() Message-ID: <20200416062532.GN11244@42.do-not-panic.com> References: <20200414041902.16769-1-mcgrof@kernel.org> <20200414041902.16769-5-mcgrof@kernel.org> <20200416062222.GC2723777@T590> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200416062222.GC2723777@T590> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Thu, Apr 16, 2020 at 02:22:22PM +0800, Ming Lei wrote: > On Tue, Apr 14, 2020 at 04:19:01AM +0000, Luis Chamberlain wrote: > > block devices are refcounted so to ensure once its final user goes away it > > can be cleaned up by the lower layers properly. The block device's > > request_queue structure is also refcounted, however, if the last > > blk_put_queue() is called under atomic context the block layer has > > to defer removal. > > > > By refcounting the block device during the use of blkcg_schedule_throttle(), > > we ensure ensure two things: > > > > 1) the block device remains available during the call > > 2) we ensure avoid having to deal with the fact we're using the > > request_queue structure in atomic context, since the last > > blk_put_queue() will be called upon disk_release(), *after* > > our own bdput(). > > > > This means this code path is *not* going to remove the request_queue > > structure, as we are ensuring some later upper layer disk_release() > > will be the one to release the request_queue structure for us. > > > > Cc: Bart Van Assche > > Cc: Omar Sandoval > > Cc: Hannes Reinecke > > Cc: Nicolai Stange > > Cc: Greg Kroah-Hartman > > Cc: Michal Hocko > > Cc: yu kuai > > Signed-off-by: Luis Chamberlain > > --- > > mm/swapfile.c | 14 ++++++++++++-- > > 1 file changed, 12 insertions(+), 2 deletions(-) > > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 6659ab563448..9285ff6030ca 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -3753,6 +3753,7 @@ static void free_swap_count_continuations(struct swap_info_struct *si) > > void mem_cgroup_throttle_swaprate(struct mem_cgroup *memcg, int node, > > gfp_t gfp_mask) > > { > > + struct block_device *bdev; > > struct swap_info_struct *si, *next; > > if (!(gfp_mask & __GFP_IO) || !memcg) > > return; > > @@ -3771,8 +3772,17 @@ void mem_cgroup_throttle_swaprate(struct mem_cgroup *memcg, int node, > > plist_for_each_entry_safe(si, next, &swap_avail_heads[node], > > avail_lists[node]) { > > if (si->bdev) { > > - blkcg_schedule_throttle(bdev_get_queue(si->bdev), > > - true); > > + bdev = bdgrab(si->bdev); > > When swapon, the block_device has been opened in claim_swapfile(), > so no need to worry about the queue being gone here. Thanks, so why bdev_get_queue() before? Luis