Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2400756pxb; Fri, 17 Sep 2021 08:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwqvg6FBqucOgNEeKf/pJlbSWsACVgzTbRcKVi5pNgrU0BYJy8FL7BKTG+X26plRGbsDfY X-Received: by 2002:a05:6402:16d1:: with SMTP id r17mr7655374edx.378.1631894320785; Fri, 17 Sep 2021 08:58:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631894320; cv=none; d=google.com; s=arc-20160816; b=OqdGyuVM/y8Az+hduiTSMXAwUdq6Ls1Vr8xARlZlCqDX/ehnKJqgkrUgOjEhZoesQ+ I/15LSnQYavGcLhpFTwreN8zuD9ltIe/B4OWSqoECGlYUTS/Oz6qFeE/25LCZ1Wev13G uTPNuQihono4ksoBGNBFKUngoehSgdUe1HlrdHF9Ili4Qv1pfVv6u4V17USyzOxeaMPr qbkbqjobkvMD/55431hhpbY2dr5g/mFmi0Kvt6tghINxSJn3swxLqceX6WnRoVR423Uk GJBYHD+0W+R+oFpDzoc+xNYsaMLiPHg/5dpBJCeSc9Jap9/ni0+B6vymNsp2ReABy5FL lLFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=TeaMkfSGUoArETTYOgnGUhGKvDN1kw0+AaJYlHgvDHM=; b=qWAN7AQJmsoBJSZkaVTyp5+2uCyOzSmsUavXB4xKbX2ZwtnTqMXOAuh6Sk8N/EDtCD kAY18eVAhdYH4ywrUD6aahMCK7dK//QO0KCSsFpo7m2PMfclzGw+oohymsDsU63GIph/ FRRjDRtkj6XyoMGK7P/M1hdiTURpoojQSKa50XdyXnaSdwgxnvF2hnM66Nbzqmcz/A/+ wXa1mioPSIR6mNeQRpsX98l3/ajzFFx8pTcIxt3tNSjrPyofUQUOlBeauxA3Vr8rxWSr +ebGDk+p+/229VSFt2nz/Bf72Y7ectzsgSpHVYDnpuonNtOdTkT5C6Xr9FZAOAP3TInw +zhA== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si7682850ejl.218.2021.09.17.08.58.17; Fri, 17 Sep 2021 08:58:40 -0700 (PDT) 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; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243031AbhIQC5n (ORCPT + 99 others); Thu, 16 Sep 2021 22:57:43 -0400 Received: from mga01.intel.com ([192.55.52.88]:40280 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234959AbhIQC5n (ORCPT ); Thu, 16 Sep 2021 22:57:43 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10109"; a="245098920" X-IronPort-AV: E=Sophos;i="5.85,299,1624345200"; d="scan'208";a="245098920" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2021 19:56:21 -0700 X-IronPort-AV: E=Sophos;i="5.85,299,1624345200"; d="scan'208";a="546107273" Received: from gao-cwp.sh.intel.com (HELO gao-cwp) ([10.239.159.133]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Sep 2021 19:56:19 -0700 Date: Fri, 17 Sep 2021 11:03:35 +0800 From: Chao Gao To: Konrad Rzeszutek Wilk Cc: Konrad Rzeszutek Wilk , Christoph Hellwig , Marek Szyprowski , Robin Murphy , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH] swiotlb: allocate memory in a cache-friendly way Message-ID: <20210917030334.GA20257@gao-cwp> References: <20210901042135.103981-1-chao.gao@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 16, 2021 at 11:49:39AM -0400, Konrad Rzeszutek Wilk wrote: >On Wed, Sep 01, 2021 at 12:21:35PM +0800, Chao Gao wrote: >> Currently, swiotlb uses a global index to indicate the starting point >> of next search. The index increases from 0 to the number of slots - 1 >> and then wraps around. It is straightforward but not cache-friendly >> because the "oldest" slot in swiotlb tends to be used first. >> >> Freed slots are probably accessed right before being freed, especially >> in VM's case (device backends access them in DMA_TO_DEVICE mode; guest >> accesses them in other DMA modes). Thus those just freed slots may >> reside in cache. Then reusing those just freed slots can reduce cache >> misses. >> >> To that end, maintain a free list for free slots and insert freed slots >> from the head and searching for free slots always starts from the head. >> >> With this optimization, network throughput of sending data from host to >> guest, measured by iperf3, increases by 7%. > >Wow, that is pretty awesome! > >Are there any other benchmarks that you ran that showed a negative >performance? TBH, yes. Recently I do fio tests with this patch. The impact of this patch is: (+ means performance improvement; - means performance regression) 1-job fio: randread: +6.7% randwrite: -1.6% read: +8.2% write: +7.4% 8-job fio: randread: -5.5% randwrite: -12.6% read: -24.8% write: -45.5% I haven't figured out why multi-job fio tests suffer. Will post v2 once the issue gets resolved. Thanks Chao