From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1daT3Z-0008VL-Oz for qemu-devel@nongnu.org; Wed, 26 Jul 2017 16:37:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1daT3W-0004UZ-N7 for qemu-devel@nongnu.org; Wed, 26 Jul 2017 16:37:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1daT3W-0004UI-DC for qemu-devel@nongnu.org; Wed, 26 Jul 2017 16:37:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20EDB3E2C0 for ; Wed, 26 Jul 2017 20:37:17 +0000 (UTC) Date: Wed, 26 Jul 2017 23:37:13 +0300 From: "Michael S. Tsirkin" Message-ID: <20170726233613-mutt-send-email-mst@kernel.org> References: <1499847223-8078-1-git-send-email-peterx@redhat.com> <1499847223-8078-5-git-send-email-peterx@redhat.com> <0850f338-98a2-614a-c8bd-3407c9b5a485@redhat.com> <20170714043241.GK27284@pxdev.xzpeter.org> <14784c80-2b88-1994-9d50-7d39dc72a808@redhat.com> <20170717015327.GQ27284@pxdev.xzpeter.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20170717015327.GQ27284@pxdev.xzpeter.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 4/4] intel_iommu: implement mru list for iotlb List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: Jason Wang , qemu-devel@nongnu.org On Mon, Jul 17, 2017 at 09:53:27AM +0800, Peter Xu wrote: > On Fri, Jul 14, 2017 at 03:28:09PM +0800, Jason Wang wrote: > >=20 > >=20 > > On 2017=E5=B9=B407=E6=9C=8814=E6=97=A5 12:32, Peter Xu wrote: > > >On Thu, Jul 13, 2017 at 04:48:42PM +0800, Jason Wang wrote: > > >> > > >>On 2017=E5=B9=B407=E6=9C=8812=E6=97=A5 16:13, Peter Xu wrote: > > >>>It is not wise to disgard all the IOTLB cache when cache size reac= hes > > >>>max, but that's what we do now. A slightly better (but still simpl= e) way > > >>>to do this is, we just throw away the least recent used cache entr= y. > > >>> > > >>>This patch implemented MRU list algorithm for VT-d IOTLB. The main= logic > > >>>is to maintain a Most Recently Used list for the IOTLB entries. Th= e hash > > >>>table is still used for lookup, though a new list field is added t= o each > > >>>IOTLB entry for a iotlb MRU list. For each active IOTLB entry, it'= s both > > >>>in the hash table in s->iotlb, and also linked into the MRU list o= f > > >>>s->iotlb_head. The hash helps in fast lookup, and the MRU list hel= ps in > > >>>knowing whether the cache is still hot. > > >>> > > >>>After we have such a MRU list, replacing all the iterators of IOTL= B > > >>>entries by using list iterations rather than hash table iterations= . > > >>Any reason of doing this, I thought hashtable was even a little bit= faster? > > >Could I ask why? > > > > > >I thought they are merely the same (when iterating all the items)? > > > > >=20 > > Ok, looks like I was wrong, but it they are merely the same, why both= er? >=20 > Because imho looping over list needs fewer LOCs and is also more > direct. E.g., for domain flush, hash needs this: >=20 > static gboolean vtd_hash_remove_by_domain(gpointer key, gpointer value, > gpointer user_data) > { > VTDIOTLBEntry *entry =3D (VTDIOTLBEntry *)value; > uint16_t domain_id =3D *(uint16_t *)user_data; > return entry->domain_id =3D=3D domain_id; > } >=20 > Then: >=20 > g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_domain, > &domain_id); >=20 > For list it is only: >=20 > FOREACH_IOTLB_SAFE(entry, s, entry_n) { > if (entry->domain_id =3D=3D domain_id) { > vtd_iotlb_remove_entry(s, entry); > } > } >=20 > Thanks, Well the LOC seems to have gone up with this patch. If we are trying to simplify code, please state this in commit log. > --=20 > Peter Xu