Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp1412379lqj; Tue, 4 Jun 2024 00:01:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDxl4s+ee4DuFGqTKkLahSfqVKMZHvjXVChUChAVL8Q6HmznNhYavd5BhHUzX6Ie8t5wi0pyPZ5wzTFLj5zXDo6OVu3619q8PVRaLptg== X-Google-Smtp-Source: AGHT+IG3BRzm2KyFnHTs/W/F4EpH+XRti2gicp0WvwggBSOngal9GU0gkOufRF067HRgt9RBoUSF X-Received: by 2002:a9d:69c2:0:b0:6f1:3bff:be3e with SMTP id 46e09a7af769-6f911f1fcb4mr13214135a34.5.1717484506706; Tue, 04 Jun 2024 00:01:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717484506; cv=pass; d=google.com; s=arc-20160816; b=o+BF/iS/OtXE21QCUKxEqFYkbZJSC16PEUjEsKANYnFR/V9aGdASN0nZkoj60F56n9 agLea2Jokq0IWHhNH9rb7OTN8KKY2W2LKaJNpdO/OmNdSd61qcuK0c0Ep6AxWpKgYkI+ QQPphaqFdG/yYElzp+blq8xzpn1QTzlM5mso42VDyEgSL2c7w8IFp8es+oeM2+0sU0lA JkLH0IqIuV2po1qfcqBYxXHtkGAdhNQ3bhYT4wWoJKvhfpcM3kAUAu1OWv3hLn4ftXZd KCzq6LXAuQa1D6vCjKW8UXQUj2OrK/lSaFrPTApSzOu/Aol2HphDXXakLAVLCD+Ptmzu FF6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=SSjWULV7NdedHqf/oEF2qRlLFo9lWGz4RPzNyrLRq9o=; fh=3U02CRf/V2zVzBV3fBylGC9UNWKoVAXxEyX/R7BoJgo=; b=QX8JYETW95eJAV0ptzaDmFhQJKo/b8lSfgG8Z6wB/+CF/NW8qaAsAVkIkNa3pyDS4k tV5fCu4k83NAfDnQh4+6kI3MFdMoqb/aQogNNrVbIMAlH4U7vsopCuuIVaTboeO0GFqT jYaj505nim0DU+3TsOTYRN+XN1TM/wQ2y7j8bG2vCaA4+B+6/CH04ZJnqcSqufwZVJZB Ybo5613AKhjvPmGjYa3t9w8MKyjMukqpZSDP3tv/aspL7I/R8lvabz0vQruK5Aw1cz4a ly8nfvhtGqMFKD5tKmcB2iWw7rupsz4cjFEbcOM73ih0draHLQaIDGW7P92xT/oYbc31 6vSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-200127-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200127-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-43ff259f5a6si104852561cf.642.2024.06.04.00.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 00:01:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200127-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-200127-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200127-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6DF081C22B61 for ; Tue, 4 Jun 2024 07:01:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 260B613F45D; Tue, 4 Jun 2024 07:01:38 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3E242209B; Tue, 4 Jun 2024 07:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717484497; cv=none; b=VMQ29rNZ9W0tcpMo1KjUdrT0wCoVnwi6/Xp2HCBsMiPEYhr++/xs+ZBSWwU5BzYOQg7f2jif/2gi3winuy4MpGsSPTQLH9skz1KYZwVUFB6hTwou9V/S5CcfHt7U1bu5gCYkZ5v0J5AL7acWFJPrcQgt0yj9q8eA3ht2ndL++N0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717484497; c=relaxed/simple; bh=PYwQcc4hO1AFYN/zQdNCGfsqlcAjCdxu5bhH8nLjHv0=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=QVujDSvBLXFvki4oV5Ho8+YqLVPpSKZGaSadAeqplflO7e1VPacuQ/Zrsbax1GVeST20NT78enrZIf46H8BPifKjwfcUtJx1DGhBoKHxOxNPtsky+KPyR5MQKPSC9y1gFS4PIz1+bS35lxBUQPXynHyzXodncip29avoPWMpDDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VthMg6H2hz4f3n6k; Tue, 4 Jun 2024 15:01:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id ED10F1A0184; Tue, 4 Jun 2024 15:01:30 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgAn9g7Ju15mYh0cOg--.37550S3; Tue, 04 Jun 2024 15:01:30 +0800 (CST) Subject: Re: [PATCH -next] blk-wbt: don't throttle swap writes in direct reclaim To: libaokun@huaweicloud.com, linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, linux-kernel@vger.kernel.org, yangerkun@huawei.com, houtao1@huawei.com, libaokun1@huawei.com, "yukuai (C)" References: <20240604030522.3686177-1-libaokun@huaweicloud.com> From: Yu Kuai Message-ID: <8b17831e-0132-17af-7ec0-6e05057c3530@huaweicloud.com> Date: Tue, 4 Jun 2024 15:01:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240604030522.3686177-1-libaokun@huaweicloud.com> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn9g7Ju15mYh0cOg--.37550S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZFW8Xry5Kr48Cr45uw4Durg_yoW5uw47pr 43Kas0yFyqvFn7Xws7XayxX3yru3y8Jr43A345Kr1SvrW3Kr13WF4vkw1a9F4UAr97uw42 gF4Fyry7Jr4avaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWrJr0_WFyUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv 6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ ?? 2024/06/04 11:05, libaokun@huaweicloud.com ะด??: > From: Baokun Li > > Now we avoid throttling swap writes by determining whether the current > process is kswapd (aka current_is_kswapd()), but swap writes can come > from either kswapd or direct reclaim, so the swap writes from direct > reclaim will still be throttled. > > When a process holds a lock to allocate a free page, and enters direct > reclaim because there is no free memory, then it might trigger a hung > due to the wbt throttling that causes other processes to fail to get > the lock. > > Both kswapd and direct reclaim set the REQ_SWAP flag, so use REQ_SWAP > instead of current_is_kswapd() to avoid throttling swap writes. Also > renamed WBT_KSWAPD to WBT_SWAP and WBT_RWQ_KSWAPD to WBT_RWQ_SWAP. > > Signed-off-by: Baokun Li LGTM Reviewed-by: Yu Kuai > --- > block/blk-wbt.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/block/blk-wbt.c b/block/blk-wbt.c > index 64472134dd26..aaacf2f5b223 100644 > --- a/block/blk-wbt.c > +++ b/block/blk-wbt.c > @@ -37,7 +37,7 @@ > enum wbt_flags { > WBT_TRACKED = 1, /* write, tracked for throttling */ > WBT_READ = 2, /* read */ > - WBT_KSWAPD = 4, /* write, from kswapd */ > + WBT_SWAP = 4, /* write, from swap_writepage() */ > WBT_DISCARD = 8, /* discard */ > > WBT_NR_BITS = 4, /* number of bits */ > @@ -45,7 +45,7 @@ enum wbt_flags { > > enum { > WBT_RWQ_BG = 0, > - WBT_RWQ_KSWAPD, > + WBT_RWQ_SWAP, > WBT_RWQ_DISCARD, > WBT_NUM_RWQ, > }; > @@ -172,8 +172,8 @@ static bool wb_recent_wait(struct rq_wb *rwb) > static inline struct rq_wait *get_rq_wait(struct rq_wb *rwb, > enum wbt_flags wb_acct) > { > - if (wb_acct & WBT_KSWAPD) > - return &rwb->rq_wait[WBT_RWQ_KSWAPD]; > + if (wb_acct & WBT_SWAP) > + return &rwb->rq_wait[WBT_RWQ_SWAP]; > else if (wb_acct & WBT_DISCARD) > return &rwb->rq_wait[WBT_RWQ_DISCARD]; > > @@ -528,7 +528,7 @@ static bool close_io(struct rq_wb *rwb) > time_before(now, rwb->last_comp + HZ / 10); > } > > -#define REQ_HIPRIO (REQ_SYNC | REQ_META | REQ_PRIO) > +#define REQ_HIPRIO (REQ_SYNC | REQ_META | REQ_PRIO | REQ_SWAP) > > static inline unsigned int get_limit(struct rq_wb *rwb, blk_opf_t opf) > { > @@ -539,13 +539,13 @@ static inline unsigned int get_limit(struct rq_wb *rwb, blk_opf_t opf) > > /* > * At this point we know it's a buffered write. If this is > - * kswapd trying to free memory, or REQ_SYNC is set, then > + * swap trying to free memory, or REQ_SYNC is set, then > * it's WB_SYNC_ALL writeback, and we'll use the max limit for > * that. If the write is marked as a background write, then use > * the idle limit, or go to normal if we haven't had competing > * IO for a bit. > */ > - if ((opf & REQ_HIPRIO) || wb_recent_wait(rwb) || current_is_kswapd()) > + if ((opf & REQ_HIPRIO) || wb_recent_wait(rwb)) > limit = rwb->rq_depth.max_depth; > else if ((opf & REQ_BACKGROUND) || close_io(rwb)) { > /* > @@ -622,8 +622,8 @@ static enum wbt_flags bio_to_wbt_flags(struct rq_wb *rwb, struct bio *bio) > if (bio_op(bio) == REQ_OP_READ) { > flags = WBT_READ; > } else if (wbt_should_throttle(bio)) { > - if (current_is_kswapd()) > - flags |= WBT_KSWAPD; > + if (bio->bi_opf & REQ_SWAP) > + flags |= WBT_SWAP; > if (bio_op(bio) == REQ_OP_DISCARD) > flags |= WBT_DISCARD; > flags |= WBT_TRACKED; >