Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp35581ybh; Fri, 6 Mar 2020 15:22:01 -0800 (PST) X-Google-Smtp-Source: ADFU+vun0fu1icjcdKYhdpcLtDbPicAUkgmHgf2AZQ1N63KjuuqaSmpahfPYRlc7JrKDhT3NAmUL X-Received: by 2002:aca:b487:: with SMTP id d129mr2050534oif.154.1583536921471; Fri, 06 Mar 2020 15:22:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583536921; cv=none; d=google.com; s=arc-20160816; b=CDIoHZAugLOMz4vZ5yOVSi2XuxbJatPYFp07nKATyKhkh8YYpzA/gB48j7MoEhuPHz FbjksM3kDeNGxFG6hMG2cVGcmtkmYhwPMlIO5zr4VKgnfQ7sR0WjxxBz3xSJuUmdqgYl U60AyDZo0rXoC7kPiH3V+jOQXHdOl8OWnxHUKy0aX3Q/sQfLlt/oivzs1gAcHnKPVsuu pR+xkevpaLpqP1E3Ls/T3niqhVUdbFjhImmHbJPAx3FBDAW99+4Ds3m9sRzXzQudzuLs YrMl/WYQ53thfbj849XBY5cY5NemTLYyeobcgg2Z+vy++0ZtBiLRUarllTZH0rCU8kpw e+TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=AaegcihBLJQJfoRSt4gkmOzXxDMBePppoosaSAJRCnQ=; b=lUYST/kYfmSX5IpDgeuF3ickSjG+Kf3WE1R9Riyg6hyrxohgFErbi3C1FNM4qYIWNi 4q5FSIukZnfvN8kM9S93zpBCnN6it5pUZXFnwD0XaV4wQL+LD1BBEmAXkoY1TdODecoz 9i7ebapB299oUDMhGp+CDoAmssDBtWGfigNdpqGh8HEUFKOKg7WQFr5txFAUpmAtTOqy GdaUjnMH5QLC4kr1d3SgzFxRKw52322ZP0Ll1d/mLY1+w3M/9pYidDaiOMmfDpI+M3as Jle4Nc70+tnYgRNNLM0Dq7yuVLmMXY6BwhscpCNI3jdSMv6GC4cXfivaefMus6PM/8Mk sjew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XXC4UXFo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b20si461975oic.136.2020.03.06.15.21.47; Fri, 06 Mar 2020 15:22:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XXC4UXFo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726307AbgCFXTj (ORCPT + 99 others); Fri, 6 Mar 2020 18:19:39 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39933 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726245AbgCFXTi (ORCPT ); Fri, 6 Mar 2020 18:19:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583536777; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AaegcihBLJQJfoRSt4gkmOzXxDMBePppoosaSAJRCnQ=; b=XXC4UXFoCltRpQBJ/xS63l1fxxsGNENnAbYAEXH8Xiyrxx3m1n++/ofx468MYP1xCvwwEY ohEh/PhLdCtvRjeU8HQOLY3zeW5IKervB8LrzFVEMTqbb3X6I7waowsJd007baa8qw+gKZ KJB2xjnIK5em3HPxd+iQyE19FVawqbI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-376-AVQ0icusOou5JCw94mAnoA-1; Fri, 06 Mar 2020 18:19:33 -0500 X-MC-Unique: AVQ0icusOou5JCw94mAnoA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 710D0DB22; Fri, 6 Mar 2020 23:19:32 +0000 (UTC) Received: from elisabeth (ovpn-200-26.brq.redhat.com [10.40.200.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCCAC5D9CD; Fri, 6 Mar 2020 23:19:24 +0000 (UTC) Date: Sat, 7 Mar 2020 00:18:56 +0100 From: Stefano Brivio To: Yury Norov Cc: Pablo Neira Ayuso , Andrew Morton , Andy Shevchenko , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: Re: [PATCH] lib/bitmap: rework bitmap_cut() Message-ID: <20200307001856.5181eda7@elisabeth> In-Reply-To: <20200306221423.18631-1-yury.norov@gmail.com> References: <20200306221423.18631-1-yury.norov@gmail.com> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yuri, I haven't reviewed the new implementation yet, just a few comments so far: On Fri, 6 Mar 2020 14:14:23 -0800 Yury Norov wrote: > bitmap_cut() refers src after memmove(). If dst and src overlap, > it may cause buggy behaviour because src may become inconsistent. I don't see how: src is always on the opposite side of the cut compared to dst, and bits are copied one by one. Also note that I originally designed this function for the single usage it has, that is, with src being the same as dst, and this is the only way it is used, so this case is rather well tested. Do you have any specific case in mind? > The function complexity is of O(nbits * cut_bits), which can be > improved to O(nbits). Nice, indeed. > We can also rely on bitmap_shift_right() to do most of the work. Also nice. > I don't like interface of bitmap_cut(). The idea of copying of a > whole bitmap inside the function from src to dst doesn't look > useful in practice. The function is introduced a few weeks ago and > was most probably inspired by bitmap_shift_*. Looking at the code, > it's easy to see that bitmap_shift_* is usually passed with > dst == src. bitmap_cut() has a single user so far, and it also > calls it with dst == src. I'm not fond of it either, but this wasn't just "inspired" by bitmap_shift_*: I wanted to maintain a consistent interface with those, and all the other functions of this kind taking separate dst and src. For the current usage, performance isn't exceedingly relevant. If you have another use case in mind where it's relevant, by all means, I think it makes sense to change the interface. Otherwise, I would still have a slight preference towards keeping the interface consistent. By the way, I don't think it's possible to do that keeping the memmove(), and at the same time implement the rest of this change, because then we might very well hit some unexpected behaviour, using bitmap_shift_right() later. All in all, I don't have a strong preference against this -- but I'm not too convinced it makes sense either. -- Stefano