Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp322747pxu; Thu, 15 Oct 2020 05:03:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzH/0743c7l2ev1ysXwPsp3pPmjBmhb0y4fojOVCgSvykaGJ1zfSPnBII+HVfVwT/BRd6HV X-Received: by 2002:a17:906:cd14:: with SMTP id oz20mr4100125ejb.7.1602763307339; Thu, 15 Oct 2020 05:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602763307; cv=none; d=google.com; s=arc-20160816; b=GXOLs9sD+ukOs9KvWmod79cakC+PpARCrmHwgH6Zoqg1U4PzqW9WyS7kbrika1CdYV Zb1GX0/jZLNB79jNqJjwfF9kK4ojqwMwHieRpnKthlxUOxrBLjwnC1QmwNINK4gZsNMZ KfMSlCpLzSl3qWbqMzZIQibFpJtGCnTm0/qtKao6pzqxBkgl8wisgUys/0ed8FkcdsRH IA+nEwerKEGVAtC0Po+74mRIZpn8ruUsBvkcckK6boIcZvJ38sC+XnZkfhZ9uk3+QmdY J079Ankop1jxzAZjk7PUS9gaUlVlLQRpEJjFKMPwejQsgUH56dxezHds194jEkNQvQYQ dG9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date; bh=20tcYIB7Mguyd+djw41+GrE8TWtb4yWvRA65PDYyDbU=; b=Z020hOMq9yhWVXGW8DGDiEUgw5NZWy6J59WnWSAi9OJhknwTTrQH9r2RyVZdwH0G1b wLMoUoV08uFKSv6oW4WJxtvl0/r4kE91pJSWMgsikzeyyU/b0xjNVt1GSbuL+P3A7zPt wn1i8GFzSSPq2HDJXFYQMVP1PBMlk76zFTQ6IbgSnO99wfvKq1Wtl+RMtJ0LOJpKlVoE BUAkLxiaZOQPxLO0lGQiVIafds/9zWXkDFnqe7Pev56f2cC1ddYh/8D4zjVHAP8IbgS/ XYXnYPjXdnApjl3FqxUUDai0U5oUmrlrgO5/+6YIbxv48QKSKYOF9r7HOygO+wH9MQh1 LEEw== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg18si1798352edb.214.2020.10.15.05.01.14; Thu, 15 Oct 2020 05:01:47 -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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730924AbgJOKAW (ORCPT + 99 others); Thu, 15 Oct 2020 06:00:22 -0400 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]:62700 "EHLO out4436.biz.mail.alibaba.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbgJOKAW (ORCPT ); Thu, 15 Oct 2020 06:00:22 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=richard.weiyang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0UC62.Wb_1602756009; Received: from localhost(mailfrom:richard.weiyang@linux.alibaba.com fp:SMTPD_---0UC62.Wb_1602756009) by smtp.aliyun-inc.com(127.0.0.1); Thu, 15 Oct 2020 18:00:09 +0800 Date: Thu, 15 Oct 2020 18:00:09 +0800 From: Wei Yang To: David Hildenbrand Cc: Wei Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Andrew Morton , "Michael S . Tsirkin" , Jason Wang , Pankaj Gupta Subject: Re: [PATCH v1 02/29] virtio-mem: simplify calculation in virtio_mem_mb_state_prepare_next_mb() Message-ID: <20201015100009.GH86495@L-31X9LVDL-1304.local> Reply-To: Wei Yang References: <20201012125323.17509-1-david@redhat.com> <20201012125323.17509-3-david@redhat.com> <20201015040204.GB86495@L-31X9LVDL-1304.local> <730d6536-f6a6-72e5-327f-00ce1224b730@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <730d6536-f6a6-72e5-327f-00ce1224b730@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 15, 2020 at 10:00:15AM +0200, David Hildenbrand wrote: >On 15.10.20 06:02, Wei Yang wrote: >> On Mon, Oct 12, 2020 at 02:52:56PM +0200, David Hildenbrand wrote: >>> We actually need one byte less (next_mb_id is exclusive, first_mb_id is >>> inclusive). Simplify. >>> >>> Cc: "Michael S. Tsirkin" >>> Cc: Jason Wang >>> Cc: Pankaj Gupta >>> Signed-off-by: David Hildenbrand >>> --- >>> drivers/virtio/virtio_mem.c | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c >>> index a1f5bf7a571a..670b3faf412d 100644 >>> --- a/drivers/virtio/virtio_mem.c >>> +++ b/drivers/virtio/virtio_mem.c >>> @@ -257,8 +257,8 @@ static enum virtio_mem_mb_state virtio_mem_mb_get_state(struct virtio_mem *vm, >>> */ >>> static int virtio_mem_mb_state_prepare_next_mb(struct virtio_mem *vm) >>> { >>> - unsigned long old_bytes = vm->next_mb_id - vm->first_mb_id + 1; >>> - unsigned long new_bytes = vm->next_mb_id - vm->first_mb_id + 2; >>> + unsigned long old_bytes = vm->next_mb_id - vm->first_mb_id; >>> + unsigned long new_bytes = old_bytes + 1; >> >> This is correct. >> >> So this looks more like a fix? > >We allocate an additional new page "one memory block too early". > >So we would allocate the first page for blocks 0..510, and already >allocate the second page with block 511, although we could have fit it >into the first page. Block 512 will then find that the second page is >already there and simply use the second page. > >So as we do it consistently, nothing will go wrong - that's why I >avoided using the "fix" terminology. > Yes, my feeling is this is not a simplification. Instead this is a more precise calculation. How about use this subject? virtio-mem: more precise calculation in virtio_mem_mb_state_prepare_next_mb() >Thanks! > >-- >Thanks, > >David / dhildenb -- Wei Yang Help you, Help me