From patchwork Mon Apr 9 04:46:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10330583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B21C16053B for ; Mon, 9 Apr 2018 04:46:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C7B28A1B for ; Mon, 9 Apr 2018 04:46:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8707228A5B; Mon, 9 Apr 2018 04:46:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44E4928A1B for ; Mon, 9 Apr 2018 04:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751737AbeDIEq1 (ORCPT ); Mon, 9 Apr 2018 00:46:27 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:36493 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750863AbeDIEq0 (ORCPT ); Mon, 9 Apr 2018 00:46:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1523249186; x=1554785186; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=pfF8myPxrrPlB+FNcWGheh3xcjKxxP9prW5GAyjaqDw=; b=ah6IWs70ZS9C4WqOH2c3oA+InIC4CeNFUvFz9JbX2c0eGkqR+15mM+P4 cOe3biiWpsoEYnUqDdoWyIZSm5SvdkynmZ8QxpC8kDviVDH3S5Zmdytm0 oaC0MIPPgwz1p5sahg8BX4bAk4yAQtpWDC8k2UPtqp/zyVw1N5x88D+XH HDTbkkMIn/3fMWgzMCtkAD5SU9I068Ae0ro0O7byOZ68ohDFjp9jaNlxU 07EaWT7r+vPgynQrk+ZOh980HnEACnlNH3giNOzuIhZMAV0nxEE3zI3tB zf4sONZXYV18y0hcOZn49Trk/eLMLsI3Gp5A2A33P2yHbhZz5mYgVvBtZ A==; X-IronPort-AV: E=Sophos;i="5.48,426,1517846400"; d="scan'208";a="75519625" Received: from mail-bn3nam01lp0180.outbound.protection.outlook.com (HELO NAM01-BN3-obe.outbound.protection.outlook.com) ([216.32.180.180]) by ob1.hgst.iphmx.com with ESMTP; 09 Apr 2018 12:46:25 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=pfF8myPxrrPlB+FNcWGheh3xcjKxxP9prW5GAyjaqDw=; b=VfCM7EV11Q2ZkXJwKRhoizk7KcPcIJrATuss0YFCQGFgyg8LQX44siQ6npeB3PQlxeO7XhUR8Qz5uWtf9qj8axI4VQ+ocJSLKUGz+IUDflNmyVRTk6NmK/bR50OAgwyeWhhRp8diLqbXqpUAwhAyylayd4vlvrcFOoD60CMO3l4= Received: from MWHPR04MB1198.namprd04.prod.outlook.com (10.173.48.151) by MWHPR04MB0190.namprd04.prod.outlook.com (10.169.201.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Mon, 9 Apr 2018 04:46:22 +0000 Received: from MWHPR04MB1198.namprd04.prod.outlook.com ([fe80::bc43:e461:43cb:4d27]) by MWHPR04MB1198.namprd04.prod.outlook.com ([fe80::bc43:e461:43cb:4d27%14]) with mapi id 15.20.0653.014; Mon, 9 Apr 2018 04:46:22 +0000 From: Bart Van Assche To: "willy@infradead.org" CC: "linux-block@vger.kernel.org" , "linux-mm@kvack.org" , "hare@suse.com" , "martin@lichtvoll.de" , "oleksandr@natalenko.name" , "axboe@kernel.dk" Subject: Re: Block layer use of __GFP flags Thread-Topic: Block layer use of __GFP flags Thread-Index: AQHTzwZ1kN9Rk3a46km7yeotYg/uy6P3Eq+AgAApNICAAKF5gA== Date: Mon, 9 Apr 2018 04:46:22 +0000 Message-ID: <63d16891d115de25ac2776088571d7e90dab867a.camel@wdc.com> References: <20180408065425.GD16007@bombadil.infradead.org> <20180408190825.GC5704@bombadil.infradead.org> In-Reply-To: <20180408190825.GC5704@bombadil.infradead.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; x-originating-ip: [76.103.131.8] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB0190; 7:tTDitOu9YvbccYKymChGrnqWSrw740/SzwN0U2AkBS2JF01ekTwqiKn5jWUQs0q3RU97F8oPKZfUrlr5Q4U+lDxdy5Be6Fd5uHzn7gskpAmQv0IuQd8pfTPorBwqBGH8x7GrWTT0FwrQ3LmZEDHI03tNSughEpxbdPkybm51Y9DlNs+Z20Z9j9y7dQXePFJCZa484eq3V1+leD4L29mjLAl2WuPu4PQPczKWI0lxQaLw832mD1PnSz0Kka1+mgFS; 20:9N8/zTuJUMEooCk4C4jbwHkvFG439+bxb5X+0k+SvGFA4bhY3RWlQ8HLHkS3Axvh8k0B35IBBrNrtmFsOO/o9wZDW7ZC5DdsJ643RXYABvhfd+3yqyBkGzKiOuUKLokabFtzv7R7Qc1E+ENKnX3IHd1JxFpJQMbositARgJu8ao= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 334e55e7-27a5-43d4-a296-08d59dd4d7f6 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB0190; x-ms-traffictypediagnostic: MWHPR04MB0190: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011); SRVR:MWHPR04MB0190; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB0190; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(366004)(396003)(39380400002)(346002)(376002)(377424004)(51444003)(199004)(189003)(66066001)(8936002)(97736004)(26005)(1730700003)(478600001)(6512007)(3846002)(6116002)(6246003)(186003)(2351001)(316002)(8676002)(68736007)(305945005)(81156014)(81166006)(118296001)(105586002)(53936002)(575784001)(86362001)(102836004)(229853002)(7736002)(106356001)(5250100002)(2501003)(6436002)(5660300001)(5640700003)(6486002)(25786009)(4326008)(36756003)(6916009)(3660700001)(14454004)(72206003)(54906003)(476003)(2616005)(11346002)(2906002)(486006)(2900100001)(59450400001)(99286004)(3280700002)(446003)(76176011)(6506007); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB0190; H:MWHPR04MB1198.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-microsoft-antispam-message-info: KaWAots8E3T+OImiQYmd25h0293dz8dHW3jJvIHn/cnlX3CyVNuXk3tMvOLEHpLT8dCmMidxa2VVHe2ibpHxrSVS935e+gigq1ndjnjWTFn3a7i8MucDEIZruR/CkhwvU6MGTKnkzxm1vfKQedartHwCFlcqrejqNCXQ+onF8DYKOrYhES4C4m0YVcnPeWyJdw80FO36nsJmdQR4Dec6Zk6x+j92tfGtmxokxuj43H3zZQSiMjEIIR4kbI4eH4zqfCWPycAwaaS2h5Y1EEiPzrtjOqNykVRCPGA524j6d1SThSxEw+vntkLkMKZs7R1kQHsUF2k2f262klSGHBx9aHavbYzHAUGMXCBInoMuDFDK5APVj2c9HszSEHFA3YDkpYrMHf02pZXvxm6sInTfbJEKqyEHQmKb3n1I3SUXri4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <303A56832F8E0F42AFCF96CD13F21E7A@namprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 334e55e7-27a5-43d4-a296-08d59dd4d7f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 04:46:22.2654 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB0190 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun, 2018-04-08 at 12:08 -0700, Matthew Wilcox wrote: > On Sun, Apr 08, 2018 at 04:40:59PM +0000, Bart Van Assche wrote: > > Do you perhaps want me to prepare a patch that makes blk_get_request() again > > respect the full gfp mask passed as third argument to blk_get_request()? > > I think that would be a good idea. If it's onerous to have extra arguments, > there are some bits in gfp_flags which could be used for your purposes. That's indeed something we can consider. It would be appreciated if you could have a look at the patch below. Thanks, Bart. Subject: block: Make blk_get_request() again respect the entire gfp_t argument Commit 6a15674d1e90 ("block: Introduce blk_get_request_flags()") translates the third blk_get_request() arguments GFP_KERNEL, GFP_NOIO and __GFP_RECLAIM into __GFP_DIRECT_RECLAIM. Make blk_get_request() again pass the full gfp_t argument to blk_old_get_request() such that kswapd is again woken up under low memory conditions if the caller requested this. Notes: - This change only affects the behavior of the legacy block layer. See also the mempool_alloc() call in __get_request(). - The __GFP_RECLAIM flag in the blk_get_request_flags() calls in the IDE and SCSI drivers was removed by commit 039c635f4e66 ("ide, scsi: Tell the block layer at request allocation time about preempt requests"). --- block/blk-core.c | 28 +++++++++++++++------------- drivers/ide/ide-pm.c | 2 +- drivers/scsi/scsi_lib.c | 3 ++- include/linux/blkdev.h | 3 ++- 4 files changed, 20 insertions(+), 16 deletions(-) -- 2.16.2 diff --git a/block/blk-core.c b/block/blk-core.c index 3ac9dd25e04e..83c7a58e4fb3 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1333,6 +1333,7 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr) * @op: operation and flags * @bio: bio to allocate request for (can be %NULL) * @flags: BLQ_MQ_REQ_* flags + * @gfp_mask: allocation mask * * Get a free request from @q. This function may fail under memory * pressure or if @q is dead. @@ -1342,7 +1343,8 @@ int blk_update_nr_requests(struct request_queue *q, unsigned int nr) * Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *__get_request(struct request_list *rl, unsigned int op, - struct bio *bio, blk_mq_req_flags_t flags) + struct bio *bio, blk_mq_req_flags_t flags, + gfp_t gfp_mask) { struct request_queue *q = rl->q; struct request *rq; @@ -1351,8 +1353,6 @@ static struct request *__get_request(struct request_list *rl, unsigned int op, struct io_cq *icq = NULL; const bool is_sync = op_is_sync(op); int may_queue; - gfp_t gfp_mask = flags & BLK_MQ_REQ_NOWAIT ? GFP_ATOMIC : - __GFP_DIRECT_RECLAIM; req_flags_t rq_flags = RQF_ALLOCED; lockdep_assert_held(q->queue_lock); @@ -1516,6 +1516,7 @@ static struct request *__get_request(struct request_list *rl, unsigned int op, * @op: operation and flags * @bio: bio to allocate request for (can be %NULL) * @flags: BLK_MQ_REQ_* flags. + * @gfp_mask: allocation mask * * Get a free request from @q. If %__GFP_DIRECT_RECLAIM is set in @gfp_mask, * this function keeps retrying under memory pressure and fails iff @q is dead. @@ -1525,7 +1526,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op, * Returns request pointer on success, with @q->queue_lock *not held*. */ static struct request *get_request(struct request_queue *q, unsigned int op, - struct bio *bio, blk_mq_req_flags_t flags) + struct bio *bio, blk_mq_req_flags_t flags, + gfp_t gfp_mask) { const bool is_sync = op_is_sync(op); DEFINE_WAIT(wait); @@ -1537,7 +1539,7 @@ static struct request *get_request(struct request_queue *q, unsigned int op, rl = blk_get_rl(q, bio); /* transferred to @rq on success */ retry: - rq = __get_request(rl, op, bio, flags); + rq = __get_request(rl, op, bio, flags, gfp_mask); if (!IS_ERR(rq)) return rq; @@ -1575,11 +1577,10 @@ static struct request *get_request(struct request_queue *q, unsigned int op, /* flags: BLK_MQ_REQ_PREEMPT and/or BLK_MQ_REQ_NOWAIT. */ static struct request *blk_old_get_request(struct request_queue *q, - unsigned int op, blk_mq_req_flags_t flags) + unsigned int op, blk_mq_req_flags_t flags, + gfp_t gfp_mask) { struct request *rq; - gfp_t gfp_mask = flags & BLK_MQ_REQ_NOWAIT ? GFP_ATOMIC : - __GFP_DIRECT_RECLAIM; int ret = 0; WARN_ON_ONCE(q->mq_ops); @@ -1591,7 +1592,7 @@ static struct request *blk_old_get_request(struct request_queue *q, if (ret) return ERR_PTR(ret); spin_lock_irq(q->queue_lock); - rq = get_request(q, op, NULL, flags); + rq = get_request(q, op, NULL, flags, gfp_mask); if (IS_ERR(rq)) { spin_unlock_irq(q->queue_lock); blk_queue_exit(q); @@ -1610,9 +1611,10 @@ static struct request *blk_old_get_request(struct request_queue *q, * @q: request queue to allocate a request for * @op: operation (REQ_OP_*) and REQ_* flags, e.g. REQ_SYNC. * @flags: BLK_MQ_REQ_* flags, e.g. BLK_MQ_REQ_NOWAIT. + * @gfp_mask: allocation mask */ struct request *blk_get_request_flags(struct request_queue *q, unsigned int op, - blk_mq_req_flags_t flags) + blk_mq_req_flags_t flags, gfp_t gfp_mask) { struct request *req; @@ -1624,7 +1626,7 @@ struct request *blk_get_request_flags(struct request_queue *q, unsigned int op, if (!IS_ERR(req) && q->mq_ops->initialize_rq_fn) q->mq_ops->initialize_rq_fn(req); } else { - req = blk_old_get_request(q, op, flags); + req = blk_old_get_request(q, op, flags, gfp_mask); if (!IS_ERR(req) && q->initialize_rq_fn) q->initialize_rq_fn(req); } @@ -1637,7 +1639,7 @@ struct request *blk_get_request(struct request_queue *q, unsigned int op, gfp_t gfp_mask) { return blk_get_request_flags(q, op, gfp_mask & __GFP_DIRECT_RECLAIM ? - 0 : BLK_MQ_REQ_NOWAIT); + 0 : BLK_MQ_REQ_NOWAIT, gfp_mask); } EXPORT_SYMBOL(blk_get_request); @@ -2065,7 +2067,7 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) * Returns with the queue unlocked. */ blk_queue_enter_live(q); - req = get_request(q, bio->bi_opf, bio, 0); + req = get_request(q, bio->bi_opf, bio, 0, GFP_NOIO); if (IS_ERR(req)) { blk_queue_exit(q); __wbt_done(q->rq_wb, wb_acct); diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c index ad8a125defdd..3ddb464b72e6 100644 --- a/drivers/ide/ide-pm.c +++ b/drivers/ide/ide-pm.c @@ -91,7 +91,7 @@ int generic_ide_resume(struct device *dev) memset(&rqpm, 0, sizeof(rqpm)); rq = blk_get_request_flags(drive->queue, REQ_OP_DRV_IN, - BLK_MQ_REQ_PREEMPT); + BLK_MQ_REQ_PREEMPT, __GFP_RECLAIM); ide_req(rq)->type = ATA_PRIV_PM_RESUME; rq->special = &rqpm; rqpm.pm_step = IDE_PM_START_RESUME; diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 0dfec0dedd5e..62d31403767a 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -267,7 +267,8 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, req = blk_get_request_flags(sdev->request_queue, data_direction == DMA_TO_DEVICE ? - REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT); + REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT, + __GFP_RECLAIM); if (IS_ERR(req)) return ret; rq = scsi_req(req); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f2cdf2636974..e0a6a741afd0 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -943,7 +943,8 @@ extern void blk_put_request(struct request *); extern void __blk_put_request(struct request_queue *, struct request *); extern struct request *blk_get_request_flags(struct request_queue *, unsigned int op, - blk_mq_req_flags_t flags); + blk_mq_req_flags_t flags, + gfp_t gfp_mask); extern struct request *blk_get_request(struct request_queue *, unsigned int op, gfp_t gfp_mask); extern void blk_requeue_request(struct request_queue *, struct request *);