Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4731643imm; Mon, 11 Jun 2018 18:20:41 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLPXAsQKNu+FA1GoHBmdh+pVFKyKa4kQgLqVxE9FJuwYQhUNt+LqR/8MLnbwQcqIqVGdIx+ X-Received: by 2002:a65:5003:: with SMTP id f3-v6mr1252401pgo.425.1528766441681; Mon, 11 Jun 2018 18:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528766441; cv=none; d=google.com; s=arc-20160816; b=BRk36sPj4MdI/8GPy8l/VHxRDC0LH1NyEtJDDjh6+02UVwu37aDVb8XvVBqIBtuaZV zIEKqTQPrhVFW4aIvSdm8fBc50QwH4/BcQOMzinUgFw+/9Kkikf9gvtlP6dxIn9z3iTS LDQX+T1oRS7BSSbbjWeAh4Zzad7ppjinovOpJkCaYnIIoSd0adR2CGeHuxCroXZfW1ss jde3dYbt59byOjh7spE5McKoDdUpbee+wp5bJzYzrJzS7+x1i4C1RZ3Vgys2G8PNVS/k vXW+zmqJKBCWUf/AP2SShgmVv/g03Ig78Tim+EgwFYhyWq/C9vrdug6XpPxT/yDzANc+ vJCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=V4AGn+9LkgufB4zANkIpMRfecrTzAsCn3CcKC6SBfbk=; b=iq59AG06ckXsEJ8u/0MVqO/dAihGjuzOd+vhJQTS2Ogd0i9h69nKVeSwG4WE+pgFIQ QyRs+vlNSt4nKncyajrVd02J1AQHL1F028Zb/P9gKgN0bWW9r1pf2M2epHEUBQS00I75 IRU/BBCY2ZqQYnEfPw+4F2adz1UBQla78ItbGdMPDEdzEYW3pdvWmrTQaztjX+liAJ74 GE/dPJD2/MwpI7+YR8+pSZkEed34gWEMazdFbTHHYm0IL1Wz7IhSZ3sSU3Zw43nMzm6C g86Gf+mK8fZhaCiZEGQ5HjkZgG9WqFKHVApqe41+2G5TORws7qquWr/lsSFjlaui+VmC +xlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=mLq/CCQ6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12-v6si5943878plk.485.2018.06.11.18.20.27; Mon, 11 Jun 2018 18:20:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=mLq/CCQ6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934909AbeFLBTE (ORCPT + 99 others); Mon, 11 Jun 2018 21:19:04 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:39574 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934694AbeFLBTB (ORCPT ); Mon, 11 Jun 2018 21:19:01 -0400 Received: by mail-io0-f193.google.com with SMTP id f1-v6so26144791ioh.6 for ; Mon, 11 Jun 2018 18:19:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=V4AGn+9LkgufB4zANkIpMRfecrTzAsCn3CcKC6SBfbk=; b=mLq/CCQ6Pf7SrZVY/7mL/RNNSMdXVQzfFxVL4IP9AfjdtNyzIiydQrtVXPe33+wRO7 RK5nsyk6c7V50Q2l4s9bd+Hj5eGkkba2DyVOjV99HCCWTTPExIvo3Q6p3uunmN7k/84n uPTX/A+4bZ7Jv7bXzXvKD/w2mMVB79PI96xZKtJM84PKCc5gNp8tpJ1K5m9u3gNbGJdr ia64KVQm09st0raD4w8ecOzRsQcdmDcVPLLUfkbu59SlJKiQljtbofahKOfChbtS5hjw lVxV67GvyUcIFkgHdizNcUJ6iEIqXpsQyg6wMqVaZhPrtSnXU5jRBtYcGAqTH+D0tdHs hAwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=V4AGn+9LkgufB4zANkIpMRfecrTzAsCn3CcKC6SBfbk=; b=JzMReH8DxilvdbaWK6Qx+1f1yi1RaOJxneDXRfx0AFCatipkwxGW6PCRGopaDXy4zx FDZsgLQt5mX9pGzDlECRfwbNB3B5gled7kOKw43o0OB6VTT8lEjajvr+hU8Tl8zOBc0e S5VSkQGBwlrrSDfyQq8ciTHJGz8TUmhQ0lcZEjXS+PApTWNRHXR7NaYovBqJG+K25aTJ A47YNJ30Jgm3jYUF2n3BKzLfi2WCrnl63Iq5ZVZslcqqQezYzTOcQLiIpv9ARWGfeQHZ 1gFIAivMyDXgj7HNtWSIzcPuwxL1eoHi8atujmtZk0w9aM0sPwrUAa7MPv06Z8VCmXa/ 8qyA== X-Gm-Message-State: APt69E2JN0XhcY4OxOjAdIXze6WoVTVAtrczusGq1mQpguPir7tQzMdz OyXFC7Kg0qq0f5nJfJAA39/fcQ== X-Received: by 2002:a6b:3446:: with SMTP id b67-v6mr1477125ioa.6.1528766340304; Mon, 11 Jun 2018 18:19:00 -0700 (PDT) Received: from [192.168.1.212] (107.191.0.158.static.utbb.net. [107.191.0.158]) by smtp.gmail.com with ESMTPSA id f12-v6sm4748028itc.41.2018.06.11.18.18.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 18:18:58 -0700 (PDT) Subject: Re: [PATCH 1/2] Convert target drivers to use sbitmap From: Jens Axboe To: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux1394-devel@lists.sourceforge.net, linux-usb@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, Juergen Gross , qla2xxx-upstream@qlogic.com, Kent Overstreet Cc: Matthew Wilcox References: <20180515160043.27044-1-willy@infradead.org> <20180515160043.27044-2-willy@infradead.org> <3a56027b-47bc-dcb8-a465-3670031572f1@kernel.dk> Message-ID: <02326395-3241-c94b-ad70-3de27a6f5a8c@kernel.dk> Date: Mon, 11 Jun 2018 19:18:55 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <3a56027b-47bc-dcb8-a465-3670031572f1@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/15/18 10:11 AM, Jens Axboe wrote: > On 5/15/18 10:00 AM, Matthew Wilcox wrote: >> From: Matthew Wilcox >> >> The sbitmap and the percpu_ida perform essentially the same task, >> allocating tags for commands. Since the sbitmap is more used than >> the percpu_ida, convert the percpu_ida users to the sbitmap API. > > It should also be the same performance as percpu_ida in light use, and > performs much better at > 50% utilization of the tag space. I think > that's better justification than "more used than". > >> diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c >> index 4435bf374d2d..28bcffae609f 100644 >> --- a/drivers/target/iscsi/iscsi_target_util.c >> +++ b/drivers/target/iscsi/iscsi_target_util.c >> @@ -17,7 +17,7 @@ >> ******************************************************************************/ >> >> #include >> -#include >> +#include >> #include /* ipv6_addr_equal() */ >> #include >> #include >> @@ -147,6 +147,28 @@ void iscsit_free_r2ts_from_list(struct iscsi_cmd *cmd) >> spin_unlock_bh(&cmd->r2t_lock); >> } >> >> +int iscsit_wait_for_tag(struct se_session *se_sess, int state, int *cpup) >> +{ >> + int tag = -1; >> + DEFINE_WAIT(wait); >> + struct sbq_wait_state *ws; >> + >> + if (state == TASK_RUNNING) >> + return tag; >> + >> + ws = &se_sess->sess_tag_pool.ws[0]; >> + for (;;) { >> + prepare_to_wait_exclusive(&ws->wait, &wait, state); >> + if (signal_pending_state(state, current)) >> + break; >> + schedule(); >> + tag = sbitmap_queue_get(&se_sess->sess_tag_pool, cpup); >> + } >> + >> + finish_wait(&ws->wait, &wait); >> + return tag; >> +} > > Seems like that should be: > > > ws = &se_sess->sess_tag_pool.ws[0]; > for (;;) { > prepare_to_wait_exclusive(&ws->wait, &wait, state); > if (signal_pending_state(state, current)) > break; > tag = sbitmap_queue_get(&se_sess->sess_tag_pool, cpup); > if (tag != -1) > break; > schedule(); > } > > finish_wait(&ws->wait, &wait); > return tag; > >> /* >> * May be called from software interrupt (timer) context for allocating >> * iSCSI NopINs. >> @@ -155,9 +177,11 @@ struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *conn, int state) >> { >> struct iscsi_cmd *cmd; >> struct se_session *se_sess = conn->sess->se_sess; >> - int size, tag; >> + int size, tag, cpu; >> >> - tag = percpu_ida_alloc(&se_sess->sess_tag_pool, state); >> + tag = sbitmap_queue_get(&se_sess->sess_tag_pool, &cpu); >> + if (tag < 0) >> + tag = iscsit_wait_for_tag(se_sess, state, &cpu); >> if (tag < 0) >> return NULL; > > Might make sense to just roll the whole thing into iscsi_get_tag(), that > would be cleaner. > > sbitmap should provide a helper for that, but we can do that cleanup > later. That would encapsulate things like the per-cpu caching hint too, > for instance. > > Rest looks fine to me. Are you going to push this further? I really think we should. -- Jens Axboe