Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp589764pxb; Wed, 27 Jan 2021 16:02:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYtKn3S62kofy+xbqL19Q6aojl4d2hUEKE9NsYagw8EaJu136o7DImjduo6b4KvXDbsT3u X-Received: by 2002:a17:906:d7:: with SMTP id 23mr6373344eji.108.1611792148575; Wed, 27 Jan 2021 16:02:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611792148; cv=none; d=google.com; s=arc-20160816; b=eI2s1LuMxPYuO++Fe5k+lqk7j1YzFRd/dN2yPLQzcEMVZFyU9Xuk5xCE0WTJ4YB5K3 kk70wBrMQrxbqb4VICwxIIYUJGKweXu7OCYFnxT9uZJCWpkNe+9uyAPuzoj6HpPss7af YRR6yxdVRb3W1bDACsrs4XGgVlYe5+HNnSlYOwrebQySvy+zpXN8x+bgYpIMCsTk49Aq Up+5KiRq9GyhM7FAvnOyiCiaP3yDMcy5R2/FTIlCWsPNKk7lflWHVyDIK4ZfQBWlFVHo ULlHfqyXysukbuX1GEWw4xwxPBca7Ft4omYd/JImJG8oTnk34ADMHRETVofUK8/0kY9l haHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=PqIH+nVCrp+fobM2GwV28HbVRTcGonkOn50Q6k34F6U=; b=idtt4WytagmPFw04qAwgv3XlSveEN33N1J5Td4IcItDlrEvHnEtDBkYBGXfeR92224 52DSnLvjBz3CbIS99K4LmY92PRM7HCODvNsOtSpdBgbjBcGWId+pte3L+STiQdpufWv7 ir3F3Zil5KlvcuJqo/YqZgJ4bMua3Z7/VtSPbldr/gjC8vz+zVGhI0WvCD6oq6eP6QAu UgMs1theL506S2V+X6fqnG9YFh84vjyun28FaeWATT7J0EydSvY7kP4bgqgMNpxknIrk WxU91ptYLY0JySLExaMT0Z4jZl/nNrLksJbLMjH/1NAJY6KMc40QH0eCCG/NQVrW9aZh Lhkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=KsYpOtT+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si1804904edc.56.2021.01.27.16.02.04; Wed, 27 Jan 2021 16:02:28 -0800 (PST) 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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=KsYpOtT+; 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=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343641AbhA0PQE (ORCPT + 99 others); Wed, 27 Jan 2021 10:16:04 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:30681 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235428AbhA0POe (ORCPT ); Wed, 27 Jan 2021 10:14:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611760474; x=1643296474; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Vas6vzHGrww2zViujLO89n+jvEzx6usSOUxeeboPCy0=; b=KsYpOtT+j2da7IBvHQfgQA57aBpTPmhWYnQfGSlR9/nXREN6lmNNf0Hs w72QBWC/vuKzSGlrR/kJg/MQcBHdtptmSy7EiZJvbDH70jQB8HbVQFzD2 Nkmxwg7QRfCkGTGwTak3BgCMApZJ/ZPwmw/LXwAQTkMswK2TjuLGdbPHg k3DkjQSKLMgCB2eA7F3cPYh/weFZZXea3wd5yZGV8vHQsCO4BDlasJ2/y 5PVKrkukHLj/al3jqq9sJRJMHuJU3vRI33o1gH3GoIo7ItiROkB33Yddf UUJejS/aPVkbEqJW8Th/1xTzghzL8kSKIy7VHv2c8tEe4pRicESUghZLG A==; IronPort-SDR: CKpC2PQqpieDUCpgSwtHAqea8m9MiqatktAj2uVZGRScfrGH/SIOzuW2QxgDtg3/GujuD1s9Ln c5KuJCsOduUuJ26mns6OMbpKYsWJ271b8uENmnmL5OobKfCgTZTDkE6gSt4KchHRUhIqgqXKJz RLQxXkkI1wrGtKyBn4rruq7h0DUy76iDqAEqVT8Vut3esOuQ8hu7Qhp4SBfd6AsplHFfdINdZ/ tcRKfXWcQNJkcgZrdTmUVH0KBANLCPjAL43cQN9rf3TWGGTRycMQJaj88h5IvDZ15PKCbhQH/2 h0E= X-IronPort-AV: E=Sophos;i="5.79,379,1602518400"; d="scan'208";a="158454216" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Jan 2021 23:13:15 +0800 IronPort-SDR: Q1QhEK+BDVTxgKcbnvbh9gMlWPcj1ZQISaVximfggfQe0EjQ2N81UhcyxLiHuORwku/OlzT4sj 58lC85miidCo5K+x12qJp7bZcW6g+LILUni2QEZnun4uWT/TPJQMEhGLmnS8+FSgkzXJPV6g8p S0BPto12LN0UedXbYtQIn0mKWxJ0tZ7sYHs3H8HtOLzfStenvMFkY9wt53OnAXYZoG0PiA6EG5 0oV0VtadNRE5TnjLt9jfzYbHh36pPR+vrX78bwW5rg6+Vbm3kEvhR9zlHd29lxtxmAN/qeq92d al+kWeAyDGl0J7hffmjImxxp Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 06:57:36 -0800 IronPort-SDR: w64i1XuSCkd1qWhfzqgpJYu/6un6gWY5MG5cMco/LTb0oWD2ot+QiV2kbuxzecbkMtSV4YRWPm lPGZvhbtkE52hm2QrE1N60R4E44rdvU5Xz3NHlY28Vbhz/ttPXF9PdDiTFCLsJD7pVOVB+E57t bsrqGbSG08jANbj7G4moWJIv6Yow31nlL8gOEw94LoQYGeKMgVlFvjuh6Qo++a4UVk/Dhf3mvT AHrYZdQ3uoElBZ0SvI8tNxqhey2ROcl3Ip8DtJQZRJW8Pl6yzu9qu5ZCpI7WavnuixWkmxzvvk 5LU= WDCIronportException: Internal Received: from bxygm33.sdcorp.global.sandisk.com ([10.0.231.247]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2021 07:13:11 -0800 From: Avri Altman To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, Bart Van Assche , yongmyung lee , Daejun Park , alim.akhtar@samsung.com, asutoshd@codeaurora.org, Zang Leigang , Avi Shchislowski , Bean Huo , cang@codeaurora.org, stanley.chu@mediatek.com, Avri Altman Subject: [PATCH 4/8] scsi: ufshpb: Make eviction depends on region's reads Date: Wed, 27 Jan 2021 17:12:13 +0200 Message-Id: <20210127151217.24760-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127151217.24760-1-avri.altman@wdc.com> References: <20210127151217.24760-1-avri.altman@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In host mode, eviction is considered an extreme measure. verify that the entering region has enough reads, and the exiting region has much less reads. Signed-off-by: Avri Altman --- drivers/scsi/ufs/ufshpb.c | 44 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 51c3607166bc..a16c0f2d5fac 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -18,6 +18,7 @@ #define WORK_PENDING 0 #define ACTIVATION_THRSHLD 4 /* 4 IOs */ +#define EVICTION_THRSHLD (ACTIVATION_THRSHLD << 6) /* 256 IOs */ /* memory management */ static struct kmem_cache *ufshpb_mctx_cache; @@ -639,6 +640,14 @@ static struct ufshpb_region *ufshpb_victim_lru_info(struct ufshpb_lu *hpb) if (ufshpb_check_srgns_issue_state(hpb, rgn)) continue; + /* + * in host control mode, verify that the exiting region + * has less reads + */ + if (ufshpb_mode == HPB_HOST_CONTROL && + atomic64_read(&rgn->reads) > (EVICTION_THRSHLD >> 1)) + continue; + victim_rgn = rgn; break; } @@ -789,7 +798,7 @@ static int ufshpb_issue_map_req(struct ufshpb_lu *hpb, static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) { - struct ufshpb_region *victim_rgn; + struct ufshpb_region *victim_rgn = NULL; struct victim_select_info *lru_info = &hpb->lru_info; unsigned long flags; int ret = 0; @@ -817,6 +826,17 @@ static int ufshpb_add_region(struct ufshpb_lu *hpb, struct ufshpb_region *rgn) * because the device could detect this region * by not issuing HPB_READ */ + + /* + * in host control mode, verify that the entering + * region has enough reads + */ + if (ufshpb_mode == HPB_HOST_CONTROL && + atomic64_read(&rgn->reads) < EVICTION_THRSHLD) { + ret = -EACCES; + goto out; + } + victim_rgn = ufshpb_victim_lru_info(hpb); if (!victim_rgn) { dev_warn(&hpb->sdev_ufs_lu->sdev_dev, @@ -1024,8 +1044,13 @@ static void ufshpb_run_active_subregion_list(struct ufshpb_lu *hpb) rgn = hpb->rgn_tbl + srgn->rgn_idx; ret = ufshpb_add_region(hpb, rgn); - if (ret) - goto active_failed; + if (ret) { + if (ret == -EACCES) { + spin_lock_irqsave(&hpb->rsp_list_lock, flags); + continue; + } + goto add_region_failed; + } ret = ufshpb_issue_map_req(hpb, rgn, srgn); if (ret) { @@ -1039,9 +1064,22 @@ static void ufshpb_run_active_subregion_list(struct ufshpb_lu *hpb) spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); return; +add_region_failed: + if (ufshpb_mode == HPB_HOST_CONTROL) { + /* + * In host control mode, it is common that eviction trials + * fail, either because the entering region didn't have enough + * reads, or a poor-performing exiting region wasn't found. + * No need to re-insert those regions to the "to-be-activated" + * list. + */ + return; + } + active_failed: dev_err(&hpb->sdev_ufs_lu->sdev_dev, "failed to activate region %d - %d, will retry\n", rgn->rgn_idx, srgn->srgn_idx); + spin_lock_irqsave(&hpb->rsp_list_lock, flags); ufshpb_add_active_list(hpb, rgn, srgn); spin_unlock_irqrestore(&hpb->rsp_list_lock, flags); -- 2.25.1