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.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 5BDE0C2BA2B for ; Thu, 16 Apr 2020 06:25:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 248A52078A for ; Thu, 16 Apr 2020 06:25:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 248A52078A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A3CED8E008E; Thu, 16 Apr 2020 02:25:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6B98E0001; Thu, 16 Apr 2020 02:25:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 841128E008E; Thu, 16 Apr 2020 02:25:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 65A028E0001 for ; Thu, 16 Apr 2020 02:25:36 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2E451180AD815 for ; Thu, 16 Apr 2020 06:25:36 +0000 (UTC) X-FDA: 76712731872.19.birds10_30e0777ff1856 X-HE-Tag: birds10_30e0777ff1856 X-Filterd-Recvd-Size: 5427 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 16 Apr 2020 06:25:35 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id cl8so925883pjb.3 for ; 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=ScpnWF0qfCFPvt4ewvubFB71yr9VW0yIyIoroSbvyvcaDpOFbHwWKfXdRCZjnoWTea uUO4/u5ToGgAFlD4KJlQCOVnnR2zpIm3WgRKWS8nCUHoTWVcwjdlE6ZUOr1wuDLq538Z aDnM5hWoJtqc0HZ/mr2dbRvJcCDPPRWbF6ogb+MmQr8EWSiLpMMXAC46sscbEr4YiVWq lSmwkzTcM+ED9BFUJAZMg3mg/NLHVhHJC5uGIaHH62LzFOx2sBQhq43bQWxziOCU/CwQ d4hGYk39a1Fdh3XRcx4GaE5HfdjWAWqTTvuauxt+ZnMnOn9QNCxDM3KgrSjLpJY2RnSa Kr7g== X-Gm-Message-State: AGi0Pub6qRvxm/XY9pbRe9mumgLbL2Ew1fWNIfT4vWHGE7DfIPNJQnR/ 92pon14brpnEOA/rXRtz40w= 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) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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