From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?windows-1252?Q?Roger_Pau_Monn=E9?= Subject: Re: [PATCHv4 12/14] xen-blkback: safely unmap grants in case they are still in use Date: Mon, 26 Jan 2015 20:21:34 +0100 Message-ID: <54C693BE.6050901@citrix.com> References: <1422291687-7398-1-git-send-email-david.vrabel@citrix.com> <1422291687-7398-13-git-send-email-david.vrabel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YFpEE-0004TU-5E for xen-devel@lists.xenproject.org; Mon, 26 Jan 2015 19:21:42 +0000 In-Reply-To: <1422291687-7398-13-git-send-email-david.vrabel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: David Vrabel , xen-devel@lists.xenproject.org Cc: Boris Ostrovsky , Jennifer Herbert List-Id: xen-devel@lists.xenproject.org El 26/01/15 a les 18.01, David Vrabel ha escrit: > From: Jennifer Herbert > = > Use gnttab_unmap_refs_async() to wait until the mapped pages are no > longer in use before unmapping them. > = > This allows blkback to use network storage which may retain refs to > pages in queued skbs after the block I/O has completed. > = > Signed-off-by: Jennifer Herbert > Signed-off-by: David Vrabel Acked-by: Roger Pau Monn=E9 This looks fine, only one comment below. [...] > +/* > + * Unmap the grant references, and also remove the M2P over-rides > + * used in the 'pending_req'. > + */ > +static void xen_blkbk_unmap(struct xen_blkif *blkif, > + struct grant_page *pages[], > + int num) > +{ > + struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; > + struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; > + unsigned int invcount =3D 0; > + int ret; > + > + while (num) { > + unsigned int batch =3D min(num, BLKIF_MAX_SEGMENTS_PER_REQUEST); > + = > + invcount =3D xen_blkbk_unmap_prepare(blkif, pages, batch, > + unmap, unmap_pages); > + if (invcount) { > + ret =3D gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); > BUG_ON(ret); > put_free_pages(blkif, unmap_pages, invcount); > - invcount =3D 0; > } > - } > - if (invcount) { > - ret =3D gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); > - BUG_ON(ret); > - put_free_pages(blkif, unmap_pages, invcount); > + pages +=3D batch; > + num -=3D batch; Could you add a comment explaining that the loop is not optimal if the pages array contains both persistent and non-persistent grants? Roger.