From patchwork Tue Apr 14 04:19:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 11486737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15506174A for ; Tue, 14 Apr 2020 04:19:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFBF120737 for ; Tue, 14 Apr 2020 04:19:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFBF120737 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 8D6858E000A; Tue, 14 Apr 2020 00:19:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7C5268E0001; Tue, 14 Apr 2020 00:19:11 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6636D8E000A; Tue, 14 Apr 2020 00:19:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 462D48E0001 for ; Tue, 14 Apr 2020 00:19:11 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 08605824559C for ; Tue, 14 Apr 2020 04:19:11 +0000 (UTC) X-FDA: 76705155702.07.bells97_8a59592a18b5a X-Spam-Summary: 2,0,0,2119b9c6c24249da,d41d8cd98f00b204,mcgrof@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:968:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2559:2562:2693:2736:2898:2903:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:4385:5007:6261:7903:8660:9389:10004:11026:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:12986:13148:13230:13255:13894:14181:14394:14721:14819:21080:21433:21444:21451:21627:21795:21987:21990:30012:30051:30054:30064:30070,0,RBL:209.85.215.194:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: bells97_8a59592a18b5a X-Filterd-Recvd-Size: 5207 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 04:19:10 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id r4so5457947pgg.4 for ; Mon, 13 Apr 2020 21:19:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y7GCMwZ+500s2UeOg6j11+a/fStJc20VLvn3M0bWMqk=; b=AL1kclqXjhyt5l2mGOM5rM/PmCqS3T5f+K1ePlGmCjwswCLVrAtoleZVt1sHwFpOdY Tse2ANNb9LZ++wgDoQXsB3dxNWZg2Y+YKiUbVxdYC6ZEHxveoFT8sb0oK5l+cYt84iLK qwf9h5Yk7VON/OQeJrHAkxLSNYtuzLOnV/f5H7jMM8VQJq0EC7L0OQUDkfPLDIBi+Pgi 4pmV6vbtQ1tp3ZgtDSeI4hKmG7fMeNfHStMhcozCEbCtL997U7u4HiNkS2B3Q2vNwk+f TgYUJ0wrPZpPu5qVAG523TL+IW/XblBcAH1ILnv03ZoeIxQCGwtju7s5V1uIVCialeDC CqgQ== X-Gm-Message-State: AGi0Pub3NHheZ6Myyzp9s/3O3DvYvIOI6uhAdMVArT2EAAgyCQ5nPkX/ 4ei3xSbSWSeMScUo2Tno1GI= X-Google-Smtp-Source: APiQypIhm3o5ig0Vl42dVHSMw8R//BDfhQcbCw+CHlsRTU54HdyPnw18cejKvzwRFkPw0xmS9mvYAQ== X-Received: by 2002:aa7:9207:: with SMTP id 7mr20846200pfo.178.1586837949770; Mon, 13 Apr 2020 21:19:09 -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 a1sm9983484pfl.188.2020.04.13.21.19.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 21:19:06 -0700 (PDT) Received: by 42.do-not-panic.com (Postfix, from userid 1000) id 1DA65419AC; Tue, 14 Apr 2020 04:19:04 +0000 (UTC) From: Luis Chamberlain To: axboe@kernel.dk, viro@zeniv.linux.org.uk, bvanassche@acm.org, gregkh@linuxfoundation.org, rostedt@goodmis.org, mingo@redhat.com, jack@suse.cz, ming.lei@redhat.com, nstange@suse.de, akpm@linux-foundation.org Cc: 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, Luis Chamberlain , Omar Sandoval , Hannes Reinecke , Michal Hocko Subject: [PATCH 4/5] mm/swapfile: refcount block and queue before using blkcg_schedule_throttle() Date: Tue, 14 Apr 2020 04:19:01 +0000 Message-Id: <20200414041902.16769-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20200414041902.16769-1-mcgrof@kernel.org> References: <20200414041902.16769-1-mcgrof@kernel.org> MIME-Version: 1.0 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: 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); + if (!bdev) + continue; + /* + * By adding our own bdgrab() we ensure the queue + * sticks around until disk_release(), and so we ensure + * our release of the request_queue does not happen in + * atomic context. + */ + blkcg_schedule_throttle(bdev_get_queue(bdev), true); + bdput(bdev); break; } }