Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp964751ybz; Wed, 15 Apr 2020 23:36:56 -0700 (PDT) X-Google-Smtp-Source: APiQypJwBbACdmY6ERe6KUFmfrDQ6ips76PWavRJ4hwUaGCjINU4I+oG5YmgBGeVxtacyopUbCON X-Received: by 2002:a05:6402:543:: with SMTP id i3mr11752760edx.255.1587019016633; Wed, 15 Apr 2020 23:36:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587019016; cv=none; d=google.com; s=arc-20160816; b=VOJCj2Qh6wSKVOkRjkFYmvP7Be5n3kzvU6cX/NDR1baUyIbhHaJ+zgjfgRLsNDXMJC TfrfMSareiDoLjGi9RpRfK6Cw6L3TDQ0y8+oNm4ndZzCd5vwoLYKpsRaobIsnTI//Eyk nlm3YWxdTIDd+K9Z2H8O4d2n47ipttfhH5qsVHuR5PyC9T3PDl0OjLIFWN8NqJIIH6Sj /IK9+xXdFvv1qnhAcDmiyuZ35i8fki7MD+leVUNiQpyVKSGfzFhL1MZeo1y3YzDc0gkN uZXSB9WEW78JQ6pmFAbrKMYiVz+aU5jEHwt45CKgAoEOukisQO9sWvcoL8kiWbkIz6VT foLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=nCd3WtsGaX/OvVWiMxmVzNhR7/RYCqVcgsji7FHaInc=; b=rvmltR6Ss/wkTfVF7WL4uDv7jm8XzNUiTuAH1/3TakrXulBbVtEHLGGD4ZauDp71ff QuwMijYFwx8f1Sq6AaG4JfdCrDzCiz93DzFj6jbumY0plXFcojQIH74Outj6Ffa24p74 h/uZ3joljtDpRTOy5WcbjOLdT90ZbnwbKq7sxpyWyiGDWRBLRo6BUBaq/nnwja9DroQ/ DruVBe2SZMNjI3DDqjnm/kI9X6yzWSyaNwrrzcP2moNtTC9G4I/U0NMT3wit8Wyd2DxK wqp7rAYiACpWEpqaKZjqSJK8bV7+mtTAHpM0/1K6o6CfBFNP/hdzozmhJzGxGSm6ZV0G VUOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AmZPzQWe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df12si2064775edb.540.2020.04.15.23.36.32; Wed, 15 Apr 2020 23:36:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AmZPzQWe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408118AbgDPGfL (ORCPT + 99 others); Thu, 16 Apr 2020 02:35:11 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52067 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2407924AbgDPGey (ORCPT ); Thu, 16 Apr 2020 02:34:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587018892; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nCd3WtsGaX/OvVWiMxmVzNhR7/RYCqVcgsji7FHaInc=; b=AmZPzQWeTZCiG7pttWXhMI2sKSMMve2zwOdHuUKRGwoMSQvvkAQuMhV7pLB8dj+rLsRZ58 lBr9hOY9X7sTnhRMuLPVywRgiJH5t1nX5nIeNPpZK0FQfBtkEtbcdHyZGCmmiAmz76OUkt 8bw+1TBY9Pl6DqU/REZrQJr77cA/xDE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-fUDLkM2QNBqVmJ_SYclSCw-1; Thu, 16 Apr 2020 02:34:47 -0400 X-MC-Unique: fUDLkM2QNBqVmJ_SYclSCw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0CE51005513; Thu, 16 Apr 2020 06:34:44 +0000 (UTC) Received: from T590 (ovpn-8-29.pek2.redhat.com [10.72.8.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47CA7A0997; Thu, 16 Apr 2020 06:34:32 +0000 (UTC) Date: Thu, 16 Apr 2020 14:34:28 +0800 From: Ming Lei To: Luis Chamberlain 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: <20200416063428.GE2723777@T590> References: <20200414041902.16769-1-mcgrof@kernel.org> <20200414041902.16769-5-mcgrof@kernel.org> <20200416062222.GC2723777@T590> <20200416062532.GN11244@42.do-not-panic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200416062532.GN11244@42.do-not-panic.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 16, 2020 at 06:25:32AM +0000, Luis Chamberlain wrote: > 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? bdev_get_queue() returns the request queue associated with the the block device, and it is just that blkcg_schedule_throttle() needs it. Maybe I misunderstood your question, if yes, please explain it in a bit detail. Thanks, Ming