Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AD94C433DF for ; Wed, 20 May 2020 15:56:44 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFBC020671 for ; Wed, 20 May 2020 15:56:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFBC020671 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbR57-0008Fg-2g; Wed, 20 May 2020 15:56:33 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jbR55-0008FS-Cy for xen-devel@lists.xenproject.org; Wed, 20 May 2020 15:56:31 +0000 X-Inumbo-ID: 78704b60-9ab2-11ea-ae69-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 78704b60-9ab2-11ea-ae69-bc764e2007e4; Wed, 20 May 2020 15:56:30 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: huEG3xWiDCZyS+UsXq1qLYEvn4On/A+8tuklwQxifEsjCpsyoR4RgKAybu41l1kw/ESMuBa/n2 uWRedc87mXLU3kj/MHcPJcayn5uq93XrsfkCKd6dt8spKJDHxn7P/ChTopgPqJkawdMY5QS8vc 6vVNOTBRw93PCkozaEQS7lI0nsVN6RSCqItx3zHc73NUXg1QMMieRe3/YzxYfNHQC9bPd0IuaC nroz7Gu/0CtK/0/O9zjLiVk2Ds1W4I3E83aMwDprihz/GWitkr6eyACPiBgwCoBaZX4epMKQg8 TIA= X-SBRS: 2.7 X-MesageID: 18368514 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.73,414,1583211600"; d="scan'208";a="18368514" Date: Wed, 20 May 2020 17:56:21 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Ian Jackson Subject: Re: [PATCH] tools/libxengnttab: correct size of allocated memory Message-ID: <20200520155621.GN54375@Air-de-Roger> References: <20200520083501.31704-1-jgross@suse.com> <24261.17303.413916.29534@mariner.uk.xensource.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <24261.17303.413916.29534@mariner.uk.xensource.com> X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To AMSPEX02CL02.citrite.net (10.69.22.126) X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , "xen-devel@lists.xenproject.org" , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Wed, May 20, 2020 at 03:49:59PM +0100, Ian Jackson wrote: > Juergen Gross writes ("[PATCH] tools/libxengnttab: correct size of allocated memory"): > > The size of the memory allocated for the IOCTL_GNTDEV_MAP_GRANT_REF > > ioctl() parameters is calculated wrong, which results in too much > > memory allocated. > > Added Roger to CC. > > Firstly, > > Reviewed-by: Ian Jackson For the FreeBSD bits: Reviewed-by: Roger Pau Monné > > Thank you. > > > But, looking at this code, why on earth what the ? > > The FreeBSD code checks to see if it's less than a page and if so uses > malloc and otherwise uses mmap ! Why not unconditionally use malloc ? > > Likewise, the Linux code has its own mmap-based memory-obtainer. ISTM > that malloc is probably going to be better. Often it will be able to > give out even a substantial amount without making a syscall. > > Essentially, we have two (similar but not identical) tiny custom > memory allocators here. Also, the Linux and FreeBSD code are > remarkably similar which bothers me. Right. This is due to the FreeBSD file being mostly a clone of the Linux one. I agree the duplication could be abstracted away. I really have no idea why malloc or mmap is used, maybe at some point requesting regions > PAGE_SIZE was considered faster using mmap directly? Thanks, Roger.